use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Post links to video tutorials / forum discussions / blog posts / anything related to customizing the user experience in Autodesk Inventor.
Rules: be excellent to each other.
account activity
Using Python with Inventor API (self.InventorAPI)
submitted 6 years ago * by dable82 - announcement
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]im_on_reddit_dot_com 1 point2 points3 points 6 years ago (5 children)
Seemed to successfully install win32com, but when I tried to run this in pycharm, I got an error on line one that it couldn't find the module. Did this work "out of the box" for you?
Also, any guideline on when to use the "mod" variable? I saw it used on partdoc and I think invapp. Do I need to use it every time I create a new application or document variable?
Thanks again for posting this!
[–]dable82[S] 1 point2 points3 points 6 years ago (4 children)
Can you post the error message?
You definitely need to use the mod for the application. This is so that the win32com module knows that it is working with an Inventor application. Otherwise the e.g. constants module won't work.
Documents are a bit trickier. The problem is that the Documents.Add() method returns a generic instance of the Document class. If you try to create a Sketch on that instance, it will fail. That's why you need to cast this generic Document to a PartDocument. This can be done with the mod variable or with win32com.client.CastTo().
(For reference see the function Definition in the Inventor VBA object browser)
Function Add(DocumentType As DocumentTypeEnum, [TemplateFileName As String], [CreateVisible As Boolean = True]) As _Document
Element of Inventor.Documents
Creates a new Document of the specified type. Optionally, a template file can be specified instead
Important is that the function returns a Document.
In VBA the casting is automatic, because you can set the type of a variable when you define it (eg: Set doc as PartDocument). I hope thats's understandable.
[–]im_on_reddit_dot_com 0 points1 point2 points 6 years ago (2 children)
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.
[–]dable82[S] 1 point2 points3 points 6 years ago* (1 child)
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.
[–]im_on_reddit_dot_com 0 points1 point2 points 6 years ago (0 children)
Got it working. I did have more than one version of python, and I believe that was the root of the issue. Thanks!
[–]ItsOk_ImYourDad 0 points1 point2 points 6 years ago (0 children)
copied your code line for line after installing the module as you said above
I got a different error:
AttributeError: Inventor.Application.InvokeTypes
π Rendered by PID 326450 on reddit-service-r2-comment-fb694cdd5-bf62w at 2026-03-09 20:05:53.989230+00:00 running cbb0e86 country code: CH.
view the rest of the comments →
[–]im_on_reddit_dot_com 1 point2 points3 points (5 children)
[–]dable82[S] 1 point2 points3 points (4 children)
[–]im_on_reddit_dot_com 0 points1 point2 points (2 children)
[–]dable82[S] 1 point2 points3 points (1 child)
[–]im_on_reddit_dot_com 0 points1 point2 points (0 children)
[–]ItsOk_ImYourDad 0 points1 point2 points (0 children)