hexagon logo

Passing Part Variables back and forth

I am having a helluva time trying to pull variables from the part program. The first time I pull a variable in this script, (Shown in blue) it works beautiful. The second time, pulling the same variable (shown in red), it pulls nothing! I have slowly changed the second call back to the exact text of the first, because nothing is working! Now it is identical except for the variable name the part variable is being assigned to and it still won't work! W T F! AngryAngryAngry

Dim Var
Dim Var2 As Object

If dblouttol > 0 Then 
   MsgBox "Part is BAD!" & Chr(10) & "Number of Dimensions Out of Tolerance:" & dblouttol & Chr(10) &"Features out of tolerance:" & Chr(10) & Msg ' Display the ID's that are out of tolerance
   [COLOR="Blue"]Set Var = objPART.GetVariableValue ("SUB_OUTTOLNUM")[/COLOR]        'Grabs the variable SUB_OUTTOLNUM from the subroutine program
   Var.stringvalue  = dblOutTol                                      'Sets variable As number of outtol dimensions. Change this To actual CMM Name/number
   Set Var2 = objPART.getvariablevalue ("SUB_ACCEPTREJECT")  'Grabs the variable Sub_ACCEPTREJECT from the subroutine program
   var2.stringvalue = "~~4 REJECTED"                                                                       'Sets variable As Accept, As part is good
                
End If  

objPART.SetVariableValue "SUB_OUTTOLNUM", Var                  'Passes the number of outtol dimensions back To the subroutine
objPART.SetVariableValue "SUB_ACCEPTREJECT", Var2           'Passes the Accept/Reject variable back To the subroutine


Dim Test1

[COLOR="Red"]Set Test1 = objpart.GetVariableValue ("SUB_OUTTOLNUM") [/COLOR]
msgbox Test1.stringvalue
  • This is ridiculous. Attempting to insert ANY new getvariablevalue line ANYWHERE fails. Even if I copy and paste the one that works!!!!! I am doing a full computer shutdown now, not just a PC-DMIS shutdown. How incredibly frustrating.
  • objPART.SetVariableValue "SUB_OUTTOLNUM", Var                  'Passes the number of outtol dimensions back To the subroutine
    


    Try commenting out the above code to see if that could be the culprit...

    Dim Test1
    
    Set Test1 = objpart.GetVariableValue ("SUB_OUTTOLNUM")
    msgbox Test1.stringvalue


    ...and Test1 should be equal to Var.

    Also, try dim them as objects, just like you have done with Var2.
  • Commenting out that line does not work. Neither does copying and pasting the exact getvariablevalue line for Var or Var2 a bit farther UP in the code! I've tried Object and no Object, and it is not working. The only lines that work are the ones I had previously written.

    I think you can put variables in a script call, just like a subroutine call, right? I will try that.

    If this is something simple, I am giving up on scripting...Rolling eyes
  • Is this all the code? Where are you declaring objPART?
  • This is not all the code. It is part of a quite lengthy script. Sometime today I am going to start with a fresh script and do some tests to see what works and what doesnt in a new file. Here is the initial declaration of stuff:


    Dim objApp As Object
    Set objApp = CreateObject("PCDLRN.Application")
    Dim objPart As Object
    Set objPart = objApp.ActivePartProgram
    Dim objCmds 'As Object
    Set objCmds = objPart.Commands
    Dim objCmd 'As Object
    Dim objDimCmd As Object
    Dim dblOutTol As Long
    dblOutTol = 0
    Dim dblTotalMeas As Long
    dblTotalMeas = 0
  • I am just guessing cause I have not tested it BUT... is it possible that the variable is emptied after the first time? just set the variable locally once at the beginning of your script instead of twice. then use the local variable till the script is complete.

    Also, the variable should be an object and not a straight DIM

    Example of what works: Link
  • EDIT: Wrong sn, same person.

    I am not setting it twice normally. I tried to grab a new variable from the program and failed. So I slowly changed my code back until it exactly matched what I did previously in the program, including variables. It STILL did not work. Trying to copy and paste the line that worked ANYWHERE else in the program fails, whether it is before or after the line that works.

    Aside from the example I posted not having Dim __ As Object, (which I have tried as well), it matches your example exactly. Could I have done something within the script that would screw itself up so it couldnt grab the variables?
  • I started fresh, with a totally new test program and script, and I cannot get the .GetVariableValue command to work. I can SET variables just fine using .setvariablevalue. I cannot GET them at all.

    The workaround right now is passing the variables into the script through the arguments thing, same as variables into a subroutine.

    I have no idea why this is happening.
  • Now I am having problems with my workaround. When I add variables to the Sub Main () line, so it looks like this:

    Sub Main (CMMNAME As String, Workorder As String, Serialnumber As String, Clocknumber As String, Partname As String)


    I get an error message saying "Error on line 268- Unknown name: (null)"

    Line 268 is my End Sub line.

    End Sub


    What does it expect that I'm not doing? When I run the script from within a part program, no error message pops up. It still seems to execute the script correctly right to the last line, and closes all files and all that. Is it because when I am editing the script it has trouble pulling values for these variables I declare in the Sub Main () block?

    ConfusedConfused This is still very much unfamiliar terrain for me.