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.

  • I'm not sure I understand what you are saying. I'm trying to force the python script to run during the CMM program. The only way I see how to get this to work is have the CMM program call up a .BAS script which in turn calls the python script. I have it working per the code I supplied about which in essence is using the cmd to call the python script.

    I'm at a standstill now until I know exactly how to pass a variable to and from the CMM program using python syntax. I'm going to open a ticket with a rather basic example for them to see if they can show me the light. I have a comment for input labeled "C1" and all I want to do is get that variable into the python script, add a simple number to it, then pass it back. Once I do that I can get some stuff done easier than in VBA, but isn't mission critical at all.
  • I'm not the most educated programmer, but I do know how to write some decent python programs....I'm trying to get a variable from the CMM and then send it back after changing it. Are you saying that the CMM variables somehow become Environment Variables just because you import the os module? I don't understand that.


  • Here's how I would do this. I would look into some fancier way of doing it as I'm somewhat confident there's a way....


    First do this:
    1. Create a folder called Python
    2. In Python folder create two files
    • CallPythonScript.bat
    • hello_world.py
    3. Write this in your CallPythonScript.bat and save it

    @echo OFF
    python "C:\<Path of Python folder>\hello_world.py"
    


    4. Write this in your hello_world.py and save it
    print('hello world')
    


    5. In Pc-Dmis insert an external command like so
    EXTERNALCOMMAND/DISPLAY ; C:\<Path Python folder>\Python\CALLPYTHONSCRIPT.BAT
    


    Let me know if this works. If it does, I'll tell ya how to get Pc-Dmis variable values from A to B by using print commands to write to text files as a start.
  • ,

    That bat file technique is almost exactly what I am already doing using a VBA(I posted the code above)....I wasn't able to get the bat file technique to work b/c of the way our One drive is setup and where my python installation is. When I called up the bat file it kept saying an __init__ or something was not found meaning I think it was pulling up the wrong CMD or terminal that couldn't reference where my python files were....in fact I was getting this same error with every attempt to use VBA to start the python file until the version I am using above seemed to side step everything.

    I'll try the bat techinique again and report back the error message or success...I try not to bother out IT team b/c they don't really like us running scripts and such...even though I have over 10 working python scripts running alot of our CT scanning room all day long.

    I'm back in on Saturday, so I'll report back....I use txt files to export many variables for later use in python. That would be an acceptable way to go here, but I'd wonder if there was a direct way to get the variable...I was able to print a list of commands in python from pcdmis using a for loop, but if I remember when I tired to toss in an if stmt like:

    if cmd = 'C1':
    x = cmd

    if threw up an error like cmd was some strange windows object that wouldnt let itself be assigned to x. Anyway...I'll be in touch.
  • An environment variable is a variable that is held system-wide, although not meant to contain complex information/long arrays it will do what you are looking for.

    In regards to your other issue there is a nice python module called 'PyInstaller' which can make your .py files into .exe which are probably much simpler for PC-DMIS to execute