Calling a function of DLL from Python

Calling a function of DLL from Python

theshoaib.mughal
Advocate Advocate
337 Views
1 Reply
Message 1 of 2

Calling a function of DLL from Python

theshoaib.mughal
Advocate
Advocate

Hello everyone,

 

My question relates to the custom component creation using Python Scripting. I am sure you are familiar with this approach but as a recap;

  1. Type in the python script to create the needed geometry and save it in CustomScript folder
  2. Compile it from autocad plant 3d using PLANTREGISTERCUSTOMSCRIPT
  3. test is using TESTACPSCRIPTS method

Now, what I want is a way to call some boolean function TEST from a DLL file placed inside CustomScript folder as well and check whether it returned a true or false. so far what I have tried is this;

 

import clr
clr.AddReference("SampleDLL")
from SampleDLLNameSpace import SampleDLL

def SAMPLECODE(ID="SAMPLECODE", **kw):
    if(SampleDLL.TEST):
        print("OK")
    else:
        print("NOT OK")

and

import ctypes

def SAMPLECODE(ID="SAMPLECODE", **kw):
    lib = ctypes.CDLL("SampleDLL")
    if(lib.TEST):
        print("OK")
    else:
        print("NOT OK")

 

When i try and compile the script using PLANTREGISTERCUSTOMSCRIPT command, it throws an error in both cases;

ModuleNotFoundError: No module named '_clr'

ModuleNotFoundError: No module named '_ctypes'

So any thought on how can I call the function from an external DLL file. Your help is always appreciated

0 Likes
338 Views
1 Reply
Reply (1)
Message 2 of 2

matt.worland
Advisor
Advisor

import ctypes had worked in the past, unfortunately Autodesk removed that import in newer versions. It would be great if they added it back in.

If my reply was helpful, please give a "Thumbs Up" or "Accept as Solution"