hexagon logo

"to_points.exe" the script version

'===========================================================================
' To Points
'
' Extracts hits from features and creates vectorpoints with
' the hits THEO's.
'
' The names are created from the source feature name and a number that
' represents the hit index.
'
' Idea taken from 'to_points.exe' from the Wilcox Script Repository
' which sadly doesn't work as expected.
'
' (c) vpt.se 2010-06-15
'===========================================================================

Sub Main()
Dim PCDApp, PCDPartPrograms, PCDPartProgram, PCDCommands, PCDCommand
Dim PCDFeatCmd
Dim prbhit
Dim numhits As Integer

Set PCDApp = CreateObject("PCDLRN.Application")
Set PCDPartPrograms = PCDApp.PartPrograms
Set PCDPartProgram = PCDApp.ActivePartProgram
Set PCDCommands = PCDPartProgram.Commands

Dim cmd As Object
Dim Fcntr As Integer
Dim FeatureList$(999)

Dim hX As Double, hY As Double, hZ As Double, hI As Double, hJ As Double, hK As Double

'***** Predialog START
Fcntr = 0
' Enumerate commands
For Each cmd In PCDCommands
' Measured (learned) feature
  If cmd.IsMeasuredFeature Then 
    FeatureList(Fcntr) = cmd.ID
    Fcntr = Fcntr + 1
  End If
' Autofeature (flagged As DCC feature)
  If cmd.IsDCCFeature Then
    FeatureList(Fcntr) = cmd.ID
    Fcntr = Fcntr + 1
  End If
Next cmd
'*****

'***** Dialog START
Begin Dialog DIALOG_1 31,48, 172, 141, "Feature to points"
  ListBox 68,8,96,128, FeatureList$(), .ListBox
  PushButton 8,8,52,12, "To points", .PointsBtn
  PushButton 8,120,52,12, "Cancel", .CancelBtn
End Dialog

Dim Dlg1 As DIALOG_1
button = Dialog(Dlg1)
' button 1 = To points, button 2 = Cancel
'*****

'***** Vectorpoint generation
Fcntr = 0
If button = 1 Then
  Set PCDCommand = PCDCommands.Item(FeatureList(Dlg1.Listbox)) 
  Set PCDFeatCmd = PCDCommand.FeatureCommand
  numhits = PCDCommand.GetText(N_HITS, 0)
  Set prbhit = CreateObject("PCDLRN.PointData")

For Fcntr = 1 To numhits
  ' Get the probehits - XYZ  
  Set prbhit = PCDFeatCmd.GetHit(Fcntr, FHITDATA_CENTROID, FDATA_THEO, FDATA_PART, AlignID, PLANE_TOP)
  hX = CDbl(prbhit.X)
  hY = CDbl(prbhit.Y)
  hZ = CDbl(prbhit.Z)
  ' Get the probehits - IJK
  Set prbhit = PCDFeatCmd.GetHit(Fcntr, FHITDATA_VECTOR, FDATA_THEO, FDATA_PART, AlignID, PLANE_TOP)
  hI = CDbl(prbhit.X)
  hJ = CDbl(prbhit.Y)
  hK = CDbl(prbhit.Z)
  ' Create vectorpoints
  Set cmd = PCDCommands.Add(602, True)
  cmd.Marked = True
  'Featurename is "sourcefeaturename-hitnumber" -> PLANE1-1
  retval = cmd.PutText (PCDCommand.ID & "-" & Fcntr, ID, 0)
  'Theo's
  retval = cmd.PutText (hX, THEO_X, 0)
  retval = cmd.PutText (hY, THEO_Y, 0)
  retval = cmd.PutText (hZ, THEO_Z, 0)
  retval = cmd.PutText (hI, THEO_I, 0)
  retval = cmd.PutText (hJ, THEO_J, 0)
  retval = cmd.PutText (hK, THEO_K, 0)
  'Targ's
  retval = cmd.PutText (hX, TARG_X, 0)
  retval = cmd.PutText (hY, TARG_Y, 0)
  retval = cmd.PutText (hZ, TARG_Z, 0)
  retval = cmd.PutText (hI, TARG_I, 0)
  retval = cmd.PutText (hJ, TARG_J, 0)
  retval = cmd.PutText (hK, TARG_K, 0)
  cmd.ReDraw
  PCDPartProgram.RefreshPart
Next
End If
'*****

'***** Cleanup
Set PCDApp = Nothing
Set PCDPartPrograms = Nothing
Set PCDPartProgram = Nothing
Set PCDCommands = Nothing
Set prbhit = Nothing
'*****

End Sub


Code posted as-is, no guarantees.
Feel free to tweak it to suit your own needs, but please post your version as well - for others to learn from.
  • PCDLRN.PartProgram.Commands.CurrentCommand returns the command on which the cursor is located.


    I was thinking the same. I guess you could use that to get the current command and convert that to points. You'd need some errorhandling included though, if the command isn't a feature containing any hits...
  • So I'm working on modifying this script to meet my needs. I have a program that has several analog scans. At the end I want to automatically export XYZIJK values for all points in each scan, similar to File...Export...XYZ. I have the script set up so it creates all point data for each scan but would like to eliminate the dialog box and have it automatically export data for all executed scans. Any ideas?

    This is my current script:
    '===========================================================================' To Points
    '
    ' Extracts hits from features And creates vectorpoints With
    ' the hits THEO's.
    '
    ' The names are created from the source feature Name And a number that
    ' represents the hit index.
    '
    ' Idea taken from 'to_points.exe' from the Wilcox Script Repository
    ' which sadly doesn't work As expected.
    '
    ' (c) vpt.se 2010-06-15
    '===========================================================================
    
    
    Sub Main()
    Dim PCDApp, PCDPartPrograms, PCDPartProgram, PCDCommands, PCDCommand
    Dim PCDFeatCmd
    Dim prbhit
    Dim numhits As Integer
    
    
    Dim txtPartName As Object
    Dim txtSerialNumber As Object
    
    
    
    
    Set PCDApp = CreateObject("PCDLRN.Application")
    Set PCDPartPrograms = PCDApp.PartPrograms
    Set PCDPartProgram = PCDApp.ActivePartProgram
    Set PCDCommands = PCDPartProgram.Commands
    
    
    Set txtPartNumber = PCDPartProgram.GetVariableValue ("V_PARTNUMBER")  '("whatever you Name the variable In the program")
    Set txtSerialNumber = PCDPartProgram.GetVariableValue ("V_SERIALNUMBER") '("whatever you Name the variable In the program")
    Set txtLotNumber = PCDpartprogram.getvariablevalue ("V_LOT")
    
    
    Dim cmd As Object
    Dim Fcntr As Integer
    Dim FeatureList$(999)
    
    
    
    
    Dim hX As Double, hY As Double, hZ As Double, hI As Double, hJ As Double, hK As Double
    
    
    Dim strFile As String
            strFile = txtPartNumber.stringvalue & "_LotNum " & txtLotNumber.stringvalue & "_SerNum " & txtSerialNumber.stringvalue & "_" & "POINTDATA.TXT" 
    
    
    
    
    '***** Predialog START
    Fcntr = 0
    ' Enumerate commands
    For Each cmd In PCDCommands
    ' Measured (learned) feature
      If cmd.IsMeasuredFeature Then 
        FeatureList(Fcntr) = cmd.ID
        Fcntr = Fcntr + 1
      End If
    ' Autofeature (flagged As DCC feature)
      If cmd.IsDCCFeature Then
        FeatureList(Fcntr) = cmd.ID
        Fcntr = Fcntr + 1
      End If
    Next cmd
    '*****
    
    
    '***** Dialog START
    Begin Dialog DIALOG_1 31,48, 172, 141, "Feature to points"
      ListBox 68,8,96,128, FeatureList$(), .ListBox
      PushButton 8,8,52,12, "To points", .PointsBtn
      PushButton 8,120,52,12, "Cancel", .CancelBtn
    End Dialog
    
    
    Dim Dlg1 As DIALOG_1
    button = Dialog(Dlg1)
    ' button 1 = To points, button 2 = Cancel
    '*****
    
    
    '***** Vectorpoint generation
    Fcntr = 0
    If button = 1 Then
      Set PCDCommand = PCDCommands.Item(FeatureList(Dlg1.Listbox)) 
      Set PCDFeatCmd = PCDCommand.FeatureCommand
      numhits = PCDFeatCmd.NumHits
      Set prbhit = CreateObject("PCDLRN.PointData")
    
    
      'Open PCDPartProgram.Path & "POINTDATA.TXT" For Append As #1
    Open "S:\Quality\ENGINETICS PART NUMBERS\5000 - 5999\5317974SK01\CMM Reports\" & strFile For Append As #1
     
    Print #1, "Point #,X,Y,Z,I,J,K"
      
    For Fcntr = 1 To numhits
      ' Get the probehits - XYZ  
      Set prbhit = PCDFeatCmd.GetHit(Fcntr, FHITDATA_CENTROID, FDATA_THEO, FDATA_PART, AlignID, PLANE_TOP)
      hX = CDbl(prbhit.X)
      hY = CDbl(prbhit.Y)
      hZ = CDbl(prbhit.Z)
      
    ' Get the probehits - IJK
      Set prbhit = PCDFeatCmd.GetHit(Fcntr, FHITDATA_VECTOR, FDATA_THEO, FDATA_PART, AlignID, PLANE_TOP)
      hI = CDbl(prbhit.I)
      hJ = CDbl(prbhit.J)
      hK = CDbl(prbhit.K)
      
    ' Create vectorpoints
      Print #1, PCDCommand.ID & "_" & Fcntr & "," & hX & "," & hY & "," & hZ & "," & hI & "," & hJ & "," & hK
      
    Next Fcntr
    
    
    Close #1
    
    
    End If
    '*****
    
    
    '***** Cleanup
    Set PCDApp = Nothing
    Set PCDPartPrograms = Nothing
    Set PCDPartProgram = Nothing
    Set PCDCommands = Nothing
    Set prbhit = Nothing
    '*****
    End Sub
  • You could remove the dialog box portion plus the "If button = 1 then..." but you would still need to code the selection of the executed scans to export, to feed the vectorpoint generation part of the script.
  • Why don't you just use the cloud of points export function? Create a COP feature for your scan and then create a COP export operator to export as either XYZ or IGES format. You can use a variable to act as a flag when the scan is executed and the COP export can be inside an IF/Then statement that checks if the flag is true and if it is it exports the points.
  • Why don't you just use the cloud of points export function? Create a COP feature for your scan and then create a COP export operator to export as either XYZ or IGES format. You can use a variable to act as a flag when the scan is executed and the COP export can be inside an IF/Then statement that checks if the flag is true and if it is it exports the points.


    +1
    Excellent solution!

    let the demon do the work. No scripting necessary.
  • I hope I don't sound like a moron, but VPT.SE, does your script work inside a specific program? I remember, back in the day, the Wilcox script was a standalone do-dad that took auto-features and created points from those features.

    Thanks.
  • I hope I don't sound like a moron, but VPT.SE, does your script work inside a specific program? I remember, back in the day, the Wilcox script was a standalone do-dad that took auto-features and created points from those features.

    Thanks.


    No, the only thing is that it needs to be run inside PC-DMIS as a script, so it isn't an EXE per se.
  • I have updated this script that will create Generic points from the hits of the Auto Features. I also updated the Script to create a Constructed Cast Points from Auto Features and adding the " .HIT[1] ". The updated script will also create a Vector Point from the Generic and Constructed Cast Points.

    '===========================================================================
    ' To Points
    '
    ' Extracts hits from features And creates vectorpoints With
    ' the hits THEO's.
    '
    ' The names are created from the source feature Name And a number that
    ' represents the hit index.
    '
    ' Idea taken from 'to_points.exe' from the Wilcox Script Repository
    ' which sadly doesn't work As expected.
    '
    ' (c) vpt.se 2010-06-15
    ' Updated Added Construct Feature And Generic Feature. davehocum 20150311
    '===========================================================================
    Sub Main()
    Dim PCDApp, PCDPartPrograms, PCDPartProgram, PCDCommands, PCDCommand
    Dim PCDFeatCmd
    Dim prbhit
    Dim numhits As Integer
    Set PCDApp = CreateObject("PCDLRN.Application")
    Set PCDPartPrograms = PCDApp.PartPrograms
    Set PCDPartProgram = PCDApp.ActivePartProgram
    Set PCDCommands = PCDPartProgram.Commands
    Dim cmd As Object
    Dim Fcntr As Integer
    Dim FeatureList$(9999)
    Dim hX As Double, hY As Double, hZ As Double, hI As Double, hJ As Double, hK As Double
    '***** Predialog START
    Fcntr = 0
    ' Enumerate commands
    For Each cmd In PCDCommands
    ' Measured (learned) feature
      If cmd.IsMeasuredFeature Then 
        FeatureList(Fcntr) = cmd.ID
        Fcntr = Fcntr + 1
      End If
    ' Autofeature (flagged As DCC feature)
      If cmd.IsDCCFeature Then
        FeatureList(Fcntr) = cmd.ID
        Fcntr = Fcntr + 1
      End If
    ' Constructed feature
    If cmd.IsConstructedFeature Then
        FeatureList(Fcntr) = cmd.ID
        Fcntr = Fcntr + 1
      End If
    Next cmd
    '*****
    '***** Dialog START
    Begin Dialog DIALOG_1 31,48, 182, 141, "Feature to Points"
      ListBox 78,8,96,128, FeatureList$(), .ListBox
      PushButton 8,8,62,12, "To Vector Points", .VPointsBtn
      PushButton 8,30,62,12, "To Cast Points", .CPointsBtn
      PushButton 8,51,62,12, "To Generic Points", .GPointsBtn
      PushButton 8,120,52,12, "Cancel", .CancelBtn
    End Dialog
    Dim Dlg1 As DIALOG_1
    button = Dialog(Dlg1)
    ' button 1 = To points, button 2 = Cancel
    '*****
    '***** Vector Point Generation
    Fcntr = 0
    If button = 1 Then
      Set PCDCommand = PCDCommands.Item(FeatureList(Dlg1.Listbox)) 
      Set PCDFeatCmd = PCDCommand.FeatureCommand
      numhits = PCDFeatCmd.NumHits
      Set prbhit = CreateObject("PCDLRN.PointData")
    For Fcntr = 1 To numhits
      ' Get the probehits - XYZ  
      Set prbhit = PCDFeatCmd.GetHit(Fcntr, FHITDATA_CENTROID, FDATA_THEO, FDATA_PART, AlignID, PLANE_TOP)
      vX = CDbl(prbhit.X)
      vY = CDbl(prbhit.Y)
      vZ = CDbl(prbhit.Z)
      ' Get the probehits - IJK
      Set prbhit = PCDFeatCmd.GetHit(Fcntr, FHITDATA_VECTOR, FDATA_THEO, FDATA_PART, AlignID, PLANE_TOP)
      vI = CDbl(prbhit.X)
      vJ = CDbl(prbhit.Y)
      vK = CDbl(prbhit.Z)
    ' Create Vector points feature (COMMAND INFORMATION CODE edit screen) 602
    ' Create Cast points feature (COMMAND INFORMATION CODE edit screen) 517
    ' Create Generic points feature (COMMAND INFORMATION CODE edit screen) 597
      Set cmd = PCDCommands.Add(602, True)
      cmd.Marked = True
      'Featurename is "sourcefeaturename-hitnumber" -> PLANE1-1
      retval = cmd.PutText (PCDCommand.ID & "_" & Fcntr, ID, 0)
      Result = cmd.SetExpression (PCDCommand.ID & "." & "HIT" & "[" & Fcntr & "]" , REF_ID, 0)
      ' Theo's
      retval = cmd.PutText (vX, THEO_X, 0)
      retval = cmd.PutText (vY, THEO_Y, 0)
      retval = cmd.PutText (vZ, THEO_Z, 0)
      retval = cmd.PutText (vI, THEO_I, 0)
      retval = cmd.PutText (vJ, THEO_J, 0)
      retval = cmd.PutText (vK, THEO_K, 0)
      ' Actl's
      'retval = cmd.PutText (vX, MEAS_X, 0)
      'retval = cmd.PutText (vY, MEAS_Y, 0)
      'retval = cmd.PutText (vZ, MEAS_Z, 0)
      'retval = cmd.PutText (vI, MEAS_I, 0)
      'retval = cmd.PutText (vJ, MEAS_J, 0)
      'retval = cmd.PutText (vK, MEAS_K, 0)
      ' Targ's
      retval = cmd.PutText (vX, TARG_X, 0)
      retval = cmd.PutText (vY, TARG_Y, 0)
      retval = cmd.PutText (vZ, TARG_Z, 0)
      retval = cmd.PutText (vI, TARG_I, 0)
      retval = cmd.PutText (vJ, TARG_J, 0)
      retval = cmd.PutText (vK, TARG_K, 0)
      PCDPartProgram.RefreshPart
      cmd.ReDraw
      
    Next
    End If
    '*****
    '***** Cast Point Generation
    Fcntr = 0
    If button = 2 Then
      Set PCDCommand = PCDCommands.Item(FeatureList(Dlg1.Listbox)) 
      Set PCDFeatCmd = PCDCommand.FeatureCommand
      numhits = PCDFeatCmd.NumHits
      Set prbhit = CreateObject("PCDLRN.PointData")
    For Fcntr = 1 To numhits
      ' Get the probehits - XYZ  
      Set prbhit = PCDFeatCmd.GetHit(Fcntr, FHITDATA_CENTROID, FDATA_THEO, FDATA_PART, AlignID, PLANE_TOP)
      cX = CDbl(prbhit.X)
      cY = CDbl(prbhit.Y)
      cZ = CDbl(prbhit.Z)
      ' Get the probehits - IJK
      Set prbhit = PCDFeatCmd.GetHit(Fcntr, FHITDATA_VECTOR, FDATA_THEO, FDATA_PART, AlignID, PLANE_TOP)
      cI = CDbl(prbhit.X)
      cJ = CDbl(prbhit.Y)
      cK = CDbl(prbhit.Z)
    ' Create Vector points feature (COMMAND INFORMATION CODE edit screen) 602
    ' Create Cast points feature (COMMAND INFORMATION CODE edit screen) 517
    ' Create Generic points feature (COMMAND INFORMATION CODE edit screen) 597
      Set cmd = PCDCommands.Add(517, True)
      cmd.Marked = True
      'Featurename is "sourcefeaturename-hitnumber" -> PLANE1-1
      retval = cmd.PutText (PCDCommand.ID & "_" & Fcntr, ID, 0)
      Result = cmd.SetExpression (PCDCommand.ID & "." & "HIT" & "[" & Fcntr & "]" , REF_ID, 0)
      ' Theo's
      retval = cmd.PutText (cX, THEO_X, 0)
      retval = cmd.PutText (cY, THEO_Y, 0)
      retval = cmd.PutText (cZ, THEO_Z, 0)
      retval = cmd.PutText (cI, THEO_I, 0)
      retval = cmd.PutText (cJ, THEO_J, 0)
      retval = cmd.PutText (cK, THEO_K, 0)
      ' Actl's
      retval = cmd.PutText (cX, MEAS_X, 0)
      retval = cmd.PutText (cY, MEAS_Y, 0)
      retval = cmd.PutText (cZ, MEAS_Z, 0)
      retval = cmd.PutText (cI, MEAS_I, 0)
      retval = cmd.PutText (cJ, MEAS_J, 0)
      retval = cmd.PutText (cK, MEAS_K, 0)
      ' Targ's
      retval = cmd.PutText (cX, TARG_X, 0)
      retval = cmd.PutText (cY, TARG_Y, 0)
      retval = cmd.PutText (cZ, TARG_Z, 0)
      retval = cmd.PutText (cI, TARG_I, 0)
      retval = cmd.PutText (cJ, TARG_J, 0)
      retval = cmd.PutText (cK, TARG_K, 0)
      PCDPartProgram.RefreshPart
      cmd.ReDraw
      
    Next
    End If
    '*****
    '***** Generic Point Generation
    Fcntr = 0
    If button = 3 Then
      Set PCDCommand = PCDCommands.Item(FeatureList(Dlg1.Listbox)) 
      Set PCDFeatCmd = PCDCommand.FeatureCommand
      numhits = PCDFeatCmd.NumHits
      Set prbhit = CreateObject("PCDLRN.PointData")
    For Fcntr = 1 To numhits
      ' Get the probehits - XYZ  
      Set prbhit = PCDFeatCmd.GetHit(Fcntr, FHITDATA_CENTROID, FDATA_THEO, FDATA_PART, AlignID, PLANE_TOP)
      gX = CDbl(prbhit.X)
      gY = CDbl(prbhit.Y)
      gZ = CDbl(prbhit.Z)
      ' Get the probehits - IJK
      Set prbhit = PCDFeatCmd.GetHit(Fcntr, FHITDATA_VECTOR, FDATA_THEO, FDATA_PART, AlignID, PLANE_TOP)
      gI = CDbl(prbhit.X)
      gJ = CDbl(prbhit.Y)
      gK = CDbl(prbhit.Z)
    ' Create Vector points feature (COMMAND INFORMATION CODE edit screen) 602
    ' Create Cast points feature (COMMAND INFORMATION CODE edit screen) 517
    ' Create Generic points feature (COMMAND INFORMATION CODE edit screen) 597
      Set cmd = PCDCommands.Add(597, True)
      cmd.Marked = True
      'Featurename is "sourcefeaturename-hitnumber" -> PLANE1-1
      retval = cmd.PutText (PCDCommand.ID & "_" & Fcntr, ID, 0)
      'Result = cmd.SetExpression (PCDCommand.ID & "." & "HIT" & "[" & Fcntr & "]" , REF_ID, 0)
      ' Theo's
      retval = cmd.PutText (gX, THEO_X, 0)
      retval = cmd.PutText (gY, THEO_Y, 0)
      retval = cmd.PutText (gZ, THEO_Z, 0)
      retval = cmd.PutText (gI, THEO_I, 0)
      retval = cmd.PutText (gJ, THEO_J, 0)
      retval = cmd.PutText (gK, THEO_K, 0)
      ' Actl's
      retval = cmd.PutText (gX, MEAS_X, 0)
      retval = cmd.PutText (gY, MEAS_Y, 0)
      retval = cmd.PutText (gZ, MEAS_Z, 0)
      retval = cmd.PutText (gI, MEAS_I, 0)
      retval = cmd.PutText (gJ, MEAS_J, 0)
      retval = cmd.PutText (gK, MEAS_K, 0)
      ' Targ's
      retval = cmd.PutText (gX, TARG_X, 0)
      retval = cmd.PutText (gY, TARG_Y, 0)
      retval = cmd.PutText (gZ, TARG_Z, 0)
      retval = cmd.PutText (gI, TARG_I, 0)
      retval = cmd.PutText (gJ, TARG_J, 0)
      retval = cmd.PutText (gK, TARG_K, 0)
      PCDPartProgram.RefreshPart
      cmd.ReDraw
      
    Next
    End If
     
    '*****
    '***** Cleanup
    Set PCDApp = Nothing
    Set PCDPartPrograms = Nothing
    Set PCDPartProgram = Nothing
    Set PCDCommands = Nothing
    Set prbhit = Nothing
    '*****
    End Sub
    
  • I like this script! I made a toolbar icon for it, and added it to my own custom toolbar. Now this function is only one click away!

    Attached Files