Message 1 of 11
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Ok so I cobbled this iLogic together for my needs but it is failing at line 25 with the following error code and I cant find anything to make it work. any help would be appreciated.
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument
' Check if the active document is a drawing referencing a model
If oDoc.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
MessageBox.Show("This rule is intended for drawings only.", "Error")
Return
End If
' Get the referenced model document
Dim modelDoc = ThisDrawing.ModelDocument
' Check if the referenced document is a part or assembly
If modelDoc.DocumentType <> DocumentTypeEnum.kPartDocumentObject AndAlso
modelDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MessageBox.Show("This rule is intended for drawings referencing parts or assemblies only.", "Error")
Return
End If
' Continue with the rest of the code...
' Get the active assembly drawing document
Dim asmDoc As AssemblyDocument = oDoc
' Find the sheet format named "24 x 36"
Dim sheetFormatName As String = "24 x 36"
Dim sheetFormat As SheetFormat = Nothing
For Each sf As sheetFormat In oDoc.SheetFormats
If sf.Name = sheetFormatName Then
sheetFormat = sf
Exit For
End If
Next
' Check if the sheet format was found
If sheetFormat Is Nothing Then
MessageBox.Show("Sheet format '24 x 36' not found.", "Error")
Return
End If
' Loop through the parts in the assembly
For Each partOccurrence As ComponentOccurrence In asmDoc.ComponentDefinition.Occurrences
' Get the part document for each component occurrence
If partOccurrence.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then
Dim partDoc As PartDocument = partOccurrence.Definition.Document
' Create a new sheet using the specified sheet format
Dim newSheet As Sheet = oDoc.Sheets.AddUsingSheetFormat(sheetFormat)
' Set the sheet name to the part name
newSheet.Name = partDoc.DisplayName
' Activate the new sheet
newSheet.Activate()
' Add the part view to the new sheet
Dim partView As DrawingView = oDoc.ActiveSheet.DrawingViews.AddBaseView(partOccurrence, Nothing, Nothing, Nothing, Nothing)
End If
Next
' Activate the first sheet
oDoc.Sheets.Item(1).Activate()
Solved! Go to Solution.