Copy title block from one drawing to a new drawing

By Xiaodong Liang

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

Comments

5 responses to “Copy title block from one drawing to a new drawing”

  1. This is such a helpful post. This must be shared to my friends.

  2. You really shared a lots of information. Thanks for sharing.

  3. This is pretty cool. It helps me a lot. Thanks for sharing!

  4. Thanks for the information you have shared. i have just learned from your previous blog on create a copy of a layout from a drawing template. You help me a lot about this.

  5. shruti lahade Avatar
    shruti lahade

    Can some body tell me the same program for autocad

Leave a Reply to shruti lahadeCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading