Message 1 of 4
Updating the old idw with updated Global styles and Title Block from Template
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I made I logic, which update syles and Title block from Teamplate in old idw. I have problew with inserting new Title block on Sheet (line 63)
' Check that the active document is a Drawing file If ThisApplication.ActiveDocument.DocumentType <> kDrawingDocumentObject Then MessageBox.Show("This rule can only run from an IDW file", "IDW-Updater", MessageBoxButtons.OK, MessageBoxIcon.Error) Exit Sub End If ' Check if the document is saved Dim activeDoc As Document = ThisApplication.ActiveDocument If String.IsNullOrEmpty(activeDoc.FullFileName) Then MessageBox.Show("The current drawing has not been saved yet. Please save the drawing first!", "Save", MessageBoxButtons.OK, MessageBoxIcon.Error) Exit Sub End If ' Check if the drawing has at least one view Dim hasView As Boolean = False For Each sheet As Sheet In activeDoc.Sheets If Sheet.DrawingViews.Count > 0 Then hasView = True Exit For End If Next If Not hasView Then MessageBox.Show("No views found in the drawing. Please add at least one view.", "Missing Views", MessageBoxButtons.OK, MessageBoxIcon.Warning) Exit Sub End If 'Update local syle from global OpenDoc = ThisDoc.Document oStyles = OpenDoc.StylesManager.Styles For Each oStyle As Style In oStyles If Not oStyle.UpToDate Then oStyle.UpdateFromGlobal End If Next ' Update drawing resources from the template Dim oBorderName As String = "MOST" Dim oTitleBlockName1 As String = "DIN rez.deli" 'open source Template file oResourceFile = "C:\Users\Public\Documents\Autodesk\Inventor 2025\Templates\MOST_SLO-rez deli.idw" Dim oSourceFile As DrawingDocument oSourceFile = ThisApplication.Documents.Open(oResourceFile, False) 'copy the resources from the source file Dim oDoc As DrawingDocument = ThisDoc.Document oSourceFile.BorderDefinitions.Item(oBorderName).CopyTo(oDoc, True) oSourceFile.TitleBlockDefinitions.Item(oTitleBlockName1).CopyTo(oDoc, True) 'close source file oSourceFile.Close(True) ' Replace title block in all sheets For Each oSheet In oDoc.Sheets oSheet.Activate If oSheet.TitleBlock IsNot Nothing Then oSheet.TitleBlock.Delete End If oSheet.AddTitleBlock(oTitleBlockName1) Next oSheet