What's new

IronPython

dnichols

New Member
Hi Everyone-

I'm trying to use the API to build multiple assemblies. (I've probably got 400+ assemblies to build from maybe 75 parts.) I'm not a COM or .NET programmer, but I've written quite a few scripts in Python. The book IronPython in Action arrived two days ago and so far I'm making progress.

I figure I'd post code as I go along for other to look at and (hopefully) learn from. If you have any suggestions or examples I'd love to see them.

So, with that said, here's a quick and dirty way to get AlibreX.dll imported into IronPython.

Code:
import sys
sys.path.append(r'c:\Program Files\Alibre Design\Program')  #Got to be able to find AlibreX.dll
import clr
clr.AddReferenceToFile('AlibreX')
import AlibreX

You can type in the lines above into the command line interpreter and then add the following:

>>> interfaces = [entity for entity in dir(AlibreX)} #Build a list of all interfaces in AlibreX
>>> len(interfaces)
212
>>> print [entity for entity in interfaces if entity.startswith('Au')]
['AutomationHook']
 

aeromorrison

Senior Member
The possibilities are pretty exciting with this.

I do a lot of Python application programming (not with the Alibre API....yet), but there is a *lot* of potential with this.
 

WoodWorks

Alibre Super User
This is great. It was not possible to get Python to link to the Alibre API, and I abandoned it.

I also noticed there is an IronRuby, for you SketchUp/Ruby programmers out there. Maybe that will work too?

My first program just returned the Alibre version number. Once that was running, it was smooth"er" going from there.
Most of my programs concentrate on manipulating parameters.

I found I have had to use a mix of VisualBasic, and AutoHotKey to fill in where the Alibre API does not support certain functions.
VisualBasic because I thought most other beginning users would use that rather than C++ or C#.


Please share a baseline or other programs you create in IronPython. Maybe a new special thread in the Binaries section (like the AutoHotKey thread).
 

WoodWorks

Alibre Super User
dnichols - There is a typo in the following line of your post as it should end with ] and not }:

>>> interfaces = [entity for entity in dir(AlibreX)] #Build a list of all interfaces in AlibreX

Thank you for posting these snippets of code as I have been playing with them and reading the first free chapter online of IronPython in Action. Now that I have finished the first chapter, and verified that I can actually get to the Alibre API, I just have to learn Python and create a standard template for test coding. Still need to learn how to get that first program to run that gives me the Alibre Version # (but I have forgotten anything I originally learned about Python).

Buying the ebook tonight and and looking forward to trying to learn to code with IronPython.
 

WoodWorks

Alibre Super User
What about development environment?

Visual Studio 2010 Professional is too expensive for part time coding.

What about Eclipse? Any others?
 

aeromorrison

Senior Member
IDLE isn't too bad. It comes with a standard Python installation. Spyder is a bit more sophisticated. Eclipse is pretty heavy-duty, but comes with quite a bit of overhead.

Once you get comfortable with Python, running interactively isn't even too bad.

Just a couple of ideas.
 

WoodWorks

Alibre Super User
Re: IronPython Development Environments

As for FREE IronPython Development environments:

SharpDevelop (#Develop) looks the most promising with forms creation and partial code completion (.NET 4.0 support beta due within weeks)

Iron Python Tools for Visual Studio 10 and free Visual Studio 2010 Integrated Shell (http://ironpython.net/tools/download/) - This release is still an early Community Technical Preview

Eclipse and PyDev (http://marketplace.eclipse.org/content/ ... de-eclipse)
 

WoodWorks

Alibre Super User
I use the Windows Visual Studio Express tools when I program in Visual Basic (and try other peoples programs in C++ and C#). They are great tools, and that is why I am concerned about a development environment for IronPython.

The IronPython add-in only work for the Professional Version of higher of Visual Studio 2010.

I spend most of my time developing Alibre models, and a bit of time developing programs to simplify and support that modeling. I have even paid to have the complicated programs developed for me. Maybe someday I will become proficient enough to spend more time programming, but for now it is sporadic enough that I remain a novice.

Most of my programs are short utility programs which are simple console applications (without any interactive window). Just too much to be suited for an interactive run.

I am comfortable using VisualBasic and AutoHotKey, but Python has the potential to allow me to write scripts as well as programs and combine the benefits of both.

A new toy with potential to aid in my Alibre modeling. (Hey, what about IronRuby as I hear Ruby has some great advantages too!)
 

aeromorrison

Senior Member
I do quite a bit of programming in Visual Basic/.NET as well as Python. In my experience, the high-end development environments are more necessary with Visual Basic/.NET than they are with Python--especially the debuggers!. Clear error-handling, reporting, inherently clean code, and general usability make highly capable IDEs, in my opinion, generally unnecessary for Python development--even for novices. For equivalent functionality, I my development time for Python applications is 3-5 times faster without a high-end IDE than Visual Basic/.NET with a high-end IDE.

Of course, everybody has their favorite coding setup...sort of like your favorite pair of jeans. This is just my 2 cents.

Thanks for the good discussion.
 

WoodWorks

Alibre Super User
Here is my version of a baseline IronPython program that provides the Alibre Design version number (Alibre must be running with at least the Home window open):

import sys
sys.path.append(r'c:\Program Files\Alibre Design\Program') #Point to location of AlibreX.dll
import clr
clr.AddReferenceToFile('AlibreX.dll')
import AlibreX
from System.IO import *
from System.Runtime.InteropServices import *

hook = Marshal.GetActiveObject('AlibreX.AutomationHook') # Hook Alibre Design - Alibre must be running
root = hook.Root

print("Version: " + root.version) # Write out the Alibre Design version
 

WoodWorks

Alibre Super User
While I find the IronPython interpreter useful for debugging code, I have a few questions:

1. How do you load existing code you don't want to have to retype during each session (like all the stuff to setup the Alibre Hook)?

2. How do you save the new code you have just entered/debugged with the Interpreter?

The books and tutorials just seem to skip over these seemly unimportant items. I am a total novice to Python and modern programming, as my introduction to programming was FORTRAN-66 and punch cards. That is why I am probably more comfortable with a Development Environment and Compiler.

Also, my current use of the API are short programs launched with an AutoHotKey shortcut, that run and modify a currently open Alibre file, while I am still in Alibre and working on a design:
Lock/Unlock ALL configurations
Import parameter values in to EXISTING parameters (Alibre only lets you import new parameters)
Count Configurations
Update Part Data (with the help of AutoHotKey to actually update the data)
 

WoodWorks

Alibre Super User
dnichols, any progress with IronPython in Action?

I seem to be stuck at a roadblock in trying to list all the Configurations in a part. Just can't make that transition from VisualBasic to IronPython.

Can you or anyone else be of help to a "cookbook" programmer?
 

aeromorrison

Senior Member
WoodWorks,

I'm sure that I could be of help. However, I am totally buried in work right now, so I probably won't get a chance to make any progress here for a couple of weeks. I'll keep you posted when I get a chance to make some headway.
 

WoodWorks

Alibre Super User
aeromorrison, A couple of weeks is fine. This Python programming is a as time permits for me.

I am basically converting Alex Franke's sample program (Version, Loop through and Count/Display Configurations).
My main problem is the looping through the Configurations.

It is the basis of most of my Parameter and Configuration programs. I have them running in Visual Basic, but I
think IronPython might have some advantages, and wish to learn more. Thanks
 
Top