hexagon logo

Getting started in VB for your PC DMIS

I like many of you have done very little with VB. As for me; I had no idea where or how to start. I could not see how typing those hundreds of lines of script could ever save me any kind of time and as far as finding a way to learn it or someone to get me started that just got to be a joke, unless I went and took a full blown course (that I didn't even know if I'd get anything out of or if I would ever use”. I had given up.

Well the other day I happened across something I think might actually be of help and makes doing something in VB practical. I don’t need to write every one of those hundreds of lines of script, and I can start learning from myself.

What I did was I took a program I already have “A regular PC DMIS Program I built and run often” and did an EXPORT as BASIC. When I opened it up all those hundreds of lines of script were already in there and though in a different “form or language” what ever you want to call it I found that I could walk thru most if not all of it as it was the same program I have in PC DMIS also. Now rather than typing all that out I need only “ADD, SUBTRACT and CHANGE things to make it work for me.

Now I think I have a starting place to try some VB.

I don’t know maybe I’m the only one that did not know this? Maybe I’m not yet on the right track, But I think I have a starting place now and I know before this I was lost.

I hope this is helpful to some of you.

Best of luck,

Tested
  • I just did this the other day also. It may help inside of PcDmis. You can also do the same with the excel macro's - I took the test32 file and changed it around some to fill out some cells and with the help of J I was able to add the variables I use from comments to fill in customer name, Inspected By and foundry name (I do things for another foundry) It helps alot
  • thanks for the information, and keep us posted
  • Good idea! I did not think of that. I will try it also and see if it helps to understand vb a little more.
  • Thanks for the info. I will try it too! Especially since I am getting ready to upgrade to 4.2!
  • I too am just starting to look at VB. IT downloaded the free version of VB and will install it hopefully today.

    My plan is to follow along with a VB for dummies book (me=dummy) at first, then ultimately move data out of PCDMIS and in to our preformatted inspection reports with excel.

    AYE YIE YIE!!! I have a feeling PCDMIS is going to be a walk in the park compared to being proficient in VB.

    To everyone just getting in to this.. GOOD LUCK Slight smile
  • I have been writing small applications with VB for years now, but on occasion I still export a program to BASIC just to see some particular syntax. It is a very useful function.

    Another thing to keep in mind, as I write each VB program, I keep them in separate folders. I've accumulated about 30 or 40 of them by now. Many of them are variants of previous programs. When I want to perform a new task, I open an existing program, make some changes, and save it under a new project name.

    If I can be of any help by providing one of my examples that may be close, let me know. I will be glad to send you one if you are willing to make the effort to understand it and make your own changes in VB.
  • Good luck everyone. I personally find VB fun to do (when I can figure it out).

    Some things to note:

    • Coding directly inside of PC-DMIS's BASIC script editor is a somewhat different experience from coding inside of something like Excel's VB script editor. The principles are the same, but some of the code statements may be slightly different since the BASIC script editor expects the code to follow the Cypress Enable. In addition the BASIC script editor does not have all the syntax code helps you can get from something like Excel's VB editor. On the other hand, you can easily tie scripts created from the BASIC script editor (.BAS files) onto PC-DMIS's toolbars and menus.
    • Use the pcdbasic.chm help file. It contains the Cypress Enable scripting language syntax for the BASIC script editor as well as a description of the Automation objects available from PC-DMIS and some sample scripts to help you get started. You can easily get to this by pressing F1 from within the BASIC Script Editor.
    • Some sample VB scripts are available for download from the Wilcox site.
    • Some user-created scripts are available for download from the Wilcox site's Custom Script Repository (you must be registered to download and to upload scripts).
    • If you plan on doing stuff in excel, here's a site I recommend. I use it as a resource for several office VB scripts I've created.

    Enjoy.
  • I use sometimes Excel's VB script editor, but I don't use PC-DMIS editor... I would like to write datas (XYZIJK) of each point of a scan without using "file/write line" in a loop (it's to long if you have a lot of points !).
    Can someone help me, please ?
    Thanks to all
  • Jeffman,

    Here is some code that I've used to extract data from a scan and write to a file -

    ***************************
    Dim mode As Integer

    Private Sub Form_Load()

    Command1.Caption = "Process"
    mode = 0

    End Sub


    Private Sub Command1_Click()


    MsgBox "The mode is " & Str(mode)

    Select Case mode

    Case 0
    process_file
    Case 1
    End
    Case 2
    End

    End Select


    End Sub


    Private Sub process_file()

    'Public Sub main(ScanID As String)

    Dim app As PCDLRN.Application
    Dim cmds As PCDLRN.Commands
    Dim cmd As PCDLRN.Command
    Dim ScanCmd As PCDLRN.Command
    Dim part As PCDLRN.PartProgram, ScanHits As PCDLRN.FeatCmd
    Dim hit As PCDLRN.PointData, vec As PCDLRN.PointData
    Dim NoScanYet As Boolean
    Dim nh As String
    Dim HitX As Double, HitY As Double, HitZ As Double
    Dim HitI As Double, HitJ As Double, HitK As Double
    Dim i As Integer, TotalCmds As Integer, CurrentCmd As Integer


    Command1.Caption = "Cancel"
    mode = 1

    NoScanYet = True
    ScanID = "SCN1"

    ' Get the App, Partprogram and Commands
    Set app = CreateObject("PCDLRN.Application")
    Set part = app.ActivePartProgram
    Set cmds = part.Commands

    ' Get the Scan from the part program
    TotalCmds = cmds.Count
    CurrentCmd = 0
    BaseText = "Processing Command # "
    EndText = "/" & Str(TotalCmds)
    For Each cmd In cmds
    CurrentCmd = CurrentCmd + 1
    If cmd.ID = ScanID And NoScanYet = True Then
    NoScanYet = False
    cmd.Next
    Set ScanCmd = cmd
    Set ScanHits = cmd.FeatureCommand
    Label1.Caption = "Found " & ScanID & " as command # " & Str(CurrentCmd)
    Exit For
    Else
    Label1.Caption = BaseText & Str(CurrentCmd) & EndText
    Label1.Refresh
    End If
    Next cmd


    If NoScanYet = True Then
    MsgBox "The Scan Feature was not found - " + ScanID
    End
    End If

    ' Some setup, establish point data objects
    Set hit = CreateObject("PCDLRN.PointData")
    Set vec = CreateObject("PCDLRN.PointData")

    ' Get the number of hits in the scan
    nh = ScanCmd.GetText(N_HITS, 0)
    cnt = CInt(nh)

    ' set startnum to 1 and endnum to the # of hits (nh)

    StartNum = 1
    EndNum = nh

    Open "c:\tmp\" & ScanID & ".txt" For Output As #1

    BaseText = "Processing Hit # "
    EndText = "/" & Str(EndNum)

    For i = StartNum To EndNum

    Label2.Caption = BaseText & Str(i) & EndText
    Label2.Refresh

    Set hit = ScanHits.GetHit(i, FHITDATA_BALLCENTER, FDATA_MEAS, FDATA_PART, AlignID, PLANE_TOP)
    HitX = CDbl(hit.x)
    HitY = CDbl(hit.y)
    HitZ = CDbl(hit.z)

    Set vec = ScanHits.GetHit(i, FHITDATA_VECTOR, FDATA_MEAS, FDATA_PART, AlignID, PLANE_TOP)
    HitI = CDbl(vec.x)
    HitJ = CDbl(vec.y)
    HitK = CDbl(vec.z)

    Write #1, i, HitX, HitY, HitZ, HitI, HitJ, HitK

    Next

    Close #1

    Command1.Caption = "Done"
    mode = 2

    End Sub


    ********************************

    It was taken from ane xisting VB project. Note that it has two Sub name lines, but the 2nd is commented out ('Public Sub main(ScanID As String)). This would be that syntax if it were a script. I sometimes develop in VB (or Excel as in your case) and then convert it to a script for use with PC-DMIS.

    There is also some extra code in there to do some displays, messaging, etc. I suspec you'll be able to extract what you need.

    One other thing to keep in mind is this. The area of code that latches onto the Scan object -

    If cmd.ID = ScanID And NoScanYet = True Then
    NoScanYet = False
    cmd.Next
    Set ScanCmd = cmd
    Set ScanHits = cmd.FeatureCommand

    has syntax which is dependedn on which type of scan you have. Linear open scans are different than Basic Circle scans, as an example.

    Anyway, I hope this helps. I'll try to answer any question you might have on it, but I wrote it quite a while ago.

    Don
  • Hi All,

    I am new to PC-DMIS but I need to write a Visual Basic program to automate some measurement. I am able to collect PC-DMIS 4.2 with my visual basic but I don't know how to define points with know XYZ and drive the CMM with my visual basic. Could someone help and post some sample codes?

    Many Thanks!
    Terry