Community
I am trying to add automate drawing production. But I can't figure out how to add a title box succesfully.
The prompttext has one field. The scale of the drawing.
Could someone point me in the right direction. Many thanks in advance
from win32com.client import *
import pythoncom
drawing_filepath = ""
# Opens App
Invapp = Dispatch('Inventor.Application')
# makes app Visible
Invapp.Visible = True
# prints a document with all function in python in it! very useful
mod = gencache.EnsureModule('{D98A091D-3A0F-4C3E-B36E-61F62068D488}', 0, 1, 0)
Invapp = mod.Application(Invapp)
#Add Document model
ActDoc = Invapp.ActiveDocument
print(ActDoc.DocumentType)
# cast documents for part or assembly depending on type
if ActDoc.DocumentType == 12290:
ActDoc = CastTo(ActDoc, 'PartDocument')
else:
ActDoc = CastTo(ActDoc, 'AssemblyDocument')
DrawingDocumentType = 12292
# Getting template
TemplateDrawing= (Invapp.FileManager.GetTemplateFile(DocumentType=12292))
# Adding drawing
DrawingDoc = Invapp.Documents.Add(DrawingDocumentType,TemplateDrawing)
# Cast drawing document
DrawingDoc = CastTo(DrawingDoc, 'DrawingDocument')
#Select firt sheet
oSheet = DrawingDoc.Sheets.Item(1)
# Placing all the view
#Specify Input Parent view
PlaceParent = Invapp.TransientGeometry.CreatePoint2d(XCoord=11.0, YCoord=9.0)
# top view
TopPlace = Invapp.TransientGeometry.CreatePoint2d(XCoord=11.0, YCoord=20.0)
# right view
RightPlace = Invapp.TransientGeometry.CreatePoint2d(XCoord=30.0, YCoord=9.0)
View = 10764 # front view
LineType = 32257
Scale1 = 1.0
ModelViewName= 'FrontView'
# Placement base view
ParentView = oSheet.DrawingViews.AddBaseView( Model=ActDoc,Position=PlaceParent,Scale=Scale1,ViewOrientation=View, ViewStyle=LineType,ModelViewName=ModelViewName, ArbitraryCamera=None, AdditionalOptions=None)
# top view
Topview = oSheet.DrawingViews.AddProjectedView(ParentView=ParentView, Position=TopPlace, ViewStyle=LineType, Scale=Scale1)
# right view
Rightview = oSheet.DrawingViews.AddProjectedView(ParentView=ParentView, Position=RightPlace, ViewStyle=LineType, Scale=Scale1)
# part of interest, Placement of Titlebox. Titleb box differ for part and assembly. Focussing on Part (12290) first
if ActDoc.DocumentType == 12290:
TitleBoxPart =DrawingDoc.TitleBlockDefinitions.Item(2)
prompt = VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R8,[str(Scale1)])
oSheet.AddTitleBlock(TitleBlockDefinition=TitleBoxPart,TitleBlockLocation=None,PromptStrings= prompt)
else:
TitleBoxAsm = DrawingDoc.TitleBlockDefinitions.Item(1).Name
oSheet.AddTitleBlock(TitleBlockDefinition=TitleBoxAsm)
For people interested in the solution,
I solved it using
prompt = VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_BSTR,[str(Scale1)])
The VT_BSTR indicates the type of the array you send, other types can be found here
https://www.oreilly.com/library/view/python-programming-on/1565926218/ch12s03s06.html
Can't find what you're looking for? Ask the community or share your knowledge.