hexagon logo

VB Script, Using PutText to enter an expression

I want to write a script that can modify the THEO and TARG values of a feature to be an expression, such as "1+0" or "2*VX+4". So far I can change the values to other values but if I give it an expression it always seems to evaluate it first and insert the result rather than the expression itself.

Not sure if what I want to do is possible but after scouring the forum for any examples I am sure that if it is possible someone on here will know how to do it.


  • code
    extracts theos and shows on screen


    Sub Main()
    Dim PCDApp, PCDPartPrograms, PCDPartProgram, PCDCommands, PCDCommand
    
    Set PCDApp = CreateObject("PCDLRN.Application")
    Set PCDPARTPROGRAMS = PCDApp.PartPrograms
    Set PCDPartProgram = PCDApp.ActivePartProgram
    Set PCDCommands = PCDPartProgram.Commands
    
    Dim cmd As Object
    Dim fcntr As Integer
    Dim FeatureList$(99999)
    Dim TX, TY, TZ, NewTX, NewTY, NewTZ As Variant
    
    fcntr = 0
    
    For Each cmd in PCDCommands
    If cmd.IsDCCFeature or cmd.IsMeasuredFeature Then
    FeatureList(fcntr) = cmd.id
    
    MSG = "feature ID = " & FeatureList(fcntr)
    
    TX = cmd.GetText(THEO_X, 0)
    ​​​​​​​TY = cmd.GetText(THEO_Y, 0)
    ​​​​​​​TZ = cmd.GetText(THEO_Z, 0)
    NewTX = TX & "+0"
    NewTY = TY & "+0"
    NewTZ = TZ & "+0"
    
    MSG = MSG & chr(10) & chr(10) & "XTheo = " &TX
    MSG = MSG & chr(10) & chr(10) & "YTheo = " &TY
    MSG = MSG & chr(10) & chr(10) & "ZTheo = " &TZ
    MSG = MSG & chr(10) & chr(10) & "NewXTheo = " &NewTX
    MSG = MSG & chr(10) & chr(10) & "NewYTheo = " &NewTY
    MSG = MSG & chr(10) & chr(10) & "NewZTheo = " &NewTZ
    
    MsgBox MSG
    
    End If
    
    Next cmd
    
    Set PCDApp = nothing
    Set PCDPartPrograms = nothing
    Set PCDPartProgram = nothing
    


    I'm stumped! I get the same thing! I am not sure why it thinks it's in a different alignment.
  • It seems to use the alignment from wherever in the prgram that you start the script.
  • It seems to use the alignment from wherever in the prgram that you start the script.


    Yep that's what it looks like. I figured our a workaround let me just converted from VB.NET to BAS and I'll post.
  • This is what VBA looks like:

    Option Explicit
    Sub GetTheos()
    ' Post: http://www.pcdmisforum.com/forum/pc-dmis-enterprise-metrology-software/pc-dmis-code-samples/411735-vb-script-using-puttext-to-enter-an-expression
    
    Dim PCDApp As PCDLRN.Application
    Dim PCDPartPrograms As PCDLRN.PartPrograms
    Dim PCDPartProgram As PCDLRN.PartProgram
    Dim PCDCommands As PCDLRN.Commands
    Dim cmd As PCDLRN.Command
    Dim editWin As PCDLRN.EditWindow
    
    Set PCDApp = CreateObject("PCDLRN.Application")
    Set PCDPartPrograms = PCDApp.PartPrograms
    Set PCDPartProgram = PCDApp.ActivePartProgram
    Set PCDCommands = PCDPartProgram.Commands
    Set editWin = PCDPartProgram.EditWindow
    
    Dim fcntr As Integer
    Dim FeatureList$(99999)
    Dim TX, TY, TZ, NewTX, NewTY, NewTZ, txtBlock, txtBlockTmp, MSG As String
    Dim lastChr, findTHEO, findChr, firstComma, secondComma As Integer
    
    fcntr = 0
    
    For Each cmd In PCDCommands
        If cmd.IsDCCFeature Or cmd.IsMeasuredFeature Then
            If cmd.Marked Then
    
                FeatureList(fcntr) = cmd.ID
    
                ' Eliminate spaces and linefeeds
                txtBlock = editWin.GetCommandText(cmd)
                txtBlock = Replace(txtBlock, " ", "")
                txtBlock = Replace(txtBlock, vbCr, "")
                txtBlock = Replace(txtBlock, vbCrLf, "")
    
                lastChr = Len(txtBlock)
                findTHEO = InStr(txtBlock, "THEO") - 1
    
                ' Eliminate text before THEO and after. Results THEO/<X,Y,Z>
                txtBlock = Right(txtBlock, lastChr - findTHEO)
                findChr = InStr(txtBlock, ">,<")
                txtBlock = Left(txtBlock, findChr)
    
                ' Strip the block of text down to X,Y,Z
                txtBlock = Replace(txtBlock, "THEO/", "")
                txtBlock = Replace(txtBlock, "<", "")
                txtBlock = Replace(txtBlock, ">", "")
    
                firstComma = InStr(txtBlock, ",")
                secondComma = InStrRev(txtBlock, ",")
    
                MSG = "feature ID = " & FeatureList(fcntr)
    
                TX = Mid(txtBlock, 1, firstComma - 1)
                TY = Mid(txtBlock, firstComma + 1, (secondComma - firstComma) - 1)
                TZ = Mid(txtBlock, secondComma + 1, lastChr)
    
                NewTX = TX & "+0"
                NewTY = TY & "+0"
                NewTZ = TZ & "+0"
    
                MSG = MSG & Chr(10) & Chr(10) & "XTheo = " & TX
                MSG = MSG & Chr(10) & Chr(10) & "YTheo = " & TY
                MSG = MSG & Chr(10) & Chr(10) & "ZTheo = " & TZ
                MSG = MSG & Chr(10) & Chr(10) & "NewXTheo = " & NewTX
                MSG = MSG & Chr(10) & Chr(10) & "NewYTheo = " & NewTY
                MSG = MSG & Chr(10) & Chr(10) & "NewZTheo = " & NewTZ
    
                MsgBox MSG
    
            End If
        End If
    Next cmd
    
    Set PCDApp = Nothing
    Set PCDPartPrograms = Nothing
    Set PCDPartProgram = Nothing
    
    End Sub


    Still trying to figure out which functions don't work in PcDmis script editor chingaderas...

    UPDATE:
    Yep sorry will try again tomorrow if I get a little time. There is no "Replace" Function so will have to come up with a different approach on how to eliminate unwanted characters.

    Try it in Excel works like a charm!
  • ??? Please explain.

    Is there a solution to retrieving in the correct alignment?
  • You can use the code below to extract data from a command using the alignment you desire. It's .net, so you'll need to modify it for basic. You can then use the oTHEO object to extract the values you want, without having to parse the command text. The string "algnID" will be the NAME of the alignment you want to use.

    [FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]Each[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] oCmd [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]In[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] DmisCommands
    
    Dim algnID as String = "ALGN1"[/SIZE][/FONT][/SIZE][/FONT]
    
    [FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] oTHEO [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]PointData[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2] = oCmd.FeatureCommand.GetHit(1, [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]FHITDATA_TYPES[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].FHITDATA_CENTROID, [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]FDATA_DATASET[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].FDATA_THEO, [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]FDATA_COORDSYS[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].FDATA_PART, algnID, [/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af][FONT=Consolas][SIZE=2][COLOR=#2b91af]ENUM_PLANE_TYPE[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2].PLANE_TOP)
    
    Dim theoX as Double = oTHEO.X[/SIZE][/FONT][/SIZE][/FONT]
    [FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]Dim theoY as Double = oTHEO.Y[/SIZE][/FONT][/SIZE][/FONT]
    [FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]Dim theoZ as Double = oTHEO.Z
    
    Next[/SIZE][/FONT][/SIZE][/FONT]
    
    
  • I will try that out tomorrow. Vacation day today.
  • NICE CODE !!! It's so much cleaner and easier than trying to parse text.

    Unfortunately I'm still getting numbers a bit off... MUCH CLOSER THOUGH! I am insuring that the proper alignment is being chosen.
  • Vacation day tomorrow for me... I'll catch up Monday