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].

  • Yes, thank you for that. That makes sense. I was always curious why when I clicked on a point from the CAD window it would annotate it like that but in a lot of different scenarios, I'm able to use a single number.

    Do you think there could be something wrong with my IF statement? I'm going to set up a message box to check it when I get a chance.

  • If you have no issues with your script when you are using the [42..42] Syntax version, then I think you should be good to go. Unless the script also does not work still, I'll take a closer look at it. I see in your post you run the script and nothing happens. Now back to what we were saying about the Basic script editor. You don't need to add the script to your program exactly, but I think if you are just running from the basic script editor window while the script command doesn't exist in the Edit Window, it may not do anything. I'll test that right now.

    Edit - It does work, it just asks me to save the script file upon execution

  • When I run the script, I get no errors, but nothing happens. No points created. No lines created. The screen refreshes, that's it.

  • I'll take a look. I unfortunately have never constructed a Scan Segment Arc. How do I do that? I'm going to make a test script on my end.
    -- Never mind, I figured it out. I'll test real quick.

    So I need cast a point to the centroid of this circle from the scan segment, and a line to the middle point of the circle constructed? I just thought, if your N_HITS is an odd number, dividing by 2 would not work as you'd get 4.5 if you had 9 hits. Are they all even?

  • SCN1       =FEAT/SCAN,LINEAROPEN,NUMBER OF HITS=243,SHOW HITS=NO,SHOWALLPARAMS=NO
                MEAS/SCAN
                  BASICSCAN/LINE,NUMBER OF HITS=243,SHOW HITS=NO,SHOWALLPARAMS=NO
                  ENDSCAN
                ENDMEAS/
    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
    CIR2       =FEAT/CIRCLE,CARTESIAN,OUT,NO
                THEO/<0.9213,2.126,-0.2203>,<0,0,1>,0.3898
                ACTL/<0.9213,2.126,-0.2203>,<0,0,1>,0.3898
                CONSTR/CIRCLE,SCAN_SEGMENT,BF,SCN1,0.7460906,2.2113933,-0.2203125,1.0909108,2.2218878,-0.2203125,0,0,0
    CIR3       =FEAT/CIRCLE,CARTESIAN,IN,NO
                THEO/<1.2598,2.3228,-0.2203>,<0,0,1>,0.3937
                ACTL/<1.2598,2.3228,-0.2203>,<0,0,1>,0.3937
                CONSTR/CIRCLE,SCAN_SEGMENT,BF,SCN1,1.1017995,2.2054785,-0.2203125,1.4324647,2.2282214,-0.2203125,0,0,0
    CIR4       =FEAT/CIRCLE,CARTESIAN,OUT,NO
                THEO/<1.6207,2.1654,-0.2203>,<0,0,1>,0.3937
                ACTL/<1.6207,2.1654,-0.2203>,<0,0,1>,0.3937
                CONSTR/CIRCLE,SCAN_SEGMENT,BF,SCN1,1.441073,2.2459341,-0.2203125,1.611191,2.3619761,-0.2203125,0,0,0

    This is my sample program for testing purposes. I want to use the nominals from the center of the radii to create an offset point so the center point is always the nominal value, then construct a line from the offset point and a measured point on the radius. If there's a rounding function that wouldn't hurt. I figured since I defined it as an integer, it would round it for me but like I said. I have no idea what I'm doing haha

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

Reply Children
No Data