hexagon logo

Modifying PCDMIS Array Variable with External Command

I want to build PCDMIS array variables externally using an EXE. As we all know, doing so within PCDMIS with a loop is slooowwwww. 

I can change simple String or Long value variables.  However, arrays are an issue.

PCDMIS Basic and PCDMIS Automation reference the methods GetVariableValue, SetVariableValue, GetArrayIndexValue, and SetArrayIndexValue.

The first two animals work.

The latter two (GetArrayIndexValue, and SetArrayIndexValue) do NOT seem to work. I get Server Automation errors with SetArrayIndexValue and zero values using GetArrayIndexValue.

Any thoughts? Clever ideas and insults welcome.

Thanks,

-Mike

Parents
  • ...and the code you are using to do this, looks like?

  •  Here's my PCDMIS simple program.

    MODE/DCC
    ASSIGN/AR1=ARRAY(0,1,2)
    ASSIGN/AR2=ARRAY(3,4,5)
    ASSIGN/V1=11
    ASSIGN/V2=22
    EXTERNALCOMMAND/NO_DISPLAY, WAIT ; C:\CMM\SCRIPTS\TEST_VARIABLE_MODIFY.EXE
    COMMENT/REPT,
    AR1
    COMMENT/REPT,
    AR2
    COMMENT/REPT,
    V1
    COMMENT/REPT,
    V2

    -----------------------------------------------------------------

    OK. Here’s the relevant code (Button Click Event in a Winform) for modifying two integer (or double) variables.

    This does work.  It will add 5 to each variable (V1 and V2) and report 16 and 27.

    Private Sub AssignV1V2_Click(sender As Object, e As EventArgs) Handles AssignV1V2_BTN.Click
    ' Update PCDMIS variables V1 and V2 at original values 11 and 22 respectively.
    Dim PCDtool As New Attach_ToPCDMIS_v1  'wrapper class for CreateObject PCDLRN.Application
    Dim PCDprg As PCDLRN.PartProgram = PCDtool.PCDLRN_ActivePRG
    Dim v1, v2 As PCDLRN.Variable

    v1 = PCDprg.GetVariableValue("V1")
    v2 = PCDprg.GetVariableValue("V2")
    v1.DoubleValue = v1.DoubleValue + 5
    v2.DoubleValue = v2.DoubleValue + 5
    PCDprg.SetVariableValue("V1", v1)
    PCDprg.SetVariableValue("V2", v2)

    PCDprg = Nothing
    PCDtool = Nothing
    End Sub '*AssignV1V2_Click(sender As Object, e As EventArgs) Handles AssignV1V2_BTN.Click

    -----------------------------------------------------------------------

    Here’s the code for modifying two Arrays of Double, AR1 and AR2. This does NOT work.

    Private Sub AssignAR12_Btn_Click(sender As Object, e As EventArgs) Handles AssignAR12_Btn.Click
    ' Update PCDMIS array variables AR1 and AR2 at original values (0,1,2) and (3,4,5) respectively.
    Dim PCDtool As New Attach_ToPCDMIS_v1 'wrapper class for CreateObject PCDLRN.Application
    Dim PCDprg As PCDLRN.PartProgram = PCDtool.PCDLRN_ActivePRG
    Dim ar1, ar2 As PCDLRN.Variable

    ar1 = PCDprg.GetVariableValue("AR1")
    ar2 = PCDprg.GetVariableValue("AR2")
    For i As Integer = 1 To ar1.GetArrayUpperBound - 1
        ar1.GetArrayIndexValue(i).DoubleValue = ar1.GetArrayIndexValue(i).DoubleValue + 10.0
        ar2.GetArrayIndexValue(i).DoubleValue = ar2.GetArrayIndexValue(i).DoubleValue + 10.0
    Next i
    PCDprg.SetVariableValue("AR1", ar1)
    PCDprg.SetVariableValue("AR2", ar2)

    PCDprg = Nothing
    PCDtool = Nothing
    End Sub '*AssignAR12_Btn_Click(sender As Object, e As EventArgs) Handles AssignAR12_Btn.Click

    The method SetArrayIndexValue with the parameters i (index) and ar1 (PCDLRN.Variable) does not work. There's no way to instantiate a PCDLRN.Variable outside of using the PCDMIS Program Object's SetVariableValue method.  So, setting an array's index value does NOT seem possible.

    Note that you can set the value of one array to another (every value from one is copied to the other).  But that's really not useful.  I want to modify and build arrays outside of PCDMIS and assign them back to a PCDMIS array variable.

    ar1.SetArrayIndexValue(i, ar1) 'Constantly throws runtime errors. 

  • Try creating two new variables (arrays) and overwrite the PC-DMIS variables with the new ones.

  • Ok. I can swap array values between AR1 and AR2 using SetVariableValue("AR1", ar2) and SetVariableValue("AR2", ar1)

    I need to create an array variable for use in the method SetVariableValue (stringVarName, VariableObject).

    Or in the Boolean Function SetArrayIndexValue (index, VariableObject).

    Both require a Variable Object for the 2nd parameter.  But Variable Objects cannot be created independently (that I know of).  The only way to create a Variable Object is to reference the PCDMIS PartProgram method GetVariableValue (stringVarName).  

    Is there another way to Create a Variable Object and populate its array?

    Note that regardless of the Variable Object used, the Boolean Function SetArrayIndexValue always throws a run-time error.  Does it only work in VBA environment?

  • If you need an additional array, say AR3, this must exist in the partprogram.
    If you need to create it (in the partprogram) use an assignment, either in the partprogram already (see above) or by your code (add the assignment to the partprogram).

    If you only need the array in your code outside the partprogram, create an array with your values and use
    PCDprg.SetVariableValue("AR1", MyNewArray)
    to populate it.

Reply
  • If you need an additional array, say AR3, this must exist in the partprogram.
    If you need to create it (in the partprogram) use an assignment, either in the partprogram already (see above) or by your code (add the assignment to the partprogram).

    If you only need the array in your code outside the partprogram, create an array with your values and use
    PCDprg.SetVariableValue("AR1", MyNewArray)
    to populate it.

Children
No Data