Create Custom Iproperties with Values from Parts Only BOM View

Create Custom Iproperties with Values from Parts Only BOM View

Victor.Tuguinay
Enthusiast Enthusiast
472 Views
8 Replies
Message 1 of 9

Create Custom Iproperties with Values from Parts Only BOM View

Victor.Tuguinay
Enthusiast
Enthusiast

I am looking to have a modified version of the code below to retrieve the item numbers of the parts that are in my sub assemblies and make custom iproperties that lists those item numbers. I will explain below.

 

So I have my main assembly with a number of subassemblies. Each of those subassemlies is composed of two parts - called "Flange" and "Pipe". I would like a "Flange Item" and "Pipe Item" custom iproperty created in each of the subassemblies (not the parts). The values of these will be equal to the item number of the part as listed in the Parts Only BOM view of the main assembly.

 

For example, in the screenshot of my model tree below, the W06-065375 ROOF NOZZLE N3 component has components "Flange" and "ROOF NOZZLE PIPE". I am trying to create custom iproperties in the W06-065375 ROOF NOZZLE N3 subassemly with the item numbers of the two parts with values from the Parts Only BOM View.

 

Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oDef As AssemblyComponentDefinition = oAsm.ComponentDefinition
Dim oBOM As BOM = oDef.BOM
oBOM.StructuredViewEnabled = True
Dim oBOMView As BOMView = oBOM.BOMViews(2) 'Structured View
For Each oRow As BOMRow In oBOMView.BOMRows
	For Each rDef As ComponentDefinition In oRow.ComponentDefinitions
		If TypeOf (rDef) Is VirtualComponentDefinition Then Continue For
		Try
			rDef.Document.PropertySets("Inventor User Defined Properties")("ItemNumber").Value = oRow.ItemNumber.ToString()
		Catch
			rDef.Document.PropertySets("Inventor User Defined Properties").Add(oRow.ItemNumber.ToString, "ItemNumber")
		End Try
	Next
Next

 

VictorTuguinay_0-1728654032773.png

@JelteDeJong @WCrihfield 

0 Likes
Accepted solutions (1)
473 Views
8 Replies
Replies (8)
Message 2 of 9

WCrihfield
Mentor
Mentor

What do you want the names of those two custom iProperties to be?  You example is just showing "ItemNumber", but if there are two different components, and there will be two custom iProperties (one to hold the ItemNumber value for each component), then their names will need to be different.  Should one be "Flange ItemNumber" and the other "Pipe ItemNumber", or something like that?

Are there any custom ModelStates in those sub assemblies?  If so, then should these custom iProperty values be the same for all ModelState versions of those sub assemblies, or will those values need to be different for different ModelState versions of those sub assemblies?  Same question for the main assembly...does it have any custom ModelStates?  And if so, will any of these details be different when a different ModelState is the active one in the main assembly?

 

Also, is it possible that the same sub assembly document is being represented within the overall structure of the main assembly by more than one component occurrence.  If so, then what if those two items have different Item Numbers under the other instance, from the main assembly BOM's point of view?  The referenced document level information will either be overwritten when the second occurrence is encountered, or the first instance will be used, and not any other instances, which may lead to unexpected results.  Just thinking about possible hypotheticals here, since writing main assembly level information down into lower levels of that assembly is usually a bad idea, for multiple reasons.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 9

Victor.Tuguinay
Enthusiast
Enthusiast

Hi! The example code only creates the "ItemNumber" custom iproperty with the value from the Structured BOM View for that subassembly. What I am looking for is to create two custom iproperties in the subassembly and will be called "Flange Item" and "Pipe Item" and will be equal to the item numbers of the two parts as they are listed in the Parts Only BOM View.

 

Thak you for your response.

0 Likes
Message 4 of 9

Victor.Tuguinay
Enthusiast
Enthusiast
There is only one occurrence for each subassemly. But each of those subassemblies will have "Flange" and "Pipe" parts which are different .ipt's. eventhough they are named the same since I stabilized the name in the model tree.
0 Likes
Message 5 of 9

Victor.Tuguinay
Enthusiast
Enthusiast

There is only one models state in those subassemblies. 

 

The custom iproperties will only be created in the subassembly level, not it the parts making up the subassembly.

 

My main objective is to fill up the "Components (B,C)" column in the table below. This column will be the item numbers of the parts making up nozzle tags. For example, N2 is composed of 1 and 7.  Those items are listed in another table called "MATERIAL LIST". I hope this makes sense.

 

VictorTuguinay_0-1728657452912.png

VictorTuguinay_1-1728657619497.png

 

 

0 Likes
Message 6 of 9

jnowel
Advocate
Advocate

like this?

Sub Main
	
Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oDef As AssemblyComponentDefinition = oAsm.ComponentDefinition
Dim oBOM As BOM = oDef.BOM
oBOM.PartsOnlyViewEnabled = True
Dim oBOMView As BOMView = oBOM.BOMViews(("Parts Only")) 'Structured View

For Each oRow As BOMRow In oBOMView.BOMRows
	For Each rDef As ComponentDefinition In oRow.ComponentDefinitions
		If TypeOf (rDef) Is VirtualComponentDefinition Then Continue For
		If InStr (rDef.Document.DisplayName.ToUpper, "FLANGE") Then 
			Set_CustomiProp(rDef.Document, "Flange Item", oRow.ItemNumber.ToString)
		ElseIf InStr (rDef.Document.DisplayName.ToUpper, "PIPE") Then 
			Set_CustomiProp(rDef.Document, "Pipe Item", oRow.ItemNumber.ToString)
		End If
	Next
Next

End Sub

Sub Set_CustomiProp(oDoc As Document, iPropName As String, iPropVal As String) 

	Try
		oDoc.PropertySets.Item("User Defined Properties").Item(iPropName).Value = iPropVal
	Catch
		 oDoc.PropertySets.Item("User Defined Properties").Add(iPropVal, iPropName)
	End Try
	
End Sub
0 Likes
Message 7 of 9

WCrihfield
Mentor
Mentor
Accepted solution

Here is an example iLogic rule you could try out for that task.

 

Sub Main
	Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
	If oADoc Is Nothing Then Return
	Dim oBOM As Inventor.BOM = oADoc.ComponentDefinition.BOM
	If Not oBOM.PartsOnlyViewEnabled = True Then oBOM.PartsOnlyViewEnabled = True
	Dim oPartsOnlyBOMView As BOMView = Nothing
	For Each oBOMView As BOMView In oBOM.BOMViews
		If oBOMView.ViewType = BOMViewTypeEnum.kPartsOnlyBOMViewType Then
			oPartsOnlyBOMView = oBOMView
			Exit For
		End If
	Next oBOMView
	If oPartsOnlyBOMView Is Nothing Then Return
	For Each oRow As BOMRow In oPartsOnlyBOMView.BOMRows
		For Each oRowOcc As ComponentOccurrence In oRow.ComponentOccurrences
			If oRowOcc.Suppressed Then Continue For
			If TypeOf oRowOcc.Definition Is VirtualComponentDefinition Then Continue For
			Dim oParentSubAsmOcc As ComponentOccurrence = oRowOcc.ParentOccurrence
			If oParentSubAsmOcc Is Nothing Then Continue For
			Dim oParentSubAsmDoc As AssemblyDocument = Nothing
			Try : oParentSubAsmDoc = oParentSubAsmOcc.Definition.Document : Catch : End Try
			If oParentSubAsmDoc Is Nothing Then Continue For
			Dim oCProps As Inventor.PropertySet = oParentSubAsmDoc.PropertySets.Item(4)
			Dim sItem As String = oRow.ItemNumber
			If oRowOcc.Name.ToUpper.Contains("PIPE") Then
				Try
					oCProps.Item("Pipe Item").Value = sItem
				Catch
					Try : oCProps.Add(sItem, "Pipe Item") : Catch : End Try
				End Try
			ElseIf oRowOcc.Name.ToUpper.Contains("FLANGE") Then
				Try
					oCProps.Item("Flange Item").Value = sItem
				Catch
					Try : oCProps.Add(sItem, "Flange Item") : Catch : End Try
				End Try
			End If
		Next oRowOcc
	Next oRow
	oADoc.Update2(True)
End Sub

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 8 of 9

Victor.Tuguinay
Enthusiast
Enthusiast
Thank you for your response.
0 Likes
Message 9 of 9

Victor.Tuguinay
Enthusiast
Enthusiast

Thanks @WCrihfield ! I tried it out and it works!

0 Likes