Deleting the TitleBlockDefinition from a sheet

By Augusto Goncalves

In Inventor, we might have many TitleBlockDefinitions in a drawing under "Drawing Resources". In case you want to replace the TitleBlockDefintion in a sheet with new TitleBlockDefinition, we need to delete the TitleBlockDefinition in the sheet and then add the new TitleBlockDefinition.

Below is a VB.NET code which will delete aTtitleBlockDefinition and add a new one. To try this sample, before you run the code, start Inventor, File->New->Standard.idw (open a new drawing).In this particular drawing, code will delete "ANSI – Large" and then add "ANSI A".

Public Sub DeleteTitleBlockOnSheet()

  ‘ Set a reference to the drawing document.

  ‘ This assumes a drawing document is active.

  Dim oDrawDoc As DrawingDocument

  oDrawDoc = m_inventorApplication.ActiveDocument

 

  ‘ Obtain a reference to the desired border defintion.

  Dim oTitleBlockDef1 As TitleBlockDefinition

  oTitleBlockDef1 = oDrawDoc.TitleBlockDefinitions.Item("ANSI A")

 

  ‘ Val1 will be true because this titleblockdefinition

  ‘ is present in the drawing doc

  Dim Val1 As Boolean = oTitleBlockDef1.IsReferenced

 

  ‘ Obtain a reference to the desired border defintion.

  Dim oTitleBlockDef2 As TitleBlockDefinition

  oTitleBlockDef2 = oDrawDoc.TitleBlockDefinitions. _

    Item("ANSI – Large")

 

  ‘ Val2 will also be true because this titleblockdefinition

  ‘ oTitleBlockDef2 is present in the drawing doc

  Dim Val2 As Boolean = oTitleBlockDef2.IsReferenced

 

  Dim oSheet As Sheet = oDrawDoc.ActiveSheet

 

  ‘ Sheet has only ANSI – Large TitleBlockDefinition

  ‘ (oTitleBlockDef2) -  Check to see if the sheet already

  ‘ has a title block and delete it if it does.

  If oSheet.TitleBlock.Definition Is oTitleBlockDef1 Then

    oSheet.TitleBlock.Delete()

  End If

 

  If oSheet.TitleBlock.Definition Is oTitleBlockDef2 Then

    oSheet.TitleBlock.Delete()

  End If

 

  Dim oTitleBlock As TitleBlock

  oTitleBlock = oSheet.AddTitleBlock(oTitleBlockDef1)

End Sub


Comments

One response to “Deleting the TitleBlockDefinition from a sheet”

  1. “we are leading DC Motor a high-tech enterprise, specializing in the
    development and manufacture of different series
    of miniature DC and gear motors Manufacturer in china”

Leave a Reply to JennyCancel reply

Discover more from Autodesk Developer Blog

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

Continue reading