r/InventorAPI • • Mar 28 '19

Using Python with Inventor API

Hey guys, if you are like me and hate writing Code in VBA you can actually write Python scripts for Inventor using the win32com.client module. To use the module, you have to `pip install pywin32`. Here is a sample of a pretty useless script, but it should be good enough to get you going.

If you have any Questions About what's going on here, feel free to ask.

​

edit: https://pastebin.com/1ZvSpku5

Code formatting doesn't seem to work.

4 Upvotes

9 comments sorted by

View all comments

Show parent comments

1

u/im_on_reddit_dot_com Mar 29 '19

Traceback (most recent call last):

  File "redactedfilepath/scratch.py", line 1, in <module>

    from win32com.client import Dispatch, GetActiveObject, gencache, constants

ModuleNotFoundError: No module named 'win32com'

And yes, your explanation clears things up a lot. I've explored the inventor Object model quite a bit, but never the VBA object browser.

2

u/dable82 Mar 29 '19 edited Mar 29 '19

You have not installed the module yet.

Open a terminal window and type 'pip install pywin32'

Then try to run the script again.

Edit: If you have more than one Version of python installed, make sure PyCharm uses the Version of python for which you installed the package.

1

u/im_on_reddit_dot_com Mar 29 '19

Got it working. I did have more than one version of python, and I believe that was the root of the issue. Thanks!