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()
Parents
  • 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 ()
  • 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
Reply
  • 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
Children
No Data