GetVariableValue Problem

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • GetVariableValue Problem

    Dear guys:

    about the method "GetVariableValue",the help file says like this--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.

    when my mouse enter the parameter,it shows the result on the screen.but how can i get that value?(offline software,but the program has been run before)



    string ReturnValue="";
    Variable tmpVarValue;
    pcdPartProgram = pcdSession.ActivePartProgram;
    tmpVarValue = pcdPartProgram.GetVariableValue(VarName);
    if (tmpVarValue.VariableType == VARIABLE_TYPE_TYPES.VARIABLE_TYPE_STRING)
    {
    ReturnValue = tmpVarValue.StringValue;
    }
    else if (tmpVarValue.VariableType == VARIABLE_TYPE_TYPES.VARIABLE_TYPE_DOUBLE)
    {
    ReturnValue = tmpVarValue.DoubleValue.ToString("F3");
    }
    else if (tmpVarValue.VariableType == VARIABLE_TYPE_TYPES.VARIABLE_TYPE_LONG)
    {
    ReturnValue = tmpVarValue.LongValue.ToString("F3");
    }

    then i get 0.000,whie the shown result is -0.071.and i wanna get the value -0.071



    QQ拼音截图未命名.bmp

  • #2
    Can't see the tiny screenshot btw.



    Have you checked you are catching the Type properly?

    string ReturnValue="";
    Variable tmpVarValue;
    pcdPartProgram = pcdSession.ActivePartProgram;
    tmpVarValue = pcdPartProgram.GetVariableValue(VarName);
    if (tmpVarValue.VariableType == VARIABLE_TYPE_TYPES.VARIABLE_TYPE_STRING)
    {
    messagebox.show("String")
    ReturnValue = tmpVarValue.StringValue;
    }
    else if (tmpVarValue.VariableType == VARIABLE_TYPE_TYPES.VARIABLE_TYPE_DOUBLE)
    ​​​​​​​messagebox.show("Double")
    {
    ReturnValue = tmpVarValue.DoubleValue.ToString("F3");
    }
    else if (tmpVarValue.VariableType == VARIABLE_TYPE_TYPES.VARIABLE_TYPE_LONG)
    ​​​​​​​messagebox.show("Long")
    {
    ReturnValue = tmpVarValue.LongValue.ToString("F3");
    }

    Have you tried it at runtime?
    Automettech - Automated Metrology Technology

    Comment


    • #3
      I use GetText for retrieving variable values, snippet from my program logger (full source somewhere in this forum):

      Code:
      'Assignment To look For
      varname = "WATCHER"
      ' Is it enabled?
      sstate = ""
      
      For cnt = 1 To PCDCommands.Count
        Set PCDCommand = PCDCommands.Item(cnt)
        If ((PCDCommand.Type = 195) And (varname = PCDCommand.GetText(DEST_EXPR, 0))) Then
          wvar = PCDCommand.GetText(SRC_EXPR, 0)
      
        If wvar = """""" Then
            sstate = " started @ "
            retval = PCDCommand.PutText("""TRUE""", SRC_EXPR, 0)
        End If
        If wvar = """TRUE""" Then
            sstate = " ended   @ "
            retval = PCDCommand.PutText("""""", SRC_EXPR, 0)
        End If
      The code is looking for a variable (assignment) called "WATCHER", when this is found and the contents of the variable is null we set it to "TRUE". Is it already "TRUE" then we clear it (empty). Note that this actually changes the assignment command in the program.
      Last edited by vpt.se; 06-10-2019, 07:28 AM.
      PC-DMIS CAD++ 2o19 R1 SP2

      Comment


      • #4
        Originally posted by NinjaBadger View Post
        Can't see the tiny screenshot btw.



        Have you checked you are catching the Type properly?

        string ReturnValue="";
        Variable tmpVarValue;
        pcdPartProgram = pcdSession.ActivePartProgram;
        tmpVarValue = pcdPartProgram.GetVariableValue(VarName);
        if (tmpVarValue.VariableType == VARIABLE_TYPE_TYPES.VARIABLE_TYPE_STRING)
        {
        messagebox.show("String")
        ReturnValue = tmpVarValue.StringValue;
        }
        else if (tmpVarValue.VariableType == VARIABLE_TYPE_TYPES.VARIABLE_TYPE_DOUBLE)
        messagebox.show("Double")
        {
        ReturnValue = tmpVarValue.DoubleValue.ToString("F3");
        }
        else if (tmpVarValue.VariableType == VARIABLE_TYPE_TYPES.VARIABLE_TYPE_LONG)
        ​​​​​​​messagebox.show("Long")
        {
        ReturnValue = tmpVarValue.LongValue.ToString("F3");
        }

        Have you tried it at runtime?


        Not yet.
        when i set my mouse on "UZZ",it shows "UZZ=0".but when i set my mouse on "OBTAIN("FA(N0001)",5,0)",it shows "OBTAIN("FA(N0001)",5,0)=-0.071".the command is as follows:

        ASSIGN/UZZ=OBTAIN("FA(N0001)",5,0)


        i need get the UZZ=-0.071.


        many thanks for your reply,Ninja.thank you very much!

        now we have a case to trans some varvalues to the automation system from programs which have been run.

        Comment


        • #5
          Originally posted by vpt.se View Post
          I use GetText for retrieving variable values, snippet from my program logger (full source somewhere in this forum):

          Code:
          'Assignment To look For
          varname = "WATCHER"
          ' Is it enabled?
          sstate = ""
          
          For cnt = 1 To PCDCommands.Count
          Set PCDCommand = PCDCommands.Item(cnt)
          If ((PCDCommand.Type = 195) And (varname = PCDCommand.GetText(DEST_EXPR, 0))) Then
          wvar = PCDCommand.GetText(SRC_EXPR, 0)
          
          If wvar = """""" Then
          sstate = " started @ "
          retval = PCDCommand.PutText("""TRUE""", SRC_EXPR, 0)
          End If
          If wvar = """TRUE""" Then
          sstate = " ended @ "
          retval = PCDCommand.PutText("""""", SRC_EXPR, 0)
          End If
          The code is looking for a variable (assignment) called "WATCHER", when this is found and the contents of the variable is null we set it to "TRUE". Is it already "TRUE" then we clear it (empty). Note that this actually changes the assignment command in the program.
          thank you vpt.i tried this method,then i got "OBTAIN("FA(N0001)",5,0)",or other expressions(such as "ABS(A-B)")

          Comment


          • vpt.se
            vpt.se commented
            Editing a comment
            That is because the value of UZZ really is "OBTAIN("FA(N0001)",5,0)"... It seems you are trying to call a function and have the result of that function put in UZZ?

            Is OBTAIN a PC-DMIS function?

        • #6
          thank you vpt! it is a expression.i should calculate the expression,then get its value.

          but how can i calculate the different expressions?any demo?
          Last edited by quentin66; 06-10-2019, 08:44 PM.

          Comment


          • #7
            Try prefixing the expression with an accent grave:

            From
            Code:
            ASSIGN/UZZ=OBTAIN("FA(N0001)",5,0)
            to
            Code:
            ASSIGN/UZZ=´OBTAIN("FA(N0001)",5,0)
            and see if that works.

            Other than that, read up on chapter 26 in the helpfile...
            Last edited by vpt.se; 06-11-2019, 02:09 AM.
            PC-DMIS CAD++ 2o19 R1 SP2

            Comment


            • #8
              Originally posted by quentin66 View Post
              when i set my mouse on "UZZ",it shows "UZZ=0"
              Never trust the variable value you see on mouse pop-up - it is often not what's expected. Execute the program, and show the value with a COMMENT.

              AndersI
              SW support - Hexagon Metrology Nordic AB

              Comment


              • #9
                you tell the true,thank you. but in this case,the program is executed by other automation system,and the program is cleared when finish.

                i should reopen the program and transfer some varValues to the database.

                Comment


                • #10
                  I think that's too late - write the variables to a file in the original program execution.
                  AndersI
                  SW support - Hexagon Metrology Nordic AB

                  Comment


                  • #11
                    Originally posted by AndersI View Post
                    I think that's too late - write the variables to a file in the original program execution.
                    yeah.but some third party equipment vendors equipped with simplified pcdmis( file output is not supported)

                    Comment

                    Related Topics

                    Collapse

                    Working...
                    X