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.
Parents
  • 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
    
    
Reply
  • 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
    
    
Children
No Data