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


    Here it is in BASIC

    Sub MAIN()
    ' 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 Object
    Dim PCDPartPrograms As Object
    Dim PCDPartProgram As Object
    Dim PCDCommands As Object
    Dim cmd As Object
    Dim editWin As Object
    Dim oTHEO As Object
    
    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, alignID, txtBlockTmp, MSG As String
    Dim lastChr, findTHEO, findChr, firstComma, secondComma As Integer
    
    fcntr = 0
    
    For Each cmd In PCDCommands
    If cmd.IsAlignment And cmd.ID <> "" Then
        alignID = cmd.ID
    End If
        If cmd.IsDCCFeature Or cmd.IsMeasuredFeature Then
            If cmd.Marked Then
    
                FeatureList(fcntr) = cmd.ID
    
                TX = CStr(cmd.FeatureCommand.GetHit(1, FHITDATA_CENTROID, FDATA_TARG, FDATA_PART, alignID, PLANE_TOP).X)
                TY = CStr(cmd.FeatureCommand.GetHit(1, FHITDATA_CENTROID, FDATA_TARG, FDATA_PART, alignID, PLANE_TOP).Y)
                TZ = CStr(cmd.FeatureCommand.GetHit(1, FHITDATA_CENTROID, FDATA_TARG, FDATA_PART, alignID, PLANE_TOP).Z)
    
                NewTX = TX & "+0"
                NewTY = TY & "+0"
                NewTZ = TZ & "+0"
    
                MSG = MSG & Chr(10) & Chr(10) & cmd.ID
                MSG = MSG & Chr(10) & Chr(10) & alignID
                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
                MSG = ""
            End If
        End If
    Next cmd
    
    Set PCDApp = Nothing
    Set PCDPartPrograms = Nothing
    Set PCDPartProgram = Nothing
    
    End Sub
  • This^^

    PointData allows you to choose in which alignment to pull the values from.
  • As a general comment I'd add: Don't use gettext unless there really is no other way to extract the values you need! Almost everything (except FCF:s and SIZE:s) have a lot of predefined methods for getting the values. In the latest versions of PC-DMIS a description of the type library is included in the Help.

    Also, gettext gives you language dependent results, going through the access functions mostly use language independent numeric constants instead.
  • As a general comment I'd add: Don't use gettext unless there really is no other way to extract the values you need! Almost everything (except FCF:s and SIZE:s) have a lot of predefined methods for getting the values. In the latest versions of PC-DMIS a description of the type library is included in the Help.

    Also, gettext gives you language dependent results, going through the access functions mostly use language independent numeric constants instead.


    GETTEXT seems to be the only thing giving good results. I am fully aware of how unreliable this can be but what else can you do? Any solutions/suggestions to the problem Andersl?
  • I'm not sure which problem you're talking about?
  • I can extract the THEO values, but they don’t seem to be in the correct coordinate (alignment) system. What advice can you give an old programmer. (Using the basic supplied with PCDMIS).

    Thanks




    Tried the "PointData" method with no success. Can't get the correct THEOs no matter what method I try unless I use the funky GETTEXT method.
  • What about GomoFazters method(s) in the ToPoints thread? http://www.pcdmisforum.com/forum/pc-...691#post392691


    Yep! I have a strong feeling GomoFazters found a work around to it by just reading into a couple lines of his code. Never thought of looking at that and I use his to_points widgets SMF
  • This seems to be working... it's pulling the correct values. Going to add a "+0" soon and report back with results.
       Private Sub PullTheos()
            Dim PCDApp As PCDLRN.Application
            Dim PCDPart As PCDLRN.PartProgram
            Dim PCDCommands As Object
            Dim cmd As PCDLRN.Command
            Dim editWin As PCDLRN.EditWindow
    
            PCDApp = CreateObject("PCDLRN.Application")
            PCDPart = PCDApp.ActivePartProgram
            PCDCommands = PCDPart.Commands
            editWin = PCDPart.EditWindow
    
            Dim algnID As String = ""
    
            For Each cmd In PCDCommands
                If cmd.IsAlignment And cmd.ID <> "" Then
                    algnID = cmd.ID
                End If
    
                If cmd.IsDCCFeature Or cmd.IsMeasuredFeature Then
                    If cmd.Marked Then
    
                        Dim oTHEO As PCDLRN.PointData = cmd.FeatureCommand.GetHit(1, PCDLRN.FHITDATA_TYPES.FHITDATA_CENTROID, PCDLRN.FDATA_DATASET.FDATA_THEO, PCDLRN.FDATA_COORDSYS.FDATA_PART, algnID, PCDLRN.ENUM_PLANE_TYPE.PLANE_TOP)
    
                        MsgBox("Feature Name: " & cmd.ID & vbCr & "Alignment Name: " & algnID & vbCr & oTHEO.X.ToString & " " & oTHEO.Y.ToString & " " & oTHEO.Z.ToString)
    
                    End If
                End If
            Next cmd
    
    
            PCDApp = Nothing
            PCDPart = Nothing
            PCDCommands = Nothing
    
        End Sub
    


    Using 2015.1 SP10 on Windows 10 x64.
  • It works on Vector Points....need to wrap it up and tweak to use on all PcD featuers.

    Private Sub Values2Expression()
            Dim PCDApp As PCDLRN.Application
            Dim PCDPart As PCDLRN.PartProgram
            Dim PCDCommands As Object
            Dim cmd As PCDLRN.Command
            Dim editWin As PCDLRN.EditWindow
            Dim pNumTHEO As Integer = 4
            Dim pNumVECT As Integer = 4
            Dim pNumTARG As Integer = 4
    
            PCDApp = CreateObject("PCDLRN.Application")
            PCDPart = PCDApp.ActivePartProgram
            PCDCommands = PCDPart.Commands
            editWin = PCDPart.EditWindow
    
            Dim algnID As String = ""
    
            For Each cmd In PCDCommands
                If cmd.IsAlignment And cmd.ID <> "" Then
                    algnID = cmd.ID
                End If
                If cmd.IsDCCFeature Or cmd.IsMeasuredFeature Then
                    If cmd.Marked Then
    
                        Dim oTHEO As PCDLRN.PointData = cmd.FeatureCommand.GetHit(1, PCDLRN.FHITDATA_TYPES.FHITDATA_CENTROID, PCDLRN.FDATA_DATASET.FDATA_THEO, PCDLRN.FDATA_COORDSYS.FDATA_PART, algnID, PCDLRN.ENUM_PLANE_TYPE.PLANE_TOP)
                        Dim oVECT As PCDLRN.PointData = cmd.FeatureCommand.GetHit(1, PCDLRN.FHITDATA_TYPES.FHITDATA_VECTOR, PCDLRN.FDATA_DATASET.FDATA_THEO, PCDLRN.FDATA_COORDSYS.FDATA_PART, algnID, PCDLRN.ENUM_PLANE_TYPE.PLANE_TOP)
                        Dim oTARG As PCDLRN.PointData = cmd.FeatureCommand.GetHit(1, PCDLRN.FHITDATA_TYPES.FHITDATA_CENTROID, PCDLRN.FDATA_DATASET.FDATA_TARG, PCDLRN.FDATA_COORDSYS.FDATA_PART, algnID, PCDLRN.ENUM_PLANE_TYPE.PLANE_TOP)
    
                        'Dim iMessage As String = "Feature Name: " & cmd.ID & vbCr & "Alignment Name: " & algnID _
                        '                         & vbCr & oTHEO.X.ToString("n" & pNumTHEO) & ", " & oTHEO.Y.ToString("n" & pNumTHEO) & ", " & oTHEO.Z.ToString("n" & pNumTHEO) _
                        '                         & vbCr & oVECT.I.ToString("n" & pNumVECT) & ", " & oVECT.J.ToString("n" & pNumVECT) & ", " & oVECT.K.ToString("n" & pNumVECT) _
                        '                         & vbCr & oTARG.X.ToString("n" & pNumTARG) & ", " & oTARG.Y.ToString("n" & pNumTARG) & ", " & oTARG.Z.ToString("n" & pNumTARG)
    
                        'MsgBox(iMessage)
    
                        '__________________________________________________________________________________
                        'Theoreticals to expression
                        cmd.SetExpression(oTHEO.X.ToString("n" & pNumTHEO) & "+0", PCDLRN.ENUM_FIELD_TYPES.THEO_X, 0)
                        cmd.SetExpression(oTHEO.Y.ToString("n" & pNumTHEO) & "+0", PCDLRN.ENUM_FIELD_TYPES.THEO_Y, 0)
                        cmd.SetExpression(oTHEO.Z.ToString("n" & pNumTHEO) & "+0", PCDLRN.ENUM_FIELD_TYPES.THEO_Z, 0)
                        '__________________________________________________________________________________
    
                        '__________________________________________________________________________________
                        'Theoretical Vectors to expression
                        cmd.SetExpression(oVECT.I.ToString("n" & pNumVECT) & "+0", PCDLRN.ENUM_FIELD_TYPES.THEO_I, 0)
                        cmd.SetExpression(oVECT.J.ToString("n" & pNumVECT) & "+0", PCDLRN.ENUM_FIELD_TYPES.THEO_J, 0)
                        cmd.SetExpression(oVECT.K.ToString("n" & pNumVECT) & "+0", PCDLRN.ENUM_FIELD_TYPES.THEO_K, 0)
                        '__________________________________________________________________________________
    
                        '__________________________________________________________________________________
                        'Targets to expression
                        cmd.SetExpression(oTHEO.X.ToString("n" & pNumTARG) & "+0", PCDLRN.ENUM_FIELD_TYPES.TARG_X, 0)
                        cmd.SetExpression(oTHEO.Y.ToString("n" & pNumTARG) & "+0", PCDLRN.ENUM_FIELD_TYPES.TARG_Y, 0)
                        cmd.SetExpression(oTHEO.Z.ToString("n" & pNumTARG) & "+0", PCDLRN.ENUM_FIELD_TYPES.TARG_Z, 0)
                        '__________________________________________________________________________________
    
                        '__________________________________________________________________________________
                        'Target Vectors to expression
                        cmd.SetExpression(oVECT.I.ToString("n" & pNumVECT) & "+0", PCDLRN.ENUM_FIELD_TYPES.TARG_I, 0)
                        cmd.SetExpression(oVECT.J.ToString("n" & pNumVECT) & "+0", PCDLRN.ENUM_FIELD_TYPES.TARG_J, 0)
                        cmd.SetExpression(oVECT.K.ToString("n" & pNumVECT) & "+0", PCDLRN.ENUM_FIELD_TYPES.TARG_K, 0)
                        '__________________________________________________________________________________
    
                    End If
                End If
            Next cmd