Can't get true values of ItemQuantity for (variable) components of iAssembly Members

Can't get true values of ItemQuantity for (variable) components of iAssembly Members

Maxim-CADman77
Advisor Advisor
202 Views
3 Replies
Message 1 of 4

Can't get true values of ItemQuantity for (variable) components of iAssembly Members

Maxim-CADman77
Advisor
Advisor

I can't get true values of ItemQuantity for (variable) components of iAssembly Members

My iLogic code is:

Option Explicit On

Dim aDoc As AssemblyDocument = ThisDoc.Document
Dim aDef As AssemblyComponentDefinition = aDoc.ComponentDefinition
Dim aBom As BOM = aDef.BOM
If aBom.StructuredViewEnabled = False Then aBom.StructuredViewEnabled = True
aBom.StructuredViewFirstLevelOnly = True

Dim fTbl As iAssemblyFactory = aDef.iAssemblyFactory
Logger.Info("iAssy Member QTY: " & fTbl.TableRows.Count)

'' ReCreate all Members
For Each row In fTbl.TableRows
	fTbl.CreateMember(row)
Next

For Each row In fTbl.TableRows

	Logger.Info(row.MemberName)

	fTbl.DefaultRow = row
	aDoc.Update
	ThisApplication.ActiveView.Update

	' fTbl.CreateMember

	aBom = Nothing
	aBom = aDef.BOM

	Dim stBOMView As BOMView = Nothing
	stBOMView = (From bv In aBom.BOMViews Where bv.ViewType = BOMViewTypeEnum.kStructuredBOMViewType).ToList.FirstOrDefault

	For Each bRow In stBOMView.BOMRows
		Logger.Info(vbTab & vbTab & "ItemNum: " & bRow.ItemNumber)

		Dim compDoc As Document = bRow.ComponentDefinitions(1).Document
		Logger.Info(vbTab & vbTab & vbTab & "Part Number: " & compDoc.PropertySets("Design Tracking Properties")("Part Number").Value)
		Logger.Info(vbTab & vbTab & vbTab & "QTY: " & bRow.ItemQuantity)
	Next
	Threading.Thread.Sleep(999)
Next

When run on attached assembly it reports incorrect QTY for ItemNum: 6 (Part Number: ADSK-1103052)

Correct/Expected values are 2, 3 and 4 but I get either same values or only one correct and zeroes for rest two.

MaximCADman77_0-1750546653280.png

What I'm missing?

 

Dear @MjDeck, could you, please, check this? 

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Accepted solutions (1)
203 Views
3 Replies
Replies (3)
Message 2 of 4

jnowel
Advocate
Advocate

i'm not really familiar with iAssembly in general so below is something i come up with as a workaround.
since the first for-loop recreates the members and can be located in iAssemblyFactory.MemberCacheDir Property. and using the iAssemblyTableRow.DocumentName as the resulting filename, i just used them as references for the BOM of the members. 

Option Explicit On

Dim aDoc As AssemblyDocument = ThisDoc.Document
Dim aDef As AssemblyComponentDefinition = aDoc.ComponentDefinition

'Dim aBom As BOM = aDef.BOM
'If aBom.StructuredViewEnabled = False Then aBom.StructuredViewEnabled = True
'aBom.StructuredViewFirstLevelOnly = True

Dim fTbl As iAssemblyFactory = aDef.iAssemblyFactory
Logger.Info("iAssy Member QTY: " & fTbl.TableRows.Count)

'' ReCreate all Members
For Each Row In fTbl.TableRows
	fTbl.CreateMember(Row)
Next

For Each Row In fTbl.TableRows

	Logger.Info(Row.MemberName)
	
	'fTbl.DefaultRow = Row
	'aDoc.Update
	'ThisApplication.ActiveView.Update

	' fTbl.CreateMember
	Dim fDoc As Document = ThisApplication.Documents.Open(fTbl.MemberCacheDir & "\" & Row.DocumentName ,False)
	Dim fBOM As BOM = 	fDoc.ComponentDefinition.BOM
	If fBOM.StructuredViewEnabled = False Then fBOM.StructuredViewEnabled = True
	fBOM.StructuredViewFirstLevelOnly = True

	Dim stBOMView As BOMView = Nothing
	stBOMView = (From bv In fBOM.BOMViews Where bv.ViewType = BOMViewTypeEnum.kStructuredBOMViewType).ToList.FirstOrDefault

	For Each bRow In stBOMView.BOMRows
		Logger.Info(vbTab & vbTab & "ItemNum: " & bRow.ItemNumber)
		Dim compDoc As Document = bRow.ComponentDefinitions(1).Document
		Logger.Info(vbTab & vbTab & vbTab & "Part Number: " & compDoc.PropertySets("Design Tracking Properties")("Part Number").Value)
		Logger.Info(vbTab & vbTab & vbTab & "QTY: " & bRow.ItemQuantity)
	Next
	fDoc.Close
	Threading.Thread.Sleep(999)
Next

 

Message 3 of 4

Maxim-CADman77
Advisor
Advisor

I currently got to the same workaround, but would like to use some more direct way..

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 4 of 4

MjDeck
Autodesk
Autodesk
Accepted solution

Hi @Maxim-CADman77 - in an iAssembly you have to set the member in the BOM. It's not automatically set by activating a row in the iAssembly table. You can set it with BOMView.iAssemblyMemberName.

After you create the stBOMView object, add this line:

stBOMView.iAssemblyMemberName = row.MemberName

I tested that in Inventor 2025. It should work in earlier versions as well.


Mike Deck
Software Developer
Autodesk, Inc.