- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have patched together some ilogic that I found on this forum..
My intent is to iterate through the assembly and take the custom iProperty (Contract Number) and basically the (item number) and the REV letter to create a stock number which I will use as a short part number. Since I found that the Item number is not accessible via iLogic.. that is not an option. Unless there is a way to do that.
My part number is to long as I have parts that have 30+ options that are defined in the part number in order to merge parts on the BOM. (190854-17.75-1.75-1.75-0.1-10.5-7-SS-W) my vendors software has a 12 character limit, so even removing the "-" would not shorten it enough.
This also needs to include all the sub assemblies and parts, and it also needs to change the stock number of all instances, due to the part number merge, otherwise i get a stock number that says varies.
I cant seem to get the "PNum" to keep counting, I just need "PNum" to keep counting so I don't end up with the same number in either a part or sub assembly. And when I turn off the "On Error Resume Next" I get
System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
at Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)
at ThisRule.ListItems(BOMRowsEnumerator Rows, Int32 indent, Document oDoc)
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)
some pointers or rewritten illogic would be much appreciated.
Sub Main()
'On Error Resume Next
numFiles = 0
Dim oAssem As AssemblyDocument = ThisDoc.Document
Dim oBOM As BOM = oAssem.ComponentDefinition.BOM
Dim BoxNote As String = "Drawing Automation"
ANum = ANum + 1
Dim oModelREV1 As String = oAssem.PropertySets("{F29F85E0-4FF9-1068-AB91-08002B27B3D9}").ItemByPropId(9).Value
Dim oModelConN1 As String = oAssem.PropertySets("Inventor User Defined Properties").Item("Contract Number").Value
oAssem.PropertySets("Design Tracking Properties").Item("Stock Number").Value = oModelConN1 & "-AS" & ANum & "-" & oModelREV1
oBOM.StructuredViewFirstLevelOnly = False
oBOM.StructuredViewEnabled = True
oBOM.PartsOnlyViewEnabled = True
oBOM.SetPartNumberMergeSettings(True, )
For Each oDoc In oAssem.AllReferencedDocuments
numFiles = numFiles + 1
If oDoc.DocumentType = 12291 Then Call ListItems(oBOM.BOMViews.Item(1).BOMRows, 0, oDoc) 'assembly
If oDoc.DocumentType = 12290 Then Call ListItems(oBOM.BOMViews.Item(3).BOMRows, 0, oDoc) 'part
MessageBox.Show(numFiles)
Next
MessageBox.Show("Thanks for being efficient!" _
& vbLf & "There are ( " & numFiles & " ) files that have been updated.", BoxNote, MessageBoxButtons.OK)
End Sub
Sub ListItems(Rows As BOMRowsEnumerator, indent As Integer, oDoc As Document)
PNum = PNum + 1
'MessageBox.Show ("PNum")
For Each oBOMRow As BOMRow In Rows
rDoc = oBOMRow.ComponentDefinitions.Item(1).Document
If rDoc IsNot oDoc Then
If Not oBOMRow.ChildRows Is Nothing Then
Call ListItems(oBOMRow.ChildRows, indent + 1, oDoc)
End If
Else
i = 1
For Each kDoc In oBOMRow.ComponentDefinitions
rDoc = oBOMRow.ComponentDefinitions.Item(i).Document
Dim oModelREV As String = oDoc.PropertySets("{F29F85E0-4FF9-1068-AB91-08002B27B3D9}").ItemByPropId(9).Value
Dim oModelConN As String = rDoc.PropertySets("Inventor User Defined Properties").Item("Contract Number").Value
rDoc.PropertySets("Design Tracking Properties").Item("Stock Number").value = oModelConN & "-" & PNum & "-" & oModelREV
PNum = PNum + 1
MessageBox.Show(PNum)
i = i + 1
Next
End If
Next
End Sub
Solved! Go to Solution.