title: How to create and use objects from the Inventor COM API in python (pywin32)
body: <p>I'm attempting to use Autodesk Inventor's COM API to create a python script that will generate PDFs of a selection on Inventor Drawings, these PDFs will then be processed in particular ways that aren't important to my question. I'm using pywin32 to access the COM API, but I'm not particularly familiar with how COM APIs are used, and the pywin32 module.</p>
  
  <p><a href="https://knowledge.autodesk.com/search-result/caas/simplecontent/content/autodesk-C2-AE-inventor-C2-AE-api-object-model-reference-document-pdfs.html" rel="nofollow noreferrer">This is the extent of the documentation for Inventor's API that I have been able to find (diagram of API Object Model Reference Document)</a>, and I have not been able to find documentation for the individual objects listed. As such, I'm basing my understanding of the use of these objects on what I can find from examples online (all in VB or iLogic - Inventor's own simple built-in language).</p>
  
  <p>A big issue I'm coming up against is in creating the objects I'd like to use. Simplified example below:</p>
  
  <pre><code>from win32com.client import *
  
  # user chooses file paths for open and save here...
  drawing_filepath = ""
  
  # Open Inventor application, and set visible (so I can tell it's opened for now)
  app = Dispatch('Inventor.Application')
  app.Visible = True
  
  # Open the file to be saved as a pdf (returns a Document object) 
  app.Documents.Open(drawing_filepath)
  # Cast the opened Document object to a DrawingDocument object (it is guaranteed to be a drawing)
  drawing = CastTo(app.ActiveDocument, "DrawingDocument")
  
  # Create and setup a print manager (so can use "Adobe PDF" printer to convert the drawings to PDF)
  print_manager = ??? # How can I create this object
  # I've tried:
  # print_manager = Dispatch("Inventor.Application.Documents.DrawingDocument.DrawingPrintManager") #"Invalid class string"
  # print_manager = drawing.DrawingPrintManager() #"object has no attribute 'DrawingPrintManger'
  # print_manager = drawing.DrawingPrintManager   # same as above
  # print_manager = drawing.PrintManger # worked in the end
  print_manager.Printer = "Adobe PDF"
  print_manager.NumberOfCopies = 1
  print_manager.ScaleMode = print_manager.PrintScaleModeEnum.kPrintFullScale
  print_manager.PaperSize = print_manager.PrintSizeEnum.kPaperSizeA3
  
  # Print PDF
  print_manager.SubmitPrint()
  </code></pre>
  
  <p>So I can't figure out how to create a DrawingPrintManager to use! You can see I've avoided this issue when creating my DrawingDocument object, as I just happened to know that there is an ActiveDocument attribute that I can get from the application itself.</p>
  
  <p>I also:</p>
  
  <ul>
  <li>don't know what the full list of attributes and methods for DrawingPrintManager are, so I don't know how to set a save location</li>
  <li>don't know for sure that the two Enums I'm trying to use are actually defined within DrawingPrintManager, but I can figure that out once I actually have a DrawingPrintManager to work with</li>
  </ul>
  
  <p>If anyone with more experience in using COM APIs or pywin32 can help me out, I'd be really appreciative. And the same if anyone can point me towards any actual documentation of Inventor's API Objects, which would make things a lot easier.</p>
  
  <p>Thanks</p>
  
  <p>Edit: After posting I've almost immediately found that I can get a PrintManager (can't tell if a PrintManager or DrawingPrintManager) by accessing <code>drawing.PrintManager</code> rather than <code>drawing.DrawingPrintManager</code>.</p>
  
  <p>This is a workaround however as it doesn't answer my question of how to create objects within pywin32.</p>
  
  <p>My problem moving forward is finding where I can access the PrintScaleModeEnum and PrintSizeEnum objects, and finding how to set the save location of the printed PDF (which I think will be a a separate question, as it's probably unrelated to the COM API).</p>