hexagon logo

Creating Nominal Center Points of Constructed Scan Segment Arcs

I'm trying to measure a bunch of radii from scanned data. They have all varying arc lengths. Some much less that the suggested 90°. So, I was going to create offset points from the nominal center of all the constructed arcs. Then use the nominal center points and a point from the arc (ex: CIR1.HIT[CIR1.NUMHITS/2]) and create a best fit line then measure the length of the line to get the size of the radius. I've got approximate 350 constructed circles from scan segment. So I'm trying to write a code to construct the points and the lines. For the record, I have no idea what I'm doing. I've just cobbled together a few things I've seen on here. I get the code to run without error but nothing happens. No features get created. What am I doing wrong? 

Sub Main()

Dim PCDApp As Object
Dim PCDPartPrograms As Object
Dim PCDPartProgram As Object
Dim PCDCommands As Object
Dim PCDCommand As Object
Dim cmd As Object

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

Dim NumFeat As Integer
Dim NumSelect As Integer
Dim I As Integer
Dim MidHit As Integer

Dim nX as Double
Dim nY as Double
Dim nZ as Double

Dim CircName As String
Dim CenterPtName As String
Dim RadLineName As String

Dim CircCenter
Dim PCDFeatCmd

NumFeat = 0
NumSelect = 0
' Enumerate commands
For Each PCDCommand In PCDCommands
' Constructed feature
  If PCDCommand.IsConstructedFeature And PCDCommand.Feature = CONST_SCAN_SEG_ARC Then 
    CircName(NumFeat) = PCDCommand.ID
    CenterPtName = CircName & "_CENTER"
    RadLineName = CircName & "_RADLINE"
    Set PCDFeatCmd = PCDCommand.FeatureCommand
    Set CircCenter = PCDFeatCmd.GetPoint(FPOINT_CENTROID, FDATA_THEO, CircName)
    nX = CDbl(CircCenter.X)
    nY = CDbl(CircCenter.Y)
    nZ = CDbl(CircCenter.Z)
    MidHit = PCDCommand.GetText(N_HITS, 0) / 2
    'CREATE OFFSET CENTERPOINT
    Set cmd = PCDCommands.Add(511, True)
    retval = cmd.PutText (nX, F_OFFSET, 1)
    retval = cmd.PutText (nY, F_OFFSET, 2)
    retval = cmd.PutText (nZ, F_OFFSET, 3)
    retval = PCDCommand.PutText (CenterPtName, ID, 0)
    retval = PCDCommand.SetToggleString ("ORIGIN", REF_ID, 0)
    retval = PCDCommand.SetToggleString (1, COORD_TYPE, 0)
    'CREATE BF RADIUS LINE
    Set cmd = PCDCommands.Add(541, True)
    retval = PCDCommand.PutText (CenterPtName, REF_ID, 1)
    retval = PCDCommand.PutText (CircName & ".HIT[" & MidHit & ".." & MidHit & "]", REF_ID, 2)
    retval = PCDCommand.PutText (RadLineName, ID, 0)
    If (NumFeat < 1000) Then
      NumFeat = NumFeat + 1
    End If
  End If
Next PCDCommand

PCDPartProgram.RefreshPart

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


End Sub



typo
[edited by: Cliff Stearns at 5:01 PM (GMT -5) on May 9, 2025]
Parents
  • Did you mark the script command in your program? Otherwise it won't execute.

    This seems a little suspect:
    retval = PCDCommand.PutText (CircName & ".HIT[" & MidHit & ".." & MidHit & "]", REF_ID, 2)

    This creates something like CIR1.HIT[1..1], if it is a line it should probably say CIR1.HIT[1]:
    retval = PCDCommand.PutText (CircName & ".HIT[" & MidHit & "]", REF_ID, 2)

  • I didn't put a script command in my program. I just ran it from basic script editor. Do I have to insert a script command in my program?

    I did the hit like that because I made a sample program to export in basic so I could see the names of things. When I was constructing the line in my sample program it kept giving me an invalid index error when I changed CIR1.HIT[42..42] to CIR1.HIT[42].

  • I could go around my program and paste this with pattern after every scan segment arc but I wanted to learn how to do some cool script haha

    CIR1       =FEAT/CIRCLE,CARTESIAN,IN,NO
                THEO/<0.4724,2.3228,-0.2203>,<0,0,1>,0.5906
                ACTL/<0.4724,2.3228,-0.2203>,<0,0,1>,0.5906
                CONSTR/CIRCLE,SCAN_SEGMENT,BF,SCN1,0.184302,2.2583087,-0.2203124,0.7334256,2.1847235,-0.2203125,0,0,0
                ASSIGN/CIRCLE_ID=GETCOMMAND(527,"UP",1)
                ASSIGN/MIDHIT=ROUND(CIRCLE_ID.NUMHITS/2)
    PNT1       =FEAT/POINT,CARTESIAN,NO
                THEO/<0.4724,2.3228,-0.2203>,<0,0,1>
                ACTL/<0.4724,2.3228,-0.2203>,<0,0,1>
                CONSTR/POINT,OFFSET,ORIGIN,CIRCLE_ID.TX,CIRCLE_ID.TY,CIRCLE_ID.TZ
    LIN1       =FEAT/LINE,CARTESIAN,UNBOUNDED,NO
                THEO/<0.4724,2.3228,-0.2203>,<-0.1493052,-0.9887912,0>
                ACTL/<0.4724,2.3228,-0.2203>,<-0.1493052,-0.9887912,0>
                CONSTR/LINE,BF,3D,PNT1,CIRCLE_ID.HIT[MIDHIT..MIDHIT],,
                OUTLIER_REMOVAL/OFF,3
                FILTER/OFF,WAVELENGTH=0

  • PNT1 =FEAT/POINT,CARTESIAN,NO
    THEO/<0.4724,2.3228,-0.2203>,<0,0,1>
    ACTL/<0.4724,2.3228,-0.2203>,<0,0,1>
    CONSTR/POINT,OFFSET,ORIGIN,CIRCLE_ID.TX,CIRCLE_ID.TY,CIRCLE_ID.TZ

    Does this not create multiple points for you on the CAD? Or just 1?

  • The point of doing the offset point is to lock in the nominal value (could use a generic point too). Because on the actual part I'm checking most of my scanned radii are less than 90° of an arc. So this is my way of measuring a small arc circle without using a Fixed Radius circle, aligning to the center, and then measuring the polar radius. There are 350 ish radii on this thing so that would be very time consuming.

  • What should your nominal value be for these Radii? I was wondering if your method was getting you the correct nominal when going to reporting the length of the line

  • For the sample program it's this:

    DIM LOC1= LOCATION OF LINE LIN1  UNITS=IN ,$
    GRAPH=OFF  TEXT=OFF  MULT=10.00  OUTPUT=BOTH  HALF ANGLE=NO
    AX    NOMINAL       +TOL       -TOL       MEAS        DEV     OUTTOL
    L       0.2953     0.0100     0.0100     0.2953     0.0000     0.0000 ----#----
    END OF DIMENSION LOC1
    DIM LOC2= LOCATION OF CIRCLE CIR1  UNITS=IN ,$
    GRAPH=OFF  TEXT=OFF  MULT=10.00  OUTPUT=BOTH  HALF ANGLE=NO
    AX    NOMINAL       +TOL       -TOL       MEAS        DEV     OUTTOL
    R       0.2953     0.0100     0.0100     0.2953     0.0000     0.0000 ----#----
    END OF DIMENSION LOC2

    It's a weird number because it's 7.5mm and I'm in inches.

  • If you do a Distance Dimension instead, and then select PNT1, and CIR1, then select add or subtract radius option do you get the same nominal value?

  • Only difference is it's negative

    DIM DIST1= 2D DISTANCE FROM POINT PNT1 TO CIRCLE CIR1     (CENTER TO CENTER),SUB_RADIUS  UNITS=IN,$
    GRAPH=OFF  TEXT=OFF  MULT=10.00  OUTPUT=BOTH
    AX    NOMINAL       +TOL       -TOL       MEAS        DEV     OUTTOL
    M      -0.2953     0.0100     0.0100    -0.2953     0.0000     0.0000 ----#----

  • Pick Add Radius instead, it may be negative or positive depending on whether you select Add or Subtract. Which feature you select first, and possible which side of the part the circle feature is located. I think only Add or subtract may matter. This will save you from needing to construct lines all over your program if it works for you this way too. And your script would end up less involved, and wouldn't need your variable statements for N_HITS / 2. Don't worry, you can still do a cool script, just an easier one

  • That would be easier. It did change to positive when I selected "add radius" instead. I'm just not entirely sure that would give me the result I want. Especially the smaller arc-ed radii. If there's only 20° of an arc, the measured circle could be wacky which could make my results look crazy. I really wish they just dimensioned all these pockets as surface profile then I wouldn't have had any of these issues haha. I still am going to report them as profile as a secondary verification.

Reply
  • That would be easier. It did change to positive when I selected "add radius" instead. I'm just not entirely sure that would give me the result I want. Especially the smaller arc-ed radii. If there's only 20° of an arc, the measured circle could be wacky which could make my results look crazy. I really wish they just dimensioned all these pockets as surface profile then I wouldn't have had any of these issues haha. I still am going to report them as profile as a secondary verification.

Children
  • I apologize for pushing you so far off topic into another subject and method entirely from your original question.

    Let's get back to what you would like your script to do. Do you still want to continue using your lines method with Location dimensions for line length?

  • Yes the line method or create a cast point from a hit on the circle and then measure it back to the offset/generic point nominal center of the circle.

  • Sorry, I've been trying to get this to work for me properly so I can tell if it is working correctly if I help you with your script. Been a pain in the butt trying to get the scans to do what I want, but I got there. So have you tried executing your script at all since you posted, or changed anything yet?

  • I tried to put a message box inside the loop, and it will not pop up, so I think there's an issue with the loop.

  • I think I figured out why, it's a good thing I created this offset point myself. So the Offset point has a required Result = segment in the exported basic script.

    So you have to have the 3 Result = for each F_OFFSET segment and can't just use PutText, but need to use SetExpression

    You will also need to add Variable --> Dim Result As Long

        retval = DmisCommand.PutText ("PNT1", ID, 0)
        retval = DmisCommand.PutText ("ORIGIN", REF_ID, 0)
        retval = DmisCommand.SetToggleString (1, COORD_TYPE, 0)
        retval = DmisCommand.PutText ("-1.103", F_OFFSET, 1)
        retval = DmisCommand.PutText ("-0.6445", F_OFFSET, 2)
        retval = DmisCommand.PutText ("0.7911", F_OFFSET, 3)
        retval = DmisCommand.SetToggleString (1, USER_DEFINED_THEOS, 0)
      Result = DmisCommand.SetExpression("CIR1.TX", F_OFFSET, 1)
      Result = DmisCommand.SetExpression("CIR1.TY", F_OFFSET, 2)
      Result = DmisCommand.SetExpression("CIR1.TZ", F_OFFSET, 3)

    Where did you get this bit of code from? Trying to figure out what creates it

    Set CircCenter = PCDFeatCmd.GetPoint(FPOINT_CENTROID, FDATA_THEO, CircName)

  • Great! Thank you! I'll try that.

    Here is where I got my inspiration. I kind of meshed these 2 together:

    Measured and Nominal Circle Values

    To Points Script

  • Do you want this script to cycle through each Constructed Scan Segment, ~350 of them. Create the origin point relative to the TX, TY, TZ offset of the circle, then a line to the NUMHITS/2? Or is there more to it than that

  • Correct!

    edit- the problem is this line <If PCDCommand.IsConstructedFeature And PCDCommand.Feature = CONST_SCAN_SEG_ARC Then>

    I changed it to <If PCDCommand.IsConstructedFeature Then> I got the message box to pop up at least before I got a mismatch error on the lines where I'm setting the nominal X,Y,Z variables.

  • I got this to create the OFFSET Origin point so far. Working on adding the Line Now. 

    Sub Main()
    
    Dim DmisApp As Object
    Dim DmisParts As Object
    Dim DmisPart As Object
    Dim DmisCmds As Object
    Dim DmisCmd As Object
    
    Set DmisApp = CreateObject("PCDLRN.Application")
    Set DmisParts = DmisApp.PartPrograms
    Set DmisPart = DmisApp.ActivePartProgram
    Set DmisCmds = DmisPart.Commands
    
    Dim i As Integer
    Dim nX As Double
    Dim nY As Double
    Dim nZ As Double
    Dim featureID As String
    Dim pntID As String
    Dim lineID As String
    Dim Result As Long
    Dim retval As Long
    
    i = 0
    For Each DmisCmd In DmisCmds
      If  DmisCmd.Type = CONST_SCAN_SEG_ARC Then 
        i = i + 1
        pntID = "MIDP" & i
        lineID = "MIDLINE" & i
        featureID = DmisCmd
        nX = DmisCmd.GetText(THEO_X, 0)
        nY = DmisCmd.GetText(THEO_Y, 0)
        nZ = DmisCmd.GetText(THEO_Z, 0)
    
        'MsgBox DmisCmd.ID
        Set DmisCmd = DmisCmds.Add(CONST_OFF_POINT, True)
          DmisCmd.Marked = True
          retval = DmisCmd.PutText(pntID, ID, 0)
          retval = DmisCmd.PutText("ORIGIN", REF_ID, 0)
          retval = DmisCmd.PutText (nX, THEO_X, 0)
          retval = DmisCmd.PutText (nY, THEO_Y, 0)
          retval = DmisCmd.PutText (nZ, THEO_Z, 0)
          Result = DmisCmd.SetExpression(featureID & ".TX", F_OFFSET, 1)
          Result = DmisCmd.SetExpression(featureID & ".TY", F_OFFSET, 2)
          Result = DmisCmd.SetExpression(featureID & ".TZ", F_OFFSET, 3)      
      End If
    Next DmisCmd
    
    DmisPart.RefreshPart
    
    '***** Cleanup
    Set DmisCmd = Nothing
    Set DmisCmds = Nothing
    Set DmisPart = Nothing
    Set DmisParts = Nothing
    Set DmisApp = Nothing
    
    End Sub

  • I think this works. Only thing I noticed is that for some reason my Theo and Actual for the Line didn't match. Probably some weird math rounding going on in the background.

    MIDP1      =FEAT/POINT,CARTESIAN,YES
                THEO/<-1.103,-0.6445,0.7911>,<0,0,1>
                ACTL/<-1.103,-0.6445,0.7911>,<0,0,1>
                CONSTR/POINT,OFFSET,ORIGIN,CIR1.TX,CIR1.TY,CIR1.TZ
    MIDLINE1   =FEAT/LINE,CARTESIAN,UNBOUNDED,NO
                THEO/<-1.103,-0.6447,0.7911>,<-0.433579,0,0.9011156>
                ACTL/<-1.103,-0.6448,0.7911>,<-0.4331797,0,0.9013076>
                CONSTR/LINE,BF,2D,MIDP1,CIR1.HIT[5..5],,
                OUTLIER_REMOVAL/OFF,3
                FILTER/OFF,WAVELENGTH=0

    Sub Main()
    
    Dim DmisApp As Object
    Dim DmisParts As Object
    Dim DmisPart As Object
    Dim DmisCmds As Object
    Dim DmisCmd As Object
    Dim FeatCmd As Object
    
    Set DmisApp = CreateObject("PCDLRN.Application")
    Set DmisParts = DmisApp.PartPrograms
    Set DmisPart = DmisApp.ActivePartProgram
    Set DmisCmds = DmisPart.Commands
    
    Dim i As Integer
    Dim nHits As Integer
    Dim nX As Double
    Dim nY As Double
    Dim nZ As Double
    Dim featureID As String
    Dim pntID As String
    Dim lineID As String
    Dim Result As Long
    Dim retval As Long
    
    i = 0
    For Each DmisCmd In DmisCmds
      If  DmisCmd.Type = CONST_SCAN_SEG_ARC Then 
        i = i + 1
        Set FeatCmd = DmisCmd.FeatureCommand
        pntID = "MIDP" & i
        lineID = "MIDLINE" & i
        featureID = DmisCmd
        nX = DmisCmd.GetText(THEO_X, 0)
        nY = DmisCmd.GetText(THEO_Y, 0)
        nZ = DmisCmd.GetText(THEO_Z, 0)
        nHit = Format(FeatCmd.NumHits / 2, "0")
    
        Set DmisCmd = DmisCmds.Add(CONST_OFF_POINT, True)
          DmisCmd.Marked = True      
          retval = DmisCmd.PutText(pntID, ID, 0)
          retval = DmisCmd.PutText("ORIGIN", REF_ID, 0)
          retval = DmisCmd.PutText (nX, THEO_X, 0)
          retval = DmisCmd.PutText (nY, THEO_Y, 0)
          retval = DmisCmd.PutText (nZ, THEO_Z, 0)
          Result = DmisCmd.SetExpression(featureID & ".TX", F_OFFSET, 1)
          Result = DmisCmd.SetExpression(featureID & ".TY", F_OFFSET, 2)
          Result = DmisCmd.SetExpression(featureID & ".TZ", F_OFFSET, 3)
         Set DmisCmd = DmisCmds.Add(CONST_BF_LINE, True)
          retval = DmisCmd.PutText(lineID, ID, 0)
          retval = DmisCmd.PutText(pntID, REF_ID, 1)
          retval = DmisCmd.PutText(featureID & ".HIT[" &  nHit & ".." & nHit & "]", REF_ID, 2)      
    
      End If
    Next DmisCmd
    
    DmisPart.RefreshPart
    
    '***** Cleanup
    Set DmisCmd = Nothing
    Set DmisCmds = Nothing
    Set DmisPart = Nothing
    Set DmisParts = Nothing
    Set DmisApp = Nothing
    
    End Sub

    Edit - Changed my usage of Left() function I used for testing for the rounding of hit number. Changed it to Format(value, "0") which properly rounds (up) rather than truncating. So in the event you have more than a single digit hit count, it will always just use the nearest whole number.