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.
  • 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!

    Thank you for the Icon AndersI. I will update my toolbar with this icon as well.
  • I played a bit more with this script,

    - removed duplicate code
    - fixed the Cancel button logic
    - added a choice "Live Generic Points", i.e. generic points that change when the original feature changes
    - added a choice "Random Error", which is just what I want/need for offline testing purposes
    - changed the naming logic so that I can generate more than one group of points from the same feature without PC-DMIS falling back to default names instead of duplicates

    I have to stop now! This is much too fun Slight smile

    Attached Files
  • I played a bit more with this script,

    - removed duplicate code
    - fixed the Cancel button logic
    - added a choice "Live Generic Points", i.e. generic points that change when the original feature changes
    - added a choice "Random Error", which is just what I want/need for offline testing purposes
    - changed the naming logic so that I can generate more than one group of points from the same feature without PC-DMIS falling back to default names instead of duplicates

    I have to stop now! This is much too fun Slight smile


    Awesome work AndersI.
    So much cleaner.
    I agree this is very fun. Thank you.
  • Great, guys!

    I agree, much fun (but far too little time to fiddle with these things).
  • 20150406
    Added Palor Check Box To AndersI update. Polar will remove the .HIT[ ] from the NOM And MEAS For the Live Gen. Points.
    Unable to find a method to stop the removal of the .HIT[ ] from the NOM And MEAS For the Live Gen. 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
    ' 20150406 
    ' Added Palor Check Box To AndersI update. Polar will remove the .HIT[ ] from the NOM And MEAS For the Live Gen. Points. 
    '===========================================================================
    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 NumFeat 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
    NumFeat = 0
    ' Enumerate commands
    For Each cmd In PCDCommands
    ' Measured (learned) feature
      If cmd.IsMeasuredFeature Then 
        FeatureList(NumFeat) = cmd.ID
        NumFeat = NumFeat + 1
      End If
    ' Autofeature (flagged As DCC feature)
      If cmd.IsDCCFeature Then
        FeatureList(NumFeat) = cmd.ID
        NumFeat = NumFeat + 1
      End If
    ' Constructed feature
    If cmd.IsConstructedFeature Then
        FeatureList(NumFeat) = cmd.ID
        NumFeat = NumFeat + 1
      End If
    Next cmd
    '*****
    '***** Dialog START
    Begin Dialog DIALOG_1 31,48, 182, 141, "Feature to Points V 3.0"
      ListBox 78,8,96,128, FeatureList$(), .ListBox
      PushButton 8,8,62,12, "Vector Points", .VPointsBtn
      PushButton 8,30,62,12, "Cast Points", .CPointsBtn
      PushButton 8,52,62,12, "Generic Points", .GPointsBtn
      PushButton 8,74,62,12, "Live Gen. Points", .LGPointsBtn
      CheckBox 8, 90, 62, 12, "Polar", .PolarCord
      CheckBox 8, 102, 62, 12, "Random error", .GenerateError
      CancelButton 8,120,52,12, "Cancel", .CancelBtn
    End Dialog
    Dim Dlg1 As DIALOG_1
    Button = Dialog(Dlg1)
    ' button 0 = Cancel, 1 = To Vector points, 2 = To Cast Points, 3 = To Generic Points, 4 = To Live Generic Points
    If (Button <> 0) Then
      '*****
      '***** Point Generation
      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)
        
        If Dlg1.GenerateError Then
          vX = vX + (Rnd() - Rnd()) / 100.0
          vY = vY + (Rnd() - Rnd()) / 100.0
          vZ = vZ + (Rnd() - Rnd()) / 100.0
        End If
        
        ' 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)
            
        Select Case Button
        Case 1:
        ' Create Vector points feature (COMMAND INFORMATION CODE edit screen) 602
          Set cmd = PCDCommands.Add(602, True)
          retval = cmd.SetExpression (PCDCommand.ID & "." & "HIT" & "[" & Fcntr & "]" , REF_ID, 0)
        Case 2:
        ' Create Cast points feature (COMMAND INFORMATION CODE edit screen) 517
          Set cmd = PCDCommands.Add(517, True)
          retval = cmd.SetExpression (PCDCommand.ID & "." & "HIT" & "[" & Fcntr & "]" , REF_ID, 0)
        Case 3: 
        ' Create Generic points feature (COMMAND INFORMATION CODE edit screen) 597
          Set cmd = PCDCommands.Add(597, True)
        Case 4:
        ' Create Generic points feature (COMMAND INFORMATION CODE edit screen) 597
          Set cmd = PCDCommands.Add(597, True)
        End Select
        
        cmd.Marked = True
        'Featurename is "sourcefeaturename_hitnumber" -> PLANE1_1
        retval = cmd.PutText (PCDCommand.ID & "_" & NumFeat & "_" & Fcntr, ID, 0)
        
        If (Button = 4) Then
          ' Live generics
           'pName = PCDCommand.ID & "." & "HIT" & "[" & Fcntr & "]."
          pName = PCDCommand.ID & "." & "HIT" & "[" & Fcntr & "]."
          ' Theo's
          retval = cmd.SetExpression (pName & "TX", THEO_X, 0)
          retval = cmd.SetExpression (pName & "TY", THEO_Y, 0)
          retval = cmd.SetExpression (pName & "TZ", THEO_Z, 0)
          retval = cmd.SetExpression (pName & "TI", THEO_I, 0)
          retval = cmd.SetExpression (pName & "TJ", THEO_J, 0)
          retval = cmd.SetExpression (pName & "TK", THEO_K, 0)
          ' Actl's
          retval = cmd.SetExpression (pName & "X", MEAS_X, 0)
          retval = cmd.SetExpression (pName & "Y", MEAS_Y, 0)
          retval = cmd.SetExpression (pName & "Z", MEAS_Z, 0)
          retval = cmd.SetExpression (pName & "I", MEAS_I, 0)
          retval = cmd.SetExpression (pName & "J", MEAS_J, 0)
          retval = cmd.SetExpression (pName & "K", MEAS_K, 0)
    
        Else
          ' 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)
        End If
    If Dlg1.PolarCord Then
         ' Set Coordinate Type  = POLAR
        retval = cmd.SetToggleString (2, COORD_TYPE, 0)
    End If
    
        PCDPartProgram.RefreshPart
        cmd.ReDraw
        
      Next
      '*****
      '***** Cleanup
      Set prbhit = Nothing
      Set PCDCommand = Nothing
      Set PCDCommands = Nothing
      Set PCDPartProgram = Nothing
      Set PCDPartPrograms = Nothing
      Set PCDApp = Nothing
      '*****
    End If 
    End Sub
    
  • ' 20150406 Added To Vector Sample Points, To Generic Sample Points, To Read Point And AndersI Live Gen. Points.
    ' Added Palor Check Box. Polar will remove the .HIT[ ] from the NOM And MEAS For the Live Gen. Points.
    ' Not all Auto Feature will work With the To Vector Sample Points and To Generic Sample Points.

    To_Points v2.0.zip
  • WARNING!

    I just noticed that the generated points are workplane-sensitive, i.e. you must ensure that the right workplane is active before generating points, otherwise the extracted points don't generate the same feature as you extracted them from. There's also a little problem with probe comp in the generated MEAS values...

    Things are never as easy as you want them to be!
  • Is there a way to turn off the "Should the insertion point move to the end bla..." prompt at the beginning of the program?


    That's something PC-DMIS decides before actually calling the script, so the answer is probably No.

    I'm not sure what triggers that question, I almost never get it (running 2014.1 offline).

  • Is there a way to turn off the "Should the insertion point move to the end bla..." prompt at the beginning of the program?

    My experience is, if you load the script in the script editor and run it you always get this prompt. If you set the script to run from a button or hot key, you never get this prompt.



    Sent from my SM-G900P using Tapatalk