Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
cadman777
in reply to: cadman777

Here's the finalized rule:

 

 

'Gets "Stock Number" of all parts in assembly and writes that value into the iprop named "StkNum" in each part

Class ThisRule
	Dim rDoc As Document
	Dim oDoc As Document
	Dim oSN As String

'access top-level assembly BOM
	Sub Main()
		On Error Resume Next
		Dim oAssem As AssemblyDocument = ThisDoc.Document
		Dim oBOM As BOM = oAssem.ComponentDefinition.BOM

		oBOM.StructuredViewFirstLevelOnly = False
		oBOM.StructuredViewEnabled = True
		oBOM.PartsOnlyViewEnabled = True
		oBOM.SetPartNumberMergeSettings(True, )

		For Each oDoc In oAssem.AllReferencedDocuments
			'run subs on BOM
			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
		Next
	End Sub

	'extract total quantity from assembly and insert it into a new Cutsom iProperty "TotalQty"
	Sub ListItems(Rows As BOMRowsEnumerator, indent As Integer, oDoc As Document)
		
		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	

'***************************************** Added & mofified from Inventor online Help Added from Inventor online Help **************************************************************************************************************************************************************** 		
			Dim oCompDef As ComponentDefinition
			oCompDef = oBomRow.ComponentDefinitions.Item(1)
			'The required property set is named "Design Tracking Properties." Obtain this from the owning document of the component.
			Dim oPropSet As PropertySet
			oPropSet = oCompDef.Document.PropertySets.Item("Design Tracking Properties")
			'Now we have all the information necessary to list the BOM content. Obtain variable information such as the item number _
			'and quantity from the BOMRow object, and the part number and description from the property set.
'				MessageBox.Show("#: " & oBomRow.ItemNumber & _
'				" Quantity:" & oBomRow.ItemQuantity & _
'				"Part Number: " & oPropSet.Item("Part Number").Value & _
'				" Description: " & oPropSet.Item("Description").Value & _
'				" Stock Number: " & oPropSet.Item("Description").Value)
'				MessageBox.Show(" Stock Number: " & oPropSet.Item("Stock Number").Value)
				Dim oSN As String = oPropSet.Item("Stock Number").Value
'***************************************** Added & mofified from Inventor online Help **************************************************************************************************************************************************************** 
				i=1

				For Each kDoc In oBOMRow.ComponentDefinitions					
					rDoc = oBOMRow.ComponentDefinitions.Item(i).Document
					rDoc.PropertySets.Item("Inventor User Defined Properties").Item("StkNum").Value = oSN
				i=i+1
				Next
			End If
		Next
	End Sub
End Class

 

 

I based this on the advice given by everybody who contributed as follows:

 

@A.Acheson" the most important thing to remember is the document name reference before the location of the iproperty".

[That reminder was a key that I never realized before. IOW, you have to make sure you identify which Inventor document you're working from in your line of code.]

 

@WCrihfield "...create a document variable, then assign the first component definition's document (from that BOMRow) to it".

[That cued me in on another thing I hadn't learned yet. My new mantra for that is, 'first declare it then assign it'.]

 

@A.Acheson "I have notice you have used a hybrid method to get the value of the iproperty stock number. You are using a combination of the property sets method and the ilogic method...The typical method for ilogic iproperty snippet...Long method for getting/setting properties."

[That helped me organize methods for one operation, which helped to dispel confusion about what is going on with differing methods.]

 

So I took the above advice, along with VB.Net Inventor Help examples, and combined them with an existing iLogic rule, and with a little adapting of the VB.Net to iLogic, got the rule to work. I wonder if it will work for others? All they have to do is open an assembly and change the iProperty names if so desired.

 

Incidentally, you'll notice in the below screenshot two columns for 2 iProperties (Stock Number and Item QTY). Inventor forced me to do that b/c in my drawing View Label where an iLogic rule creates the label showing the Qty Req'd, when pulling from 'Item QTY' the rule sometimes won't see a total quantity, and reports the wrong number or resorts to "1". When there's 500+ parts to detail, all that error does is add to the work load! So the way I got around that was to use someone's suggestion in this forum and make a plain text column by copying the values out of the native Inventor iProperty column, and pasting them into a substitute iProperty column. Then query that sub col to get the numbers for the View Label. It worked. So I wanted to try that with a rule that sorts all parts in an assembly by Stock Number. It wasn't working when querying the native Inventor 'Stock Number' iProperty, so now I can try using a substitute iProperty to get what I want out of that rule. Gotta luv these zillions of work-arounds to do just one simple thing!

 

Anyway, here's the results of the above rule:

cadman777_0-1628437316981.jpeg

 


Thanx for the help!

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator