Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm starting work on this piece of code. It works fine on Assembly documents but throws this error on Weldments. What am I doing wrong?
Thank you much!
Sub Main() If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Messagebox.Show("Run this rule from an Assembly document!", "Error!") Exit Sub End If 'Get the active assembly. Dim doc As AssemblyDocument = ThisDoc.Document Dim refDocs = doc.ComponentDefinition.Occurrences.Cast(Of ComponentOccurrence). Select(Of Document)(Function(occ) occ.ReferencedDocumentDescriptor.ReferencedDocument). Distinct().ToList() For Each oRefDoc As Document In refDocs If Not oRefDoc.IsModifiable Or _ oRefDoc.ComponentDefinition.BOMStructure <> BOMStructureEnum.kNormalBOMStructure Then Continue For If oRefDoc.DocumentType = kAssemblyDocumentObject Then Dim oAsmPN As String = oRefDoc.PropertySets("Design Tracking Properties")("Part Number").Value If Left(oAsmPN, 1) = "5" Then '5000 part numbers define a Weldment MessageBox.Show(oAsmPN, "Assembly Part Number:") CompileWeldments(oRefDoc, oAsmPN) ElseIf Left(oAsmPN, 1) = "2" Then '2000 part number define an Assembly 'CompileAssemblies End If End If Next End Sub Sub CompileWeldments(oRefDoc As AssemblyDocument, oAsmPN As String) Dim refDocs = oRefDoc.ComponentDefinition.Occurrences.Cast(Of ComponentOccurrence). Select(Of Document)(Function(occ)occ.ReferencedDocumentDescriptor.ReferencedDocument). Distinct().ToList() For Each ooRefDoc As Document In refDocs If Not ooRefDoc.IsModifiable Or _ ooRefDoc.ComponentDefinition.BOMStructure <> BOMStructureEnum.kNormalBOMStructure Then Continue For oPN = ooRefDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value If Left(oPN, 1) = "7" Or Left (oPN, 1) = "8" Then 'get only part numbers 7000 and 8000 MessageBox.Show("Assembly: " & oAsmPN & vbCrLf & "Part: " & oPN, "Weldment and SubPart:") End If Next End Sub
Solved! Go to Solution.