Message 1 of 2

Not applicable
09-01-2017
03:02 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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")
Solved! Go to Solution.