Message 1 of 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
some of my clients want to have their own titleblock. Then nothing changes to the properties, but to the appearance. I already made some code for this, but it doesn't work. It crashes on the part from line 24 to line 40, while this works in a separate ilogic rule
Sub Main() Dim oDoc As Document = ThisDoc.Document If MessageBox.Show ( _ "This will change all title blocks in IDW file for all of the files referenced by this document that have drawings files." _ & vbLf & "This rule expects that the drawing file shares the same name and location as the component." _ & vbLf & " " _ & vbLf & "Are you sure you want to create IDW Drawings for all of the referenced documents?" _ & vbLf & "This could take a while.", "iLogic - Batch Output PDFs ",MessageBoxButtons.YesNo) = vbNo Then Exit Sub End If '- - - - - - - - - - - - -Component Drawings - - - - - - - - - - - - Dim oDrawDoc As DrawingDocument Dim oNoDwgString, idwPathName As String For Each oRefDoc As Document In oDoc.AllReferencedDocuments oBaseName = System.IO.Path.GetFileNameWithoutExtension(oRefDoc.FullFileName) oPathAndName = System.IO.Path.GetDirectoryName(oRefDoc.FullFileName) & "\" & oBaseName If (System.IO.File.Exists(oPathAndName & ".idw")) Then oDrawDoc = ThisApplication.Documents.Open(oPathAndName & ".idw", True) 'save copy of it to other directory Dim doc As DrawingDocument = ThisDoc.Document Dim templateFileName As String = "D:\data\Autodesk - Morren\3. Inventor templates\Morrenbv.idw" Dim templateDoc As DrawingDocument = ThisApplication.Documents.Open(templateFileName, False) ' copy your titleblock to original drawing Dim templateTitleBloc As TitleBlockDefinition = templateDoc.TitleBlockDefinitions.Item("GL bv") Dim newTitleBlok As TitleBlockDefinition = templateTitleBloc.CopyTo(doc, True) ' close the template document templateDoc.Close(True) For Each sheet As Sheet In doc.Sheets Dim oldTitleblock As TitleBlock = Sheet.TitleBlock If (oldTitleblock IsNot Nothing) Then oldTitleblock.Delete() End If Sheet.AddTitleBlock(newTitleBlok) Next 'oDrawDoc.SaveAs(oFolder & oBaseName & ".idw", True) oDrawDoc.Close oDrawDoc = Nothing Else idwPathName = oRefDoc.FullFileName oNoDwgString = oNoDwgString & vbLf & idwPathName End If Next MessageBox.Show("Title blocks are changed") MsgBox("Files found without drawings: " & vbLf & oNoDwgString) End Sub
Solved! Go to Solution.