Issue
I am about to attempt a title block swap from within inventor’s API to copy and paste a good title block into an old idw. Is there any API?
Solution
The code below copies a title block from one drawing to a new drawing.Assume you have a template file (source drawing), which contains a titleblock named "ANSI A", and another drawing that the titleblock will be copied into (let’s say "drawing1.idw"), run the following VBA code, then you will see that the titleblock from the source drawing is copied into "drawing1.idw" and the tibleblocks in all Sheets are replaced with the one newly copied in. If the titleblock named as "ANSI A" in the "drawing1.idw" has existed before the copying, then the new titleblock copied into will be renamed as "Copy of ANSI A" to avoid the name conflict.
Public Sub TitleBlockCopy() ' assume Inventor application is available Dim oSourceDocument As DrawingDocument oSourceDocument = ThisApplication.ActiveDocument ' Open the new drawing to copy the title block into. Dim oNewDocument As DrawingDocument oNewDocument = ThisApplication.Documents.Open("e:casedrawing1.idw") ' Get the new source title block definition. Dim oSourceTitleBlockDef As TitleBlockDefinition oSourceTitleBlockDef = oSourceDocument.TitleBlockDefinitions.Item("ANSI A") ' Get the new title block definition. Dim oNewTitleBlockDef As TitleBlockDefinition oNewTitleBlockDef = oSourceTitleBlockDef.CopyTo(oNewDocument) ' Iterate through the sheets, replace tibleblock with the one newly added. Dim oSheet As Sheet For Each oSheet In oNewDocument.Sheets oSheet.Activate oSheet.TitleBlock.Delete Call oSheet.AddTitleBlock(oNewTitleBlockDef) Next End Sub

Leave a Reply