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
  • What exactly happens when you try your script? I don't actually have PCDMIS but use a similar program...

    There is also environment variables, which you could set in python and and use a VBA script to pull into PCDMIS, not sure how impractical that is though:

    import os
    
    os.environ["MYVARIABLE"] = "hello"
    print(os.environ["MYVARIABLE"])
    
    
    

    VBA to read the variable is Environ("MYVARIABLE")

Reply
  • What exactly happens when you try your script? I don't actually have PCDMIS but use a similar program...

    There is also environment variables, which you could set in python and and use a VBA script to pull into PCDMIS, not sure how impractical that is though:

    import os
    
    os.environ["MYVARIABLE"] = "hello"
    print(os.environ["MYVARIABLE"])
    
    
    

    VBA to read the variable is Environ("MYVARIABLE")

Children