hexagon logo

Creating Writelines for Points in a Program

I'm fairly new to CMM programming and PC-DMIS so go easy on me. I do not have much experience with writing code but after reading through this forum it appears that you can do a lot to automate some of the things I have to do within my programs. The program I'm working with now requires that I create a Writeline for each point taken within the program to write the Point name along with the Nominal XYZ IJK and Measured XYZ values to a text file. This is very tedious so I thought I ask about creating a script to do this for me.

The writeline currently looks like this where IP_1000 is the ID for the vector point. The script would have to create a writeline like this at the end of the program for each point.

FILE/WRITELINE,F1,"IP_1000"+" , "+IP_1000.X+" , "+IP_1000.Y+" , "+IP_1000.Z+" , "+IP_1000.TI+" , "+IP_1000.TJ+" , "+IP_1000.TK+" , "+IP_1000.TX+" , "+IP_1000.TY+" , "+IP_1000.TZ

Thanks in advance for any help you can offer.
  • Make a script that parses your program at the end of the run and if the command is a vector point, have it print the requested information to file. If you look at the sources from other scripts in here I am sure you'll find pieces that will take you a great way along your scripting journey.
  • Or, to make it simpler, create a PC-DMIS sub-routine that does the writeline, and call that subroutine for each point you want written out. Then you don't have to write the point name ten times, only once...
  • There are about 400 points in these programs so having to call a subroutine for each point doesn't seem like the best solution. I'd like to do just as vpt.se suggested but I don't know where to get started. I've only done very simple coding in vb and never anything that interfaces with another program such as PC DMIS.
  • Are only some points interesting, or should all vector points be shoveled to file? If only some points are interesting, I hope you have named them in a specific way.
  • Well, the 400 subroutine calls are far easier to enter than 400 unique writelines where the name is repeated ten times Slight smile But I agree that vpt:s method would be much better, and fix this kind of problem for any program, once and for all.

    Here is a part of an Excel VBA script I made to dump a PC-DMIS program, just to see what the different commands contained. It's not complete, it's a bit old, but it might give you some ideas. It contains the loop through the part program, detection of what kind of command, and how to get the XYZIJK from features and hits. It might contain errors, and is probably not runnable exactly as is...

    You can safely ignore all the Rows()..., Selection..., ActiveSheet... lines, as these put data into the Excel sheet. I left them in, as the right part shows what the different fields are called in PC-DMIS.

    
    Sub GetPCDMISdata()
    
      Dim app As PCDLRN.Application
      Dim pp As PCDLRN.PartPrograms
      Dim cmds As PCDLRN.Commands
      Dim cmd As PCDLRN.Command  
    
      Dim CurAlign As String
      Dim CurWP As Integer
    
      Set app = CreateObject("PCDLRN.Application")
      Set part = app.ActivePartProgram
      Set cmds = part.Commands
    
      Dim pd As PointData
      Set pd = CreateObject("PCDLRN.POINTDATA")
    
      For Each cmd In cmds
    
        If cmd.IsComment Then
    
          Rows(i).Select
          Selection.Font.ColorIndex = 0
          Set ComCmd = cmd.CommentCommand
          ActiveSheet.Cells(i, 3) = ComCmd.CommentType
          ActiveSheet.Cells(i, 4) = ComCmd.Comment
          ActiveSheet.Cells(i, 8) = ComCmd.Input
    
        ElseIf cmd.IsAlignment Then
    
          CurAlign = cmd.AlignmentCommand.ID
          ActiveSheet.Cells(i, 3) = CurAlign
    
        ElseIf cmd.Type = SET_WORKPLANE Then
    
          CurWP = cmd.ModalCommand.Workplane
          ActiveSheet.Cells(i, 3) = CurWP
    
        ElseIf cmd.IsFeature Then
    
          If Not cmd.IsHit Then
    
            Rows(i).Select
            Selection.Font.ColorIndex = 42
            Set FeatCommand = cmd.FeatureCommand
            If FeatCommand.Polar Then
              Result = FeatCommand.GetData(pd, FDATA_CENTROID, FDATA_MEAS, FDATA_POLAR, CurAlign, CurWP)
              If Result Then
                ActiveSheet.Cells(i, 6) = pd.X
                ActiveSheet.Cells(i, 7) = pd.Y
                ActiveSheet.Cells(i, 8) = pd.Z
              End If
            Else
              Result = FeatCommand.GetPoint(FPOINT_CENTROID, FDATA_MEAS, fx, fy, fz)
              If Result Then
                ActiveSheet.Cells(i, 6) = fx
                ActiveSheet.Cells(i, 7) = fy
                ActiveSheet.Cells(i, 8) = fz
              End If
            End If
    
            Result = FeatCommand.GetVector(FVECTOR_VECTOR, FDATA_MEAS, fi, fj, fk)
            If Result Then
              ActiveSheet.Cells(i, 9) = fi
              ActiveSheet.Cells(i, 10) = fj
              ActiveSheet.Cells(i, 11) = fk
            End If
    
            If cmd.IsDCCFeature Then
              HitPoints = FeatCommand.GetPoints(FHITDATA_CENTROID, FDATA_MEAS, FDATA_PART, CurAlign, CurWP)
              HitVectors = FeatCommand.GetPoints(FHITDATA_VECTOR, FDATA_MEAS, FDATA_PART, CurAlign, CurWP)
              For HitNo = 0 To FeatCommand.NumHits - 1
                i = i + 1
                Rows(i).Select
                Selection.Font.ColorIndex = 42
                ActiveSheet.Cells(i, 6) = HitPoints(HitNo * 3 + 0)
                ActiveSheet.Cells(i, 7) = HitPoints(HitNo * 3 + 1)
                ActiveSheet.Cells(i, 8) = HitPoints(HitNo * 3 + 2)
                ActiveSheet.Cells(i, 9) = HitVectors(HitNo * 3 + 0)
                ActiveSheet.Cells(i, 10) = HitVectors(HitNo * 3 + 1)
                ActiveSheet.Cells(i, 11) = HitVectors(HitNo * 3 + 2)
              Next HitNo
            End If
    
          Else
            Rows(i).Select
            Selection.Font.ColorIndex = 42
            Set FeatCommand = cmd.FeatureCommand
    
            Result = FeatCommand.GetPoint(FHITDATA_CENTROID, FDATA_MEAS, fx, fy, fz)
            ActiveSheet.Cells(i, 6) = fx
            ActiveSheet.Cells(i, 7) = fy
            ActiveSheet.Cells(i, 8) = fz
    
            Result = FeatCommand.GetVector(FVECTOR_VECTOR, FDATA_MEAS, fi, fj, fk)
            If Result Then
              ActiveSheet.Cells(i, 9) = fi
              ActiveSheet.Cells(i, 10) = fj
              ActiveSheet.Cells(i, 11) = fk
            End If
    
          End If
     next
    end sub
    
    
  • Another option
    In the editor window


    YOU WOULD NEED TO PHYSICALLY COUNT ALL THE VECTOR POINTS!!!!!

    (Ex. You have 416 vpoints)


    ASSIGN/COUNT = 0
    
    DO/
    ASSIGN/COUNT = COUNT + 1
    
    ASSIGN/V1 = GETCOMMAND("602","TOP",COUNT)
    
    ASSIGN/VPNT_NAME = GETTEXT("ID",1,V1)
    
    ASSIGN/MX = GETTEXT("MEASURED X",0,V1)
    ASSIGN/MY = GETTEXT("MEASURED Y",0,V1)
    ASSIGN/MZ = GETTEXT("MEASURED Z",0,V1)
    
    ASSIGN/TI = GETTEXT("THEORETICAL I",1,V1)
    ASSIGN/TJ = GETTEXT("THEORETICAL J",1,V1)
    ASSIGN/TK = GETTEXT("THEORETICAL K",1,V1)
    
    ASSIGN/TX = GETTEXT("THEORETICAL X",1,V1)
    ASSIGN/TY = GETTEXT("THEORETICAL Y",1,V1)
    ASSIGN/TZ = GETTEXT("THEORETICAL Z",1,V1)
    
    (Your file writeline would go here using the above variables)
    
    UNTIL/COUNT>415
    
    
  • Another option
    In the editor window


    YOU WOULD NEED TO PHYSICALLY COUNT ALL THE VECTOR POINTS!!!!!

    (Ex. You have 416 vpoints)


    ASSIGN/COUNT = 0
    
    DO/
    ASSIGN/COUNT = COUNT + 1
    
    ASSIGN/V1 = GETCOMMAND("602","TOP",COUNT)
    
    ASSIGN/VPNT_NAME = GETTEXT("ID",1,V1)
    
    ASSIGN/MX = GETTEXT("MEASURED X",0,V1)
    ASSIGN/MY = GETTEXT("MEASURED Y",0,V1)
    ASSIGN/MZ = GETTEXT("MEASURED Z",0,V1)
    
    ASSIGN/TI = GETTEXT("THEORETICAL I",1,V1)
    ASSIGN/TJ = GETTEXT("THEORETICAL J",1,V1)
    ASSIGN/TK = GETTEXT("THEORETICAL K",1,V1)
    
    ASSIGN/TX = GETTEXT("THEORETICAL X",1,V1)
    ASSIGN/TY = GETTEXT("THEORETICAL Y",1,V1)
    ASSIGN/TZ = GETTEXT("THEORETICAL Z",1,V1)
    
    (Your file writeline would go here using the above variables)
    
    UNTIL/COUNT>415
    
    




    If I wanted to use this method but only output vector points that begin with IP_ is that possible or would that required a VB script?

    Thanks for all your help!
  • Another option
    In the editor window


    ASSIGN/COUNT = 0
    
    DO/
    ASSIGN/COUNT = COUNT + 1
    
    ASSIGN/V1 = GETCOMMAND("602","TOP",COUNT)
    
    ASSIGN/VPNT_NAME = GETTEXT("ID",1,V1)
    [COLOR=#FF0000]ASSIGN/V2 = LEFT(VPNT_NAME,3)[/COLOR]
    
    [COLOR=#FF0000]IF/V2 == "IP_"[/COLOR]
    
    ASSIGN/MX = GETTEXT("MEASURED X",0,V1)
    ASSIGN/MY = GETTEXT("MEASURED Y",0,V1)
    ASSIGN/MZ = GETTEXT("MEASURED Z",0,V1)
    
    ASSIGN/TI = GETTEXT("THEORETICAL I",1,V1)
    ASSIGN/TJ = GETTEXT("THEORETICAL J",1,V1)
    ASSIGN/TK = GETTEXT("THEORETICAL K",1,V1)
    
    ASSIGN/TX = GETTEXT("THEORETICAL X",1,V1)
    ASSIGN/TY = GETTEXT("THEORETICAL Y",1,V1)
    ASSIGN/TZ = GETTEXT("THEORETICAL Z",1,V1)
    
    (Your file writeline would go here using the above variables)
    
    [COLOR=#ff0000]END_IF[/COLOR]
    
    UNTIL/COUNT>500
    
    


    I think this should work.

    This tests the 3 left characters in the string VPNT_NAME if they are equal to IP_

    If so, writeline, if not go to next vector point. (You need to enter a number that is greater than the number of vector points starting with IP_

    in the

    UNTIL/COUNT>

    line.)
  • Thanks dph51. This is working great and doing exactly what I need it to do. Maybe one day I'll have enough "spare" time to dive into VB.