hexagon logo

How to open a python script in pcdmis?

I've got a couple basic scripts running on our programs and you simply go to INSERT > BASIC SCRIPT and chose the .bas file. But it won't let me choose a python file .py.
I tried external command and that doesn't work and I've tried INSERT > FILE I/O COMMAND > FILE OPEN, but when I run the program it runs the program without doing anything inside the python script.

How were those running some python scripts here actually getting pcdmis to open the python script?

Thanks.

Parents
  • Appreciate the replies...I believe I was onto something last night, but my problem is at work we have One Drive and my python is installed somewhere else so I'm getting python errors. I need to have our IT look at how I'm calling the cmd.exe to run the python script.

    I don't think the external program works b/c it needs to be called with python.exe for example if you want to run a python program from cmd you need to enter 'py program.py'

    Because my work setup is on the strange side, I just tried to get a python program running from inside Excel VBA. There are many methods to do this by googling, but I found this example to be the shortest:

    Sub Main()
    
    Dim vbaShell As Object
    Set vbaShell = VBA.CreateObject("Wscript.Shell")
    vbaShell.Run """C:\Users\Owner\AppData\Local\Programs\Python\Py thon310\python.exe""" & """C:\Users\Owner\Desktop\PCDMIS.PY"""
    
    End Sub
    
    ​
    


    The python code I tested below, I simply dumped into Excel VBA and ran it from there and it worked. For anyone, unfamiliar with win32api it is a library you must install after you install python on your computer. To get win32api library open a command prompt and type in 'pip install pywin32' they have different names for some reason.

    My goal is to not learn a new language as I enjoy pythons elegance and libraries and don't have the need to learn a new language. I'd like to write programs that I can do already in 20-30 minutes instead of struggling thru vba syntax.

    import win32com.client as w32
    dmisapp = w32.Dispatch('PCDLRN.Application')
    dmispart = dmisapp.ActivePartProgram
    dmiscommands = dmispart.Commands
    
    print(dmisapp.CurrentFolder) # Location of .PRG
    input('Press any key to continue...')
    
    dmispart.RefreshPart()​
    


    I'll post my code and what I'm doing once I get this up and running. I'm sure what I'm doing can be done in VBA, but I'd much prefer using python.
Reply
  • Appreciate the replies...I believe I was onto something last night, but my problem is at work we have One Drive and my python is installed somewhere else so I'm getting python errors. I need to have our IT look at how I'm calling the cmd.exe to run the python script.

    I don't think the external program works b/c it needs to be called with python.exe for example if you want to run a python program from cmd you need to enter 'py program.py'

    Because my work setup is on the strange side, I just tried to get a python program running from inside Excel VBA. There are many methods to do this by googling, but I found this example to be the shortest:

    Sub Main()
    
    Dim vbaShell As Object
    Set vbaShell = VBA.CreateObject("Wscript.Shell")
    vbaShell.Run """C:\Users\Owner\AppData\Local\Programs\Python\Py thon310\python.exe""" & """C:\Users\Owner\Desktop\PCDMIS.PY"""
    
    End Sub
    
    ​
    


    The python code I tested below, I simply dumped into Excel VBA and ran it from there and it worked. For anyone, unfamiliar with win32api it is a library you must install after you install python on your computer. To get win32api library open a command prompt and type in 'pip install pywin32' they have different names for some reason.

    My goal is to not learn a new language as I enjoy pythons elegance and libraries and don't have the need to learn a new language. I'd like to write programs that I can do already in 20-30 minutes instead of struggling thru vba syntax.

    import win32com.client as w32
    dmisapp = w32.Dispatch('PCDLRN.Application')
    dmispart = dmisapp.ActivePartProgram
    dmiscommands = dmispart.Commands
    
    print(dmisapp.CurrentFolder) # Location of .PRG
    input('Press any key to continue...')
    
    dmispart.RefreshPart()​
    


    I'll post my code and what I'm doing once I get this up and running. I'm sure what I'm doing can be done in VBA, but I'd much prefer using python.
Children
  • I agree. I would rather use python instead of VBA. I was hoping to use python for PC-DMIS and I just found it much easier to use Visual Studio and C#. With Visual Studio it's all there for me to develop GUI, Console apps and executables all within one install. Right now I am learning the Go or golang using VS code for other projects.