Python?

Python?

Anonymous
Not applicable
3,551 Views
32 Replies
Message 1 of 33

Python?

Anonymous
Not applicable
Just wondering if there had been any talk (unofficial) of using Python as the scripting interface to Inventor now that VBA is being phased out by Microsoft. PyIV has a nice ring to it!
0 Likes
3,552 Views
32 Replies
Replies (32)
Message 2 of 33

Anonymous
Not applicable
Well we could always use Ruby, that way the language would be common with SketchUp! Or maybe Java even.

Seriously, is VBA really being dropped??
I use it in Inventor, ACAD, Word and use VB6 as my preferred language (started with VB3). The thought of learning a new language fills me with dread! (old dog, new tricks).
0 Likes
Message 3 of 33

Anonymous
Not applicable
>Well we could always use Ruby, that way the language would be common with SketchUp!

I thought it was weird that Google uses Python for its web dev, but then used Ruby for SketchUp. I'm sure there's a good reason.

>Seriously, is VBA really being dropped??
this is what I heard, also repeated by Brian(?) on this forum (maybe)
http://en.wikipedia.org/wiki/Visual_Basic
0 Likes
Message 4 of 33

Anonymous
Not applicable
"I thought it was weird that Google uses Python for its web dev, but then used Ruby for SketchUp. I'm sure there's a good reason."

I think the good reason was that Ruby on SketchUp pre-dated the purchase by Google, Ruby was free (would have suited @Last) and available for both Windows & Mac (again would have suited @Last).

Of course I may be wrong.
0 Likes
Message 5 of 33

rschader
Advocate
Advocate
Have you guys looked at my COMPLETELY ignored post(s) from 5/14/08 about the replacement for VBA (VSTA)? That's the most likely candidate for replacing VBA in Inventor, but my question was totally ignored, same as my last few posts have been, here is the text of my original posts:

Subject: VSTA as replacement for VBA in Inventor.

It looks like this "update" for VBA called VSTA (Visual Studio Tools for Applications) has been around SINCE VS2005! Yet no mention here of any plans to switch over to this new technology, especially with the advent of 64 bit Inventor which has some serious issues with 32 bit VBA? I am sorely disappointed!

Bob S.

http://msdn.microsoft.com/en-us/vs2005/aa700828.aspx

and VSTA 2.0 is due out soon:
http://msdn.microsoft.com/en-us/vsx2008/products/bb933739.aspx

and

BTW, it looks like Autodesk may already be planning this, since they have already implemented VSTA for Autodesk Revit 2009.

http://www.integr-8.com/besidethecursor/2008/04/vsta-for-revit-architecture-install.html

So why did Revit get it first instead of Inventor?
0 Likes
Message 6 of 33

Anonymous
Not applicable
>Have you guys looked at my COMPLETELY ignored post(s) from 5/14/08 about the replacement for VBA (VSTA)?

no, not at all, I think it was your posts I was reading.

BTW, are you a Pythonista Bob?
0 Likes
Message 7 of 33

Anonymous
Not applicable
Well, I do think Python is a very good programming language and well developed,
but I never really got into it much. I was more familiar with php or perl in the
past. I would very much like to see Autodesk add python as a scripting language,
but I think that will happen about the same time they roll out that version
of Inventor that run's natively on Linux, Solaris and MacOS X!

Also, just in case anyone might mis-interpret my statement about being ignored,
it was in reference to Autodesk employee's responding to my posts and questions.

Bob

P.S. What's the diff between a Pythonista and a Pythoneer?

Josh_Petitt wrote:
0 Likes
Message 8 of 33

Anonymous
Not applicable
So now I have to learn C# ????
Not sure I can cope having been with VB since v3!
0 Likes
Message 9 of 33

Anonymous
Not applicable
No, but you will have to learn VB.Net if you don't know that yet.

Bob S.

PeterCharles wrote:
> So now I have to learn C# ????
0 Likes
Message 10 of 33

Anonymous
Not applicable
>What's the diff between a Pythonista and a Pythoneer?

whether you live north or south of the equator?

>I would very much like to see Autodesk add python as a scripting language,but I think that will happen about the same time they roll out that versionof Inventor that run's natively on Linux, Solaris and MacOS X!

With Python, at least when they do roll out IV on the other OS's, they can be sure that the scripting language will work on all three 😉
0 Likes
Message 11 of 33

Anonymous
Not applicable
Maybe we should take a clue from this guy and
start an open source project to create a python COM
addin like he started for autocad?

http://pyacad.sourceforge.net/

Python Extension for Autocad/Intellicad Autocad/Intellicad Extension for Python

This Project has the goal to make Python available as a scripting language for the CAD programs Autocad and Intellicad.

Josh_Petitt wrote:
0 Likes
Message 12 of 33

Anonymous
Not applicable
> No, but you will have to learn VB.Net if you don't know that yet.

Which is not a huge stretch from VB.

Richard
0 Likes
Message 13 of 33

rschader
Advocate
Advocate
Josh,

I've been doing some research and some initial experimenting with python and more specifically PythonWin which provides access to COM objects. It looks like we can already use python (thru pythonwin COM) to program inventor, though there is MUCH to figure out. PythonWin interactive shell even presents dropdown lists of methods, etc like VB when you type a period, but for some reason, I can't get Name or DisplayName for my ActiveDocument? I was able to print the name of the ActiveSheet (see attached image).

Bob S
0 Likes
Message 14 of 33

Anonymous
Not applicable
SWEET!

I haven't played much with this, so I didn't know if a Python, wrapper would be required or not (apparently not!).

> though there is MUCH to figure out
Bob, you are (un)officially on the bleeding edge 🙂 (especially since you are using a beta Python build)
0 Likes
Message 15 of 33

Anonymous
Not applicable
I actually started out with the 3.0 beta of python, but there
isn't any precompiled install of pythonwin for that. 2.6 had
one so I tried that, but I am thinking of moving back further,
since I am getting a failure error trying to run makepy.py
with no arguments to pre-generate the internal constants and
stuff for the Inventor COM interface!

Bob S.

Josh_Petitt wrote:

> Bob, you are (un)officially on the bleeding edge 🙂 (especially since you are using a beta Python build)
0 Likes
Message 16 of 33

Anonymous
Not applicable
>3.0 beta of python

wowza, that is new, I don't think Python 3000 is released (or even finished yet). I'm using the latest released build 2.5.2. I believe it should have COM support, I'll try tonight on some Excel spreadsheets.
0 Likes
Message 17 of 33

Anonymous
Not applicable
The COM support is a separate package: pywin32-212.win32-py2.5.exe
that you can download from sourceforge at
http://sourceforge.net/projects/pywin32/

Bob

Josh_Petitt wrote:
>> 3.0 beta of python
>
> wowza, that is new, I don't think Python 3000 is released (or even finished yet). I'm using the latest released build 2.5.2. I believe it should have COM support, I'll try tonight on some Excel spreadsheets.
0 Likes
Message 18 of 33

rschader
Advocate
Advocate
Attached are my first python scripts I wrote as a test. They are really similar variations of the same script. Inv_ClearDisplayname2CRAP.py when run sets the active document's displayname to "CRAP", while Inv_ClearDisplayname.py clears the displayname, which on IV2009 seems to force Inventor to reset the displayname to the filename of the document.

Inv_ClearDisplayname2CRAP.py:
# Inventor test script for pythonwin COM access
# converted from VBA code by Bob Schader
import win32com.client
oApp=win32com.client.Dispatch("Inventor.Application")
oDoc=oApp.ActiveDocument
oDoc.DisplayName="CRAP"
oDoc.Update()

Inv_ClearDisplayname.py:
# Inventor test script for pythonwin COM access
# converted from VBA code by Bob Schader
import win32com.client
oApp=win32com.client.Dispatch("Inventor.Application")
oDoc=oApp.ActiveDocument
oDoc.DisplayName=""
oDoc.Update()

The attached zipfile contains extra print statements and comments, the lines above are the actual stripped down code that does the work.

Bob S.
0 Likes
Message 19 of 33

Anonymous
Not applicable
>document's displayname to "CRAP"

I trust this stands for "CoRe APplication"? 😉

These scripts are good for automating IV, I am wondering now if it is possible to call Python code from IV? Basically so one could assign an Inventor button to call the Python script. I am now wondering if one could use the existing Add-in model to embed the Python interpreter into Inventor? Sorry for not checking any of this out myself, but I'll have to do it on my own time at home.
0 Likes
Message 20 of 33

Anonymous
Not applicable
Josh_Petitt wrote:
> I trust this stands for "CoRe APplication"? 😉

Yup!
It was either that or "SHareable, Integrated Techniques"

What I'm wondering myself, is 1). how to add a button to an environment
panel to execute an external script or executable (I had heard that it
was possible). If not, some like Mr. Macro (call it Mr. Python?) could
be written as an addin?, and 2). how to run the scripts without a python
console window popping up momentarily.

Down the road, though, I think the bigger barriers will be figuring out
if it's possible to do events, and interaction graphics or selections
from Python, but it seems promising.

Bob
0 Likes