hexagon logo

How to pass a variable to and from PCDMIS using Python?

I wanted to open a thread for only this issue. There is some simple, but cool stuff I'd like to do if I could simply pass a variable to and from PCDMIS and Python.

I'd prefer not having to use a notepad temporary txt file that is the workaround for passing variables.

Below is the code in python that seems like the correct syntax to pass the variables, but it isn't working. You're my hero if you have the solution ;)

import win32com.client as w32

# Connect to PCDMIS
dmisapp = w32.Dispatch('PCDLRN.Application')
dmispart = dmisapp.ActivePartProgram

# Retrieve the value of the variable "SHORTLOT"
# The VBA script to do this would be the following syntax:
# Dim Var As Object
# Set Var = dmispart.GetVariableValue ("SHORTLOT")

# The python syntax similar to the above approach does not work:
short_lot_value = dmispart.GetVariableValue("SHORTLOT")


# Set the value of the variable "SHORTLOT"
# The VBA Script to do this is:
# dmispart.SetVariableValue "SHORTLOT", short_lot_value

# The python method would seem to be this but doesn't work:
short_lot_value = "LOT-123456"
dmispart.SetVariableValue("SHORTLOT", short_lot_value)

Parents
  • I don't normally use python, so if I get some particular wrong, you'll have to excuse me. The reason it doesn't work is because you are treating an object as a string. The dmispart.GetVariableValue function returns an object of type variable. You have to define an object for that, e.g., dmisvar = dmispart.GetVariableValue("SHORTLOT"). Then you use that object's properties to get or set the value.

    import win32com.client as w32
    
    dmisapp = w32.Dispatch("PCDLRN.Application")
    dmispart = dmisapp.ActivePartProgram
    dmisvar = dmispart.GetVariableValue("SHORTLOT")
    
    short_lot_value = dmisvar.StringValue
    # OR
    dmisvar.StringValue = "LOT-123456"

  •  

    Thanks for the reply. I'll give that a shot. in the coming weeks and report back how it is working. Here is the code I'm going to try to pass back a variable to PCDMIS from python.

    import win32com.client as w32
    
    # Connect to PCDMIS
    dmisapp = w32.Dispatch('PCDLRN.Application')
    dmispart = dmisapp.ActivePartProgram
    dmisvar = dmispart.GetVariableValue("SHORTLOT")
    
    dmisvar.StringValue = "LOT-123456"
    
    dmispart.SetVariableValue("SHORTLOT", dmisvar.StringValue)
    
    
    

Reply
  •  

    Thanks for the reply. I'll give that a shot. in the coming weeks and report back how it is working. Here is the code I'm going to try to pass back a variable to PCDMIS from python.

    import win32com.client as w32
    
    # Connect to PCDMIS
    dmisapp = w32.Dispatch('PCDLRN.Application')
    dmispart = dmisapp.ActivePartProgram
    dmisvar = dmispart.GetVariableValue("SHORTLOT")
    
    dmisvar.StringValue = "LOT-123456"
    
    dmispart.SetVariableValue("SHORTLOT", dmisvar.StringValue)
    
    
    

Children