Hi George,
the following code remove your old Titleblock and re-insert the new TitleBlock definition.
This code work fine only if all informations are filled by Iproperties.
If you would like to change within your Titleblock definition only the changed text and image, then we will do it.
Sub Main()
oTransMgr = ThisApplication.TransactionManager
oTrans = oTransMgr.StartTransaction(ThisApplication.ActiveDocument, "ChangeTemplate")
On Error Goto ErrorManagement
'On Error Resume Next
Dim oDrawingDoc As Inventor.DrawingDocument = ThisApplication.ActiveDocument
DeleteTitleBlock(oDrawingDoc)
UpdateTitleBlock("Template full filename and Path", "Your TitleBlock definition Name", oDrawingDoc) ' change parameters
oTemplateMonoDoc = ThisApplication.Documents.ItemByName("Template full filename and Path") ' change parameters
If oTemplateMonoDoc.Open Then oTemplateMonoDoc.Close(True)
ErrorManagement: '(error mangement)
If Err.number<>0 Then MessageBox.Show(Err.description & vbCr & Err.number, "Error")
oTrans.End
End Sub
Private Sub DeleteTitleBlock(oDrawingDoc as Inventor.DrawingDocument) ' remove titleblock definition
On Error Resume Next
For Each oSheet In oDrawingDoc.Sheets
oSheet.TitleBlock.Delete
Next
For Each oSheetFormat In oDrawingDoc.SheetFormats
oSheetFormat.Delete
Next
For Each oTitle In oDrawingDoc.TitleBlockDefinitions
oTitle.Delete
Next
End Sub
Private Sub UpdateTitleBlock(TbPath As String, TbName As String, oThisDoc as Inventor.Document)
Dim oTemplateDoc As DrawingDocument = ThisApplication.Documents.Open(TbPath, False)
Dim oThisDocTitleBlock As TitleBlockDefinition = oTemplateDoc.TitleBlockDefinitions.Item(TbName).CopyTo(oThisDoc)
For Each oSheet In oThisDoc.Sheets
Call oSheet.AddTitleBlock(oThisDocTitleBlock)
Next
oTemplateDoc.Close(True)
End Sub
Bregs
Rossano Praderi
--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------