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 want the script to essentially do this. I just added the assignment for clarity.

    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/V1=ROUND(CIR1.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,CIR1.TX,CIR1.TY,CIR1.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,CIR1.HIT[V1..V1],,
                OUTLIER_REMOVAL/OFF,3
                FILTER/OFF,WAVELENGTH=0

  • When I try to do the CONSTR/POINT,OFFSET,ORIGIN,CIR1.TX,CIR1.TY,CIR1.TZ it is creating 2 points in a single point. At least visually on my CAD. Is that the same for you? I feel like doing a CAST point would do the same thing, just the vectors would not be perfect

  • 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 ----#----

Reply Children