hexagon logo

python development instances for pc-dmis.

import win32com.client as w32
dmisapp = w32.Dispatch('PCDLRN.Application')
dmispart = dmisapp.ActivePartProgram
dmiscommands = dmispart.Commands

def pc_dmis_report():
    for cmd in dmiscommands:
        if cmd.IsDimension and int(cmd.DimensionCommand.OutTol)==0:
            cmd.SetToggleString(3,165,0)
        else:
            cmd.SetToggleString(4,165,0)

pc_dmis_report()
dmispart.RefreshPart()
  • I don't see why not. Going the RPi route, it's got Linux, which is extremely versatile. It could easily (for someone who knows exactly what they're doing) be used to accept inputs/control outputs to/from a CMM.
    If only I had one I could test on... :P
  • Yeah me too. Also, if I had the knowledge to be able to do this would be a big plus.
  • No luck with python 3.5 either. This could be user privilege or just a Windows 10 security again.
    Also, as you stated that this could be an install issue on my part.


    Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:38:48) [MSC v.1900 32 bit (Intel)] on win32
    Type "copyright", "credits" or "license()" for more information.
    >>>
    RESTART: C:\Users\davehocum\AppData\Local\Programs\Python\P ython35-32\PC-DMIS_Test1.py
    Traceback (most recent call last):
    File "C:\Users\davehocum\AppData\Local\Programs\Pyt hon\ Python35-32\lib\site-packages\win32com\client\dynamic.py", line 89, in _GetGoodDispatch
    IDispatch = pythoncom.connect(IDispatch)
    pywintypes.com_error: (-2147221021, 'Operation unavailable', None, None)
    During handling of the above exception, another exception occurred:
    Traceback (most recent call last):
    File "C:\Users\davehocum\AppData\Local\Programs\Pyt hon\ Python35-32\PC-DMIS_Test1.py", line 2, in <module>
    dmisapp = w32.Dispatch('PCDLRN.Application')
    File "C:\Users\davehocum\AppData\Local\Programs\Pyt hon\ Python35-32\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
    dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userN ame,clsctx)
    File "C:\Users\davehocum\AppData\Local\Programs\Pyt hon\ Python35-32\lib\site-packages\win32com\client\dynamic.py", line 114, in _GetGoodDispatchAndUserName
    return (_GetGoodDispatch(IDispatch, clsctx), userName)
    File "C:\Users\davehocum\AppData\Local\Programs\Pyt hon\ Python35-32\lib\site-packages\win32com\client\dynamic.py", line 91, in _GetGoodDispatch
    IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
    pywintypes.com_error: (-2146959355, 'Server execution failed', None, None)
    >>>


    I'm thinking that arttk is right about it being an issue with the type library not being registered. I remember having lots of issues with that a while ago, but can't remember the solution for the life of me.

    Can you try changing "dmisapp = w32.Dispatch" to "dmisapp = w32.GetActiveObject" and then running it after you've opened a test PC-DMIS program?

    ETA: I think this might have been the solution.
    http://timgolden.me.uk/python/win32_how_do_i/generate-a-static-com-proxy.html

    For me, it was:
    import sys
    from win32com.client import makepy
    
    sys.argv = ["makepy", r"C:\Program Files\Hexagon\PC-DMIS 2017 R2 64-bit\Pcdlrn.tlb"]
    makepy.main ()
  • Thank you for the info. I will give this a try asap and let you know what my results are.
  • So far, I got this. "Importing module"

    I did try changing "dmisapp = w32.Dispatch" to "dmisapp = w32.GetActiveObject" and received the same as before.

    Code:
    import sys
    from win32com.client import makepy

    sys.argv = ["makepy", r"C:\Program Files\Hexagon\PC-DMIS 2018 R1 64-bit\Pcdlrn.tlb"]
    makepy.main ()
    Generating to C:\Users\davehocum\AppData\Local\Programs\Python\Python35-32\lib\site-packages\win32com\gen_py\7B1E293F-219C-4F48-81FC-1DB24F7DC527x0x13x1.py
    Building definitions from type library...
    Generating...
    Importing module
  • arttk,
    Was not able to get past the errors.
    All I could get out of this was "Building definitions from type library..., Generating..., Importing module". Nothing happens after that.
    Then try to Run:
    Code:
    import win32com.client as w32
    dmisapp = w32.Dispatch('PCDLRN.Application')
    dmispart = dmisapp.ActivePartProgram
    dmiscommands = dmispart.Commands

    def pc_dmis_report():
    for cmd in dmiscommands:
    if cmd.IsDimension and int(cmd.DimensionCommand.OutTol)==0:
    cmd.SetToggleString(3,165,0)
    else:
    cmd.SetToggleString(4,165,0)

    pc_dmis_report()
    dmispart.RefreshPart()

    and then received the same error again.


  • I'm thinking that arttk is right about it being an issue with the type library not being registered. I remember having lots of issues with that a while ago, but can't remember the solution for the life of me.

    Can you try changing "dmisapp = w32.Dispatch" to "dmisapp = w32.GetActiveObject" and then running it after you've opened a test PC-DMIS program?

    ETA: I think this might have been the solution.
    http://timgolden.me.uk/python/win32_how_do_i/generate-a-static-com-proxy.html

    For me, it was:
    import sys
    from win32com.client import makepy
    
    sys.argv = ["makepy", r"C:\Program Files\Hexagon\PC-DMIS 2017 R2 64-bit\Pcdlrn.tlb"]
    makepy.main ()


    Googling the error message turns up this: https://stackoverflow.com/questions/49453592/python-ms-access-com-server-execution-failed
    Do you have multiple versions of PC-DMIS installed?

    Also, to double check, do you have PC-DMIS open with a PRG loaded when you run this? I get the same error if I try running the script without a program open.
  • If you have multiple PC-DMIS versions installed, it may be a mismatch between "the last version run (or installed) with admin rights" and "the currently running version". All automation programs look in HKEY_CLASSES_ROOT\PCDLRN.Application\CLSID to see what to contact when you reference "PCDLRN.Application" in your program.

    Each time PC-DMIS is started (or installed), it tries to write its own CLSID there, but it will only succeed when running with admin rights. So if you have 2018 R1 installed, but run 2017 R2, everything will just hang for a long time when the script tries to start 2018 R1 (as the Registry has informed it), something which will not succeed while 2017 R2 is still running.

    Start the PC-DMIS version you want to use once with admin rights, exit, then in the normal way and see if it makes any difference.

    Alternatively, if you have the rights, change the access rights on HKEY_CLASSES_ROOT\PCDLRN.Application\CLSID so a normal user may change it (your IT department might want to have a say about that...).
  • If the CLSID's mismatch, you might get a dialog saying "Server busy" as the COM (from the old version) tries to talk to the version that isn't started (usually the newer version).