Message 1 of 10
iLogic to Assign New Part Numbers and List Unchanged Files
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I'm using Inventor Professional 2022 64-Bit, Build 492, Release: 2022.4.1.
I have a rule that I'm trying to use to assign new part numbers to all components in the Parts Only view of the BOM of an assembly.
It's been working well, but needs more error catching functionality.
I just need it to display a message box and show what parts it couldn't modify (Content Center component, Library Part, Suppressed part, etc.
I'm still a novice when it comes to iLogic, but I've been able to patch together this code after reading posts online.
Could someone explain how I could achieve what I'm wanting to do?
Public Sub Main()
Dim oAssemblyDocument As AssemblyDocument
oAssemblyDocument= ThisDoc.Document
Dim oAssemblyComponentDefinition As AssemblyComponentDefinition
oAssemblyComponentDefinition = oAssemblyDocument.ComponentDefinition
Dim oAsmCustomPropSet As PropertySet = oAssemblyDocument.PropertySets.Item("Inventor User Defined Properties")
Dim oAsmSkidNumber As String
Dim oAsmSkidLetter As String
Try
'Get current custom prop value
oAsmSkidNumber = iProperties.Value("Custom", "SKID NUMBER")
oAsmSkidLetter = iProperties.Value("Custom", "SKID LETTER")
Catch
'Assume error means prop not found so create it
oAsmCustomPropSet.Add("", "SKID NUMBER")
oAsmCustomPropSet.Add("", "SKID LETTER")
'Get User input
oAsmSkidNumber = InputBox("Please enter a Skid Number", "iLogic", oAsmSkidNumber)
oAsmSkidLetter = InputBox("Please enter a Skid Letter", "iLogic", oAsmSkidLetter)
'Set custom prop value
iProperties.Value("Custom", "SKID NUMBER") = oAsmSkidNumber
iProperties.Value("Custom", "SKID LETTER") = oAsmSkidLetter
End Try
Dim oBOM As BOM
oBOM = oAssemblyComponentDefinition.BOM
oBOM.PartsOnlyViewEnabled = True
Dim oBOMView As BOMView
oBOMView = oBOM.BOMViews.Item("Parts Only") 'or structured
Try
oBOMView.Sort("Description", True,)
oBOMView.Renumber(1, 1)
Catch
MessageBox.Show("The program has failed. There are no parts to renumber.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop)
Exit Sub
End Try
For Each oBOMRow As BOMRow In oBOMView.BOMRows
Try
Dim oComponentDefinition As ComponentDefinition
oComponentDefinition = oBOMRow.ComponentDefinitions.Item(1)
MsgBox("anything")
Dim oBOMItemNumber As String
oBOMItemNumber = oBOMRow.ItemNumber() 'this is item number in the BOM
Dim oAsmSkidDesignation As String = oAsmSkidNumber & "-" & oAsmSkidLetter & "-" & oBOMItemNumber
Dim oComponentDefinitionPropertySet As PropertySet
oComponentDefinitionPropertySet = oComponentDefinition.Document.PropertySets.Item("Design Tracking Properties")
'Project property tab
oComponentDefinitionPropertySet.Item("Part Number").Value = oAsmSkidDesignation
'populates the Part Number property
Catch
Dim oComponentDefinition As ComponentDefinition
oComponentDefinition = oBOMRow.ComponentDefinitions.Item(1)
MsgBox("anything")
Dim oPropSets As PropertySets = oComponentDefinition.PropertySets
Dim oPropSet As PropertySet = oPropSets.Item("Design Tracking Properties")
Dim oPN As [Property] = oPropSet.Item("Part Number")
Dim oPNText As String = oPN
MessageBox.Show("The following components were unchanged: " & oPNText, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Next
End Sub