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

  • You do not need to include it in your program for execution if this is a one-off thing you are trialing out. You executing it from the Basic Script Editor is fine. If this were a script you need to run after each program execution then you should include it in your program.

    I have a script I made for dimensioning location axes for each hit of a feature that we needed in the past. I see your code uses REF_ID, 2. Is that because of the scan segments? My script uses REF_ID, 0

    Relevant portion of script

    If button = 1 Then 'If create button is selected, create location dimensions    
        For i = startHitNum To endHitNum 'Iterate through Each hit number And create dimension commands
            Dim hitNum As Integer
            Dim featureID As String
    
            hitNum = i
            dimensionID = Dlg1.dimensionInput & hitNum ' Combine Dimension ID With hit number For dimension counter
            featureID = Dlg1.featInput & ".HIT[" & hitNum & "]" ' Combine featureID With hit number For Feature Hit counter 
    
            Set DmisCommand = DmisCommands.Add(DIMENSION_START_LOCATION, True)
            DmisCommand.Marked = True
            retval = DmisCommand.PutText(dimensionID, ID, 0) ' Create Dimension ID
            retval = DmisCommand.PutText(featureID, REF_ID, 0) ' Use referenced Feature ID
            Result = DmisCommand.SetExpression(featureID, REF_ID, 0)
    
            If Dlg1.XCheckBox = 1 Then  'X VALUE
                Set DmisCommand = DmisCommands.Add(DIMENSION_X_LOCATION, True)
                retval = DmisCommand.PutText("X", AXIS, 0)
                If Dlg1.XPlusTol = "" And Dlg1.XMinusTol = "" Then            
                retval = DmisCommand.PutText("0.0050", F_PLUS_TOL, 0) 'Setting Default Plus Tolerance If none entered
                retval = DmisCommand.PutText("0.0050", F_MINUS_TOL, 0) 'Setting Default Minus Tolerance If none entered
                End If
                If Dlg1.XPlusTol <> ""  And Dlg1.XMinusTol <> "" Then
                retval = DmisCommand.PutText(Dlg1.XPlusTol, F_PLUS_TOL, 0) 'Setting keyed In Plus Tolerance
                retval = DmisCommand.PutText(Dlg1.XMinusTol, F_MINUS_TOL, 0) 'Setting keyed In Minus Tolerance
                End If
            End If

    I actually do recall there being an index error when I was doing something in the past. I believe Neil had said that we need to give it a starting index value so it knows where it is relative to the starting index, and you can't just use [42] instead of [42..42]. But I'm pretty sure you can for some things. I believe it may work in later versions of PC-DMIS. The issue I posted about in this thread actually does not give me invalid Index errors in 2023.2.

    I found the link. See below

    https://nexus.hexagon.com/community/public/pc-dmis/f/pc-dmis-for-cmms/138933/extracting-3-largest-values/809159

  • I used REF_ID, 2 because I'm constructing a BF line. REF_ID, 1 is the theoretical center point of the radius (I'm using an offset point) and REF_ID, 2 is the middle hit of the radius. That's how it exported from my sample program, so I used that as a template. 

  • Ahh I get it now, I think it's because I haven't done constructions yet with scripting. This makes sense now. Each REF_ID, i  - through whatever number it ends on is each feature REF_ID used in the construction.

    REF_ID, 1 = Feature 1, REF_ID 2 = Feature 2 and so forth. Thanks for explaining

    Did you read the post about the invalid Index error I posted in the link?

  • 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

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

Children
No Data