hexagon logo

Assigning Integer value from a script

Here's some low hanging fruit for the right person Wink

I am trying to assign an value to an Integer type variable in PCDMIS program, from within a PCDMIS Basic script.

In the .PGM I have:

ASSIGN/MY_INT=INT(1)


Then, in the Basic script I am trying:

Dim App As Object
Set App = CreateObject("PCDLRN.Application")

Dim Part As Object
Set Part = App.ActivePartProgram

Dim SNVar As Object
Set SNVar = Part.GetVariableValue("SERNUMBER")

Dim PPVar As Object
Set PPVar = Part.GetVariableValue("MY_INT")



MsgBox PPVar.StringValue '[B]HERE GETTING A BLANK MSBOX[/B]

. . .

Dim kSUBRPP125 As Integer
kSUBRPP125 = 0

PPVar.StringValue = kSUBRPP125
MsgBox PPVar.StringValue 'HERE MSDBOX IS OK

Part.SetVariableValue "MY_INT", PPVar

​​

And finally back in .PGM I am casing out the new value of MY_INT that is supposed to be assigned in the above script, and the case doesn't execute:

SELECT/MY_INT
CASE/0
CS3 =CALLSUB/SUBR_125MM,C:\Users\Public\Documents\Hexagon\PC-DMIS\2021.2\Subroutines\Iprogname.PRG :,
END_CASE/
END_SELECT/​
​


I have other script code that successfully assigns string variable value. What am I doing wrong for integer variable setting?

Thx, z
  • Good day,

    1.) It doesn't matter what you write in a pcDMIS-Variable beforehand if you overwrite it with a script afterwards
    2.) also you can write in a string in this pcDMIS-Variable and then do a type cast Int(Str-pcDMIS-Variable), this will only fail if someone dont put a number in this string.
    3.) you just have to make sure that the pcDMIS-Variable is present before the script

    That means this code is enough
    ASSIGN/MY_INT=0​



    ################################################## ###################################
    4.) your Script should look like this:

    Sub Main()
      ' Dim Something
       Dim App As Object
       Set App = CreateObject("PCDLRN.Application")
    
       Dim Part As Object
       Set Part = App.ActivePartProgram
    
       Dim PPVar As Object
       Dim sVarName As String
       Dim retval
    
      ' Get pcDMIS - Variable Object
       sVarName = "MY_INT"
    
       Set PPVar = Part.GetVariableValue(sVarName)
       If Not PPVar Is Nothing Then
         PPVar.LongValue = 2 '<-(a integer, your case should work )
         'or
         'PPVar.StringValue = "2" '<-(a string, you need to do Int(varname) in pcdmis )
         retval = Part.SetVariableValue(sVarName, PPVar)
       End If
    
      ' free something
        Set PPVar = Nothing
        Set Part = Nothing
        Set App = Nothing
    
    End Sub​
    


    4.1.)
    i dont know why msgbox dont work on this .. maybe because PPVar is a 'special' variable object


    ################################################## ###################################
    5.) Helpfile Remarks
    PC-DMIS variables only hold values during execution; at learn time PC-DMIS variables have a value of zero. The GetVariableValue and SetVariableValue methods only change a variable's value during the script's execution. If you want to permanently change a value of a variable inside PC-DMIS, you should use the PutText method instead.


    the values changed by GetVariableValue(varname) are only valid during the script execution.
    If the script is fired while a measuring program execution​, then they are valid in the whole process​,
    but are immediately overwritten again when an "assign/varname =" is read from the measuring program execution after the script call
  • thank you, that does work!

    The case statement is now switching off correctly.

    At the subroutine call, however (i.e. within a case), the error "Cannot open the file for writing" is throwing up before the subroutine is run. Is that because the subroutine is in the same file as the calling program?
  • please post some code, this should work with a extern or intern subroutine