Read BOM Structure in Rule

Read BOM Structure in Rule

Anonymous
Not applicable
429 Views
1 Reply
Message 1 of 2

Read BOM Structure in Rule

Anonymous
Not applicable

I am writing a program that adds some custom iProperties to each part in an assembly based on some rules.  I would like to make it so that if a part is labelled as a Purchased Part in the BOM then the rule won't make changes to it.  I'm pasting my code below.  Any ideas?  I've made a start, at the commented area, but I don't know if that's very close or not.  Any help would be appreciated.

 

 


Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument Dim oDoc As Document oACD = oAsmDoc.ComponentDefinition Dim oSS As SelectSet oSS = oAsmDoc.SelectSet oSS.Clear Dim objcoll As ObjectCollection objcoll = ThisApplication.TransientObjects.CreateObjectCollection For Each oDoc In oAsmDoc.AllReferencedDocuments If oDoc.DocumentType = kPartDocumentObject Then Dim oPartDoc As PartDocument = oDoc Dim model As String = oPartDoc.DisplayName model = model & ".ipt" For Each oOcc in oACD.Occurrences.AllReferencedOccurrences(oPartDoc) objcoll.Add(oOcc) Next oSS.SelectMultiple(objColl) 'If the part in question is a Purchsed Part (according to the BOM) then don't do anything. 'Trying to read the BOM structure here. 'If oOcc.Definition.BOMStructure = BOMStructureEnum.kNormalBOMStructure Then Try 'Is scrapfactor present? scrapfactor = iProperties.Value(model,"Custom", "scrapfactor") plasfactor = iProperties.Value(model,"Custom", "plasfactor") 'Is scrapfactor zero? If scrapfactor = 0 Then 'Ask user for values scrapfactor = InputBox("It appears this part is cut on the Plas table" _ & vbLf & "Enter value between 0-1 for scrap factor" _ & vbLf & "Example: 0.15" _ & vbLf & "Value MUST start with a 0.", "Scrap Factor for " & iProperties.Value(model, "Summary", "Title"), "0.1") plasfactor = 0.2 iProperties.Value(model,"Custom", "scrapfactor") = scrapfactor iProperties.Value(model,"Custom", "plasfactor") = plasfactor End If Catch 'If iProperties are not present, make sure they should be created, then create them and prompt user for values scrapyn = MessageBox.Show("Is this part cut on the Plas table?", iProperties.Value(model, "Summary", "Title") ,MessageBoxButtons.YesNo) If scrapyn = vbYes scrapfactor = InputBox("Enter value between 0-1 for scrap factor" _ & vbLf & "Example: 0.15" _ & vbLf & "Value MUST start with a 0.", "Scrap Factor for " & iProperties.Value(model, "Summary", "Title"), "0.1") plasfactor = 0.2 iProperties.Value(model,"Custom", "scrapfactor") = scrapfactor iProperties.Value(model,"Custom", "plasfactor") = plasfactor Else If scrapyn = vbNo End If End Try Try 'Is brakefactor present? brakefactor = iProperties.Value(model,"Custom", "brakefactor") 'Is brakefactor zero? If brakefactor = 0 Then 'Set brakefactor to default value brakefactor = 0.15 iProperties.Value(model,"Custom", "brakefactor") = brakefactor End If Catch 'If iProperties are not present, make sure they should be created, then create them and prompt user for values brakeyn = MessageBox.Show("Is this part made on the Press Brake?", iProperties.Value(model, "Summary", "Title") ,MessageBoxButtons.YesNo) If brakeyn = vbYes brakefactor = 0.2 iProperties.Value(model,"Custom", "brakefactor") = brakefactor Else If scrapyn = vbNo End If End Try Else End If objcoll.Clear oSS.Clear Next MessageBox.Show("Done", "Done")

 

 

0 Likes
Accepted solutions (1)
430 Views
1 Reply
Reply (1)
Message 2 of 2

HermJan.Otterman
Advisor
Advisor
Accepted solution

Hello Java,

 

stick with the referenced documents.... don't use the occurences. the Purchased bom structure is a document setting.

 

try somthing like this:

 

    Private Sub FindParts_NotPurchased()
        Dim oMainAssembly As AssemblyDocument = Thisapplication.ActiveDocument
        Dim oDoc As Inventor.Document

        For Each oDoc In oMainAssembly.AllReferencedDocuments

            If oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
                Dim oPartDoc As PartDocument = TryCast(oDoc, PartDocument)
                If oPartDoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure Then
                    'skip
                Else
                    'create properties
                End If

            ElseIf oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
                Dim oAssemblyDoc As AssemblyDocument = TryCast(oDoc, AssemblyDocument)
                If oAssemblyDoc.ComponentDefinition.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure Then
                    'skip
                Else
                    'create properties
                End If

            End If
        Next
    End Sub

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan