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: A.Acheson

Thanx for the hint, and thanx for admitting that it can be complicated. I tried what you suggested, and it did get me further, but not far enough. There's something missing, and I think (but am not sure) that I need to add more lines to 'drill-down' from the Document all the way down to the Part level.

 

The problem is I don't know how to write lines of code. I WANT to learn, and have been trying since 2018 (during spare time), but just can't find the information I need to 'get it'. I've read and read for 100's of hours, worked through lessons, and more, but there is no structure to any of this that I can see. If there is structure to it, then I would like to read a book or do lessons that will teach me the structure (like English grammar: subject + predicate = complete sentence, or subject + predicate + object = complete sentence), so I can CONSTRUCT lines of code (programming sentences). ALL the lessons and books (like 'VBA for Dummies') do NOT teach that. Having gotten a degree as a teacher, I can tell you as a matter of FACT that all these people who write these books DO NOT KNOW HOW TO TEACH. They just run through concepts and topics that are packed into their heads, but don't TEACH the grammar/syntax of code writing. I get the feeling that they expect you to 'just get it' as you copy their scatter-brained code. But like TAX LAW, you just don't 'get it', b/c there's a myriad of underlying presumptions that are HIDDEN BEHIND the law that not even judges know. Same w/this code stuff. I need all those BASIC hidden rules for constructing sentences (lines of code).

 

Here's the macro I'm trying to make a very simple change to but can't figure out how to do it. It originally was like your post in getting the ItemQuantity from the BOMRow. I wanted to use that comprehensive 'flat list' to get the 'Stock Number' and do the same thing with it that the macro already does. So I figured I could change just one line and it would work. But if I knew the rules better, then I'd know if I needed to change add more lines in addition to changing that one line.  I trust you get what I'm telling you. Incidentally, if I knew how to do this, I would not be borrowing other people's code. I would write mine 'from scratch'. Here's the code:

 

'Get and Set 'Stock Number' in all parts in an assembly in a Custom iProperty named 'StkNum'

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	
' *****************************************************************************************************************************************
'This is what I tried to do using the BOM, but couldn't figure out how to get the iProperty out of the BOM. Is this possible to do?:
' *****************************************************************************************************************************************
				'oSN = oBOMRow.PropertySets.Item("Design Tracking Properties").Item("Stock Number").Value
' ****************************************************************************************************************************************************
'This is how I interpreted your instructions, but it didn't return any value, even though there is a value in the 'Stock Number' of every ipt file:
' ****************************************************************************************************************************************************
				oSN = iProperties.Value(rDoc, "Design Tracking Properties", "Stock Number")
' ****************************************************
'This is my check to see if the line returns a value
' ****************************************************
				MessageBox.Show(oSN, "Stock Number") 
				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

 

Thanx for your 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