Issue
Question: How do I change text items in the TitleBlockDefinition in Inventor?
Answer: Assuming you have an active drawing document open, first you need to access the TitleBlockDefinitions collection. Step through the collection to find the Title Block of interest, as shown in the following code fragment, the "ANSI - Large" title block definition.
When the TitleBlockDefinition of interest is found, we select the TextBoxes collection. Step through the collection until the TextBox of interest is found. For a TextBox the 'Text' property is a read/write property. The most important code in the following code fragment is placing the TitleBlockDefinition into edit mode with a call to 'Edit' and exiting the edit mode with a call to 'ExitEdit'.
Two code samples and a sample drawing document ("Drawing.zip") demonstrate this.
VBA:
Private Sub ChgTitleBlkDef()
Dim objDoc As Document
Set objDoc = ThisApplication.ActiveDocument
If objDoc Is Nothing Then
MsgBox "No Active Document"
Set objDoc = Nothing
Exit Sub
End If
'Is the active document a drawing document?
If objDoc.DocumentType <> kDrawingDocumentObject Then
MsgBox "Not a drawing document"
Set objDoc = Nothing
Exit Sub
End If
Dim objDrawDoc As DrawingDocument
Set objDrawDoc = objDoc
Dim colTitleBlkDefs As TitleBlockDefinitions
Set colTitleBlkDefs = objDrawDoc.TitleBlockDefinitions
Dim objTitleBlkDef As TitleBlockDefinition
For Each objTitleBlkDef In colTitleBlkDefs
If objTitleBlkDef.Name = "ANSI - Large" Then
'we have the title blk we want
Exit For
End If
Next objTitleBlkDef
If objTitleBlkDef Is Nothing Then
MsgBox "ANSI - Large TitleBlockDefinition not found!"
Set objDrawDoc = Nothing
Set colTitleBlkDefs = Nothing
Set objTitleBlkDef = Nothing
Exit Sub
End If
' If we are here we have the title block of interest.
' Get the title block sketch and set it active
Dim objDrwSketch As DrawingSketch
Call objTitleBlkDef.Edit(objDrwSketch)
Dim colTextBoxes As TextBoxes
Set colTextBoxes = objDrwSketch.TextBoxes
Dim objTextBox As TextBox
For Each objTextBox In colTextBoxes
If objTextBox.Text = "TITLE" Then
objTextBox.Text = "Captain CAD Engineering"
Exit For
End If
Next objTextBox
Call objTitleBlkDef.ExitEdit(True)
' Clean up
Set objDrawDoc = Nothing
Set colTitleBlkDefs = Nothing
Set objTitleBlkDef = Nothing
Set objDrwSketch = Nothing
Set colTextBoxes = Nothing
Set objTextBox = Nothing
Beep
End Sub
VB .NET:
Sub ChgTitleBlkDef()
Dim objDrawDoc As DrawingDocument _
= CType(oApp.ActiveDocument, DrawingDocument)
Dim colTitleBlkDefs As TitleBlockDefinitions _
= objDrawDoc.TitleBlockDefinitions
Dim objTitleBlkDef As TitleBlockDefinition = Nothing
For Each objTitleBlkDef In colTitleBlkDefs
If objTitleBlkDef.Name = "ANSI - Large" Then
'we have the title blk we want
Exit For
End If
Next
' If we are here we have the title block of interest.
' Get the title block sketch and set it active
Dim objDrwSketch As DrawingSketch = Nothing
objTitleBlkDef.Edit(objDrwSketch)
Dim colTextBoxes As TextBoxes _
= objDrwSketch.TextBoxes
For Each objTextBox As TextBox In colTextBoxes
If objTextBox.Text = "TITLE" Then
objTextBox.Text = "Captain CAD Engineering"
Exit For
End If
Next
objTitleBlkDef.ExitEdit(True)
Beep()
End Sub