enthought / comtypes

A pure Python, lightweight COM client and server framework, based on the ctypes Python FFI package.
Other
290 stars 97 forks source link

plugin problem #497

Closed Asseelhij closed 7 months ago

Asseelhij commented 11 months ago

Hello, I am trying the Pyaxis connection. I wrote a code that runs successfully on my laptop, but it has some issues when I try to run it on my PC (I need it to work on my PC because my AxisVM model is too heavy to run on my laptop). So, on my PC, some code snippets work fine. For example, I could open Axisvm via Python and create a new load case, but some code snippets like (patchlines = axm.ObjectCreator.NewLines3d()) give an attribute error:

(KeyError Traceback (most recent call last) File ~\anaconda3\Lib\site-packages\comtypes__init.py:274, in _cominterface_meta.new..CaseInsensitive.getattr(self, name) 273 try: --> 274 fixed_name = self.__map_case[name.lower()] 275 except KeyError:

KeyError: 'objectcreator'

During handling of the above exception, another exception occurred:

AttributeError Traceback (most recent call last) Cell In[22], line 2 1 # origo is located at the left bottom corner ----> 2 patchlines = axm.ObjectCreator.NewLines3d()

File ~\anaconda3\Lib\site-packages\comtypes__init.py:276, in _cominterface_meta.new..CaseInsensitive.getattr(self, name) 274 fixed_name = self.__map_case[name.lower()] 275 except KeyError: --> 276 raise AttributeError(name) 277 if fixed_name != name: # prevent unbounded recursion 278 return getattr(self, fixed_name)

AttributeError: ObjectCreator)

Can you help me fix this? I tried to uninstall axisvm and comtypes modules and reinstall them, but it was still not working.

thank you in advance.

junkmd commented 11 months ago

Hello.

First, I haven't fully grasped your situation, so please provide the following information:

  1. Is 'Pyaxis' a library? If so, could you provide the source code repository?
  2. Please tell me the version of Python you used.
  3. Share the code that worked successfully on both your laptop and PC.

Additionally, if you can provide the results in a code block format as shown here: https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks#fenced-code-blocks, it would be greatly appreciated.

Asseelhij commented 11 months ago

Thank you for your reply,

Pyaxis is a Python package for AxisVM. you can find more here (https://github.com/AxisVM/pyaxisvm).

I'm using Python 3.11.4 on my laptop and 3.12.0 on my PC.

I will write the code here then point out the code blocks that don't work on my pc.

import axisvm
import comtypes
import comtypes.client as cc
import sys
from time import sleep
# Define AX_APP_PROGID for the AxisVM application
AX_APP_PROGID = 'AxisVM.AxisVMApplication'

#Define AX_APP_PROGID for the AxisVM application
AX_APP_PROGID = 'AxisVM.AxisVMApplication'

# Import the 'ax' module for AxisVM
try:
    import comtypes.gen._0AA46C32_04EF_46E3_B0E4_D2DA28D0AB08_0_17_200 as ax
    print("AxisVM module imported!")
except:
    print("AxisVM module import error !")

# Define the StartAxisVM() function as in the first code snippet
def StartAxisVM(): 
    axApp = None
    try:
        axApp = cc.CreateObject(AX_APP_PROGID, comtypes.CLSCTX_ALL, None, ax.IAxisVMApplication)
        print("AxisVM object created")
    except:
        print("error creating the object!")
        sys.exit()
    if not axApp is None:
        if WaitForAxisVM_loaded(axApp):
            axApp.Visible = ax.lbTrue
            axApp.CloseOnLastReleased = ax.lbFalse
            axApp.AskCloseOnLastReleased = ax.lbTrue
            axApp.AskSaveOnLastReleased = ax.lbTrue
            axApp.ApplicationClose = ax.acEnableNoWarning
            return axApp
    if axApp is None:
        print("AxisVM start error !")
        exit()

# Define the WaitForAxisVM_loaded() function as in the first code snippet
def WaitForAxisVM_loaded(aAxApp):
    try:
        while not (aAxApp.Loaded == ax.lbTrue):
            sleep(0.1)
            print("waiting")
        return True
    except:
        return False

# Rest of the code for loading the model from file
model_file_path = "C:/Users/user/Downloads/OLD BRIDGE - TENDONS INSIDE CONCRETE - successfull analysis.axe"

try:
    axApp = StartAxisVM()
    axModel = axApp.Models[1]

    axModel.LoadFromFile(model_file_path)

    print(f"Model '{model_file_path}' loaded successfully.")
except Exception as e:
    print(f"Error loading model: {str(e)}")
# Define the AxisVM model
axm = axModel
#Load Case 1 - Constant distributed vertical load on the whole domain
lcid1 = 1
axm.LoadCases.Name[1] = 'LC1'

the next code block only works on my laptop and on my PC gives an error.

qz = -1.0  # load intensity

LoadDomainConstant = axtlb.RLoadDomainConstant(
    LoadCaseId=lcid1,
    DomainId=121,
    qx=0,
    qy=0,
    qz=qz,
    DistributionType=axtlb.sddtSurface,
    SystemGLR=axtlb.sysGlobal
)
_ = axm.Loads.AddDomainConstant(LoadDomainConstant)

The result of the code is to open a file (model on AxisVM) and define a load case.

junkmd commented 11 months ago

Thank you for the information. Please try the following:

  1. Since the Python version differs between your laptop and PC, try running it on your PC with Python 3.11.4. (comtypes hasn't been tested on Python 3.12 in CI yet. We are waiting for the support for Python 3.12 to be added on Appveyor.)

  2. comtypes generates Python modules based on the COM library contents in the execution environment. Check the contents of comtypes.gen._0AA46C32_04EF_46E3_B0E4_D2DA28D0AB08_0_17_200.

  3. I checked requirements.txt in pyaxisvm, and it's locked to comtypes==1.1.11. Try it with the latest version, 1.2.0.

Asseelhij commented 11 months ago

thank you for your recommendations, I tried to degrade Python to 3.11.5 it didn't work, I realized that I had Python downloaded by itself and inside Anaconda, I uninstalled the Python version which is outside anaconda. also, comtypes 1.2 is noncompatible with axisvm package. I got this error (ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. axisvm 1.0.5 requires comtypes==1.1.11, but you have comtypes 1.2.0 which is incompatible.)


From: Jun Komoda @.> Sent: Tuesday, October 17, 2023 5:01 AM To: enthought/comtypes @.> Cc: Za'al Ode Al-Hijazeen Asseel @.>; Author @.> Subject: Re: [enthought/comtypes] plugin problem (Issue #497)

Thank you for the information. Please try the following:

  1. Since the Python version differs between your laptop and PC, try running it on your PC with Python 3.11.4. (comtypes hasn't been tested on Python 3.12 in CI yet. We are waiting for the support for Python 3.12 to be added on Appveyorhttps://github.com/appveyor/ci/issues/3879.)

  2. comtypes generates Python modules based on the COM library contents in the execution environment. Check the contents of comtypes.gen._0AA46C32_04EF_46E3_B0E4_D2DA28D0AB08_0_17_200.

  3. I checked requirements.txt in pyaxisvm, and it's locked to comtypes==1.1.11https://github.com/AxisVM/pyaxisvm/blob/37dd19272bb6ec63a64e6948001570167b86abd8/requirements.txt#L8. Try it with the latest version, 1.2.0.

— Reply to this email directly, view it on GitHubhttps://github.com/enthought/comtypes/issues/497#issuecomment-1766274052, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BDCWSVGYC32ABQLHIQUADEDX7ZXRLAVCNFSM6AAAAAA6DPVDUSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONRWGI3TIMBVGI. You are receiving this because you authored the thread.Message ID: @.***>

junkmd commented 11 months ago

Did you find any differences in the codebase of comtypes.gen._0AA46C32_04EF_46E3_B0E4_D2DA28D0AB08_0_17_200 on your laptop and PC?

Are there any differences in the contents of _methods_ and _disp_methods_ for each class defined within the module?

EwoutH commented 11 months ago
  1. Since the Python version differs between your laptop and PC, try running it on your PC with Python 3.11.4. (comtypes hasn't been tested on Python 3.12 in CI yet. We are waiting for the support for Python 3.12 to be added on Appveyor.)

AppVeyor updated their images with Python 3.12 (https://github.com/appveyor/ci/issues/3879).

junkmd commented 7 months ago

@Asseelhij Is there an update on this issue?

Asseelhij commented 7 months ago

@junkmd I am using Python 3.11.5 and comtypes 1.1.11 and it works perfectly.

junkmd commented 7 months ago

I suspect that the generated module under comtypes.gen was a partial file, as mentioned in #114.

Since comtypes==1.1.11 does not support Python==3.11, I think that pyaxisvm will not work with Python>=3.11 as long as pyaxisvm requires comtypes==1.1.11.