What's new

Automation using Python and win32all

Automation using Python and win32all

Hello,

My name is Duane, and I was wondering if anyone here had successfully (or not!) 'driven' Alibre through its COM API using Python.

If you have, could you please help a newbie out with some examples?

Thanks!
Duane
 

modtek

Member
API in Python

Hello Duane,

Try contacting "Woodworks". In one of his the earlier posts, he had mentioned about using Python for API.

With regards,

Mod-Tek
 

WoodWorks

Alibre Super User


I tried using Active State Python with the COM interface included, and was unable to get a working program. I think that there is a problem with my installation as I could not even get the examples using COM with Excel to work for me. My next step will be to try an installation using Python with the free COM extension. If you get the standard examples working with any Python COM package, let me know and I will assist in getting the correct code running for a programming template. I am not a programmer like Modtek, but I am doing simple routines to automate short tasks.

I instead have been concentrating on using the Microsoft Visual Basic Express edition because it is FREE, and has dialog box capabilities (which are not as well developed in Python). The other advantage of Visual Basic is the ability to use the same programming language to create programs in Excel to drive Alibre models.

For quick routines (which I was looking to Python to create), I have instead been using Macro Express, which provides keystroke and mouse macro capability for any installed program. I like that software because I can use my experience in programming for any software package, and not have to learn another proprietary programming language. It takes a little getting used to writing macros for Alibre, but it is basically keystroke programming using the menus and selections as well as keyboard shortcuts. I am getting quite sophisticated with macros, and will try to update the macros posted on my website when I get some time in July.

You can contact me via private message, or via the email link at my website at http://www.kelseywoodworks.com.
 

demarchi

Senior Member


Hi,
I am interested in the possibility to use of python.
I checked the python installations fro http://www.python.org and the pywin32 extensions ( https://sourceforge.net/projects/pywin32/ ), and it looks it should be possible to connect to the Alibre API.

in fact

Code:
import win32com.client
adhook = win32com.client.DispatchBaseClass(\"AlibreX.AutomationHook\")

Returns exit code status 0. Nonetheless I don't know how to go on.
Anyone can help?

I would also point out the wxpython project offers the possibilty ot build a GUI, and it might prove a nice solution.

Thanks,
Massimo
 

cclark440

Alibre Super User


While I have never used python, this is the code for Visual Basic
Code:
    Dim objHook As AlibreX.AutomationHook   'Define the Alibre hook
    Dim objRoot As AlibreX.IADRoot          'Define the Root to work with

    objHook = GetObject(, \"AlibreX.AutomationHook\") 'Create the Alibre hook
    objRoot = objHook.Root                  'Create the Root to work with

I would imagine that the next steep you need to take is to create the Root object. Once this is done you should have access to all the API offers.
 

demarchi

Senior Member


I tried to create the root object, but I got an error.

I'm surely missing something simple, but I have no clue.
 

cclark440

Alibre Super User


Just a question,

Why are you using python? Are you already familiar with it?
You can download VB 2005 Express edition for free from Microsoft.
I tried a couple different environments before I started using VB, but VB ended up being the easiest to get started with. Plus its code completion feature is very handy as it shows you all of the available properties and methods as you write the code.
 

demarchi

Senior Member


I'm not familiar with Python, I used Delphi and friends, PHP, and a little bit of Perl.
I was interested in the language because I am planning to write some scripts also under Linux, and VB is obviosly not a solution. The idea was to get in touch with Python, and use it in both operating systems. The COM support and the wxpython extensions ringed a bell...
By the way the pythonwin editor offers code completion too, and a COM browser.
Nonetheless getting started is not so easy...
 
Automation using Python and win32all

Hi,

I have been working a bit on this, and in conjunction with developers using Python and COM, seem to have arrived at what was causing us difficulty (see end of this message for E-mail explanation)

The issue seems to be that the Alibre COM object does not support calling through the COM IDispatch process. Since VB doesn't use that interface, it works OK.

I would (respectfully, of course) request from the Alibre development team, looking into fixing this deficiency in the COM interface, which would then open up automation of Alibre to many other platforms and languages.

I am more than willing to help with this!

Thanks,
Duane


(Attached E-mail response)

> Hello,
>
> I am trying to use pywin32 to automate a CAD package from Alibre (http://www.alibre.
com) called Design Express.
>
> The documentation I can get is written for Visual Basic (and not all that
well at that), and I get the following error from the following lines:
>
> [Python Code]
> import win32com.client
> AlibreObject=win32com.client.Dispatch(r"AlibreX.
AutomationHook")
> [End Python code]
>
> Error traceback:
> AlibreObject = win32com.client.Dispatch(r"AlibreX.AutomationHook")
> File "C:\\Python24\\Lib\\site-packages\\win32com\\client\\__init__.py", line 95,
in Dispatch
> dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,
userName,clsctx)
> File "C:\\Python24\\Lib\\site-packages\\win32com\\client\\dynamic.py", line 98,
in _GetGoodDispatchAndUserName
> return (_GetGoodDispatch(IDispatch, clsctx), userName)
> File "C:\\Python24\\Lib\\site-packages\\win32com\\client\\dynamic.py", line 78,
in _GetGoodDispatch
> IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.
IID_IDispatch)
> pywintypes.com_error: (-2147467262, 'No such interface supported', None, None)
>

The problem seems that the COM object that Alibre implements is buggy.
According to the
type library (I've installed the free Express version) the call above should
return an
object that implements the IAutomationHook interface, which is derived from
IDispatch:

[
odl,
uuid(424539A8-7014-4174-B0BF-F5EE5BB71DF5),
helpstring("IAutomationHook interface"),
dual,
oleautomation
]
interface IAutomationHook : IDispatch {
[id(0x00000001), propget, helpstring("Returns the automation root")]
HRESULT Root([out, retval] IDispatch** ppRoot);
[id(0x00000002), helpstring("Initiates a new Alibre Design Automation
client")]
HRESULT Initialize(
[in] BSTR serverURL,
[in] BSTR loginID,
[in] BSTR passwd,
[in] VARIANT_BOOL disableSecureMode,
[in] int unused);
[id(0x00000003), helpstring("Initiates a new Debug client")]
HRESULT InitializeDebug(
[in] BSTR serverURL,
[in] BSTR loginID,
[in] BSTR passwd,
[in] VARIANT_BOOL disableSecureMode,
[in] int unused);
};

Experiments with comtypes (the ctypes com framework) show that the
object can successfully be QueryInterface'd for IAutomationHook, but not
for IDispatch. I'm not sure pywin32 can handle such a buggy object,
but you could probably try to run makepy on the typelib and then
create the object. Others may have more knowledge if or how this
would work.

Thomas
 
Top