hexagon logo

Help with string handling

Can someone please give me a hint as to why I the value of ScanID, which is being passed in from PC-DMIS, in the following script won't give me any text when I try to use it as part of a file name or try to write the value as text in the output file? The rest of this scripts works just fine so I know that it is getting the correct value for the command ID from PC-DMIS, it is finding the command, creating the output file, writing the point data to the file, etc. Thanks for any help.

Dim App As Object
Dim Part As Object
Dim Cmds As Object
Dim Cmd As Object

Sub Main (ScanID As String)

' Initialize PC-DMIS
Set App = CreateObject("PCDLRN.Application")
    If App Is Nothing Then
        MsgBox "PC-DMIS initialization error!",48, "Error!"
        Exit Sub
    Else
        Set Part = App.ActivePartProgram
        If Part Is Nothing Then
            MsgBox "Part Program not opened!", 48, "Error!"
            Exit Sub
        Else
            Set Cmds = Part.Commands
            If Cmds Is Nothing Then
                MsgBox "Pointer to commands not valid!", 48, "Error!"
                Exit Sub
            End If
        End If
    End If


' Locate Scan
For Each Cmd In Cmds
   If Cmd.isfeature Then
        If Cmd.ID = ScanID Then
          Set ScanCmd = Cmd
          Set ScanHits = ScanCmd.FeatureCommand
          Exit For
        End If
    End If
Next Cmd

' Report And Exit If Scan Not Found
If ScanCmd Is Nothing Then
    MsgBox "Scan Not Found!", 48, "Error!"
    Exit Sub
End If

' Create point data objects
Set Hit = CreateObject("PCDLRN.PointData")
Set Vec = CreateObject("PCDLRN.PointData")

' Get the number of hits In the scan
NH = ScanHits.NumHits
CNT= CInt(NH)

' Set startnum To 1 And endnum To the # of hits (nh)
StartNum = 1
EndNum = NH

Open "C:\TMP\" & ScanID & ".txt" For Output As #1

Write #1, ScanID

For i = StartNum To EndNum

Set hit = ScanHits.GetHit(i, FHITDATA_BALLCENTER, FDATA_MEAS, FDATA_PART, AlignID, PLANE_TOP)
HitX = CDbl(hit.x)
HitY = CDbl(hit.y)
HitZ = CDbl(hit.z)

Set vec = ScanHits.GetHit(i, FHITDATA_VECTOR, FDATA_MEAS, FDATA_PART, AlignID, PLANE_TOP)
HitI = CDbl(vec.x)
HitJ = CDbl(vec.y)
HitK = CDbl(vec.z)

Write #1, HitX, HitY, HitZ, HitI, HitJ, HitK

Next

Close #1

End Sub
  • Nevermind, I figured it out.

    I was using the GETCOMMAND method in the PC-DMIS to grab the feature ID and pass it over to the script. This is passing a pointer to the feature and not actually a string. Even though the variable was declared as a string in the script it actually had no string value so just showed as blank in any context where I was trying to display the text. Interestingly it worked just fine in any context where I was trying to reference the command itself.

    By using the GETTEXT method to grab the feature ID instead of GETCOMMAND everything works fine.

    There was no way to diagnose this from the code posted above. You would also need to see the PC-DMIS program from which the ScanID variable is being passed. The code posted above is perfectly fine.

    Credit for this code above goes to Alexander Mavrov and Don Ruggieri. I mashed pieces of two scripts that had been posted here previously into one.