iLogic Set Material of Parts in Assembly Based on Custom iProperty Value

iLogic Set Material of Parts in Assembly Based on Custom iProperty Value

jishee
Enthusiast Enthusiast
1,333 Views
1 Reply
Message 1 of 2

iLogic Set Material of Parts in Assembly Based on Custom iProperty Value

jishee
Enthusiast
Enthusiast

I have created a custom iProperty in my parts that is called 'Material'. Based on the value that has been assigned, I want to change the material of the part to match. For example, I have parts that have 'Aluminum' for the custom 'Material' iProperty and I want to change the part material to 'Aluminum' from a custom material library I created. I have pieced together some code from some other items I am using but cannot seem to get it to work correctly. Any help is greatly appreciated.

 

'Define assembly component definition
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

'Set material library to WWCW_Material_Library
Dim assetLib As AssetLibrary
assetLib = ThisApplication.AssetLibraries.Item("WWCW_Material_Library")

'Iterate through all of the occurrences
Dim oOcc As ComponentOccurrence
Dim oOccDoc As Document
Dim oPropSet As PropertySet
Dim oProp As [Property]
For Each oOcc In oAsmCompDef.Occurrences
	'Check for material and skip virtual components
	If oOcc.Definition.Type <> ObjectTypeEnum.kVirtualComponentDefinitionObject Then
		oOccDoc = oOcc.Definition.Document
		oPropSet = oOccDoc.PropertySets.Item("Inventor User Defined Properties")
		For Each oProp In oPropSet
			If oProp.Name = "Material" Then
				If oProp.Value = "Aluminum" Then
					'Set the material
					Dim oMaterial_1 As Material
					oMaterial_1 = oOccDoc.Materials.Item("Aluminum")
				Else If oProp.Value = "Silicone" Then
					'Set the material
					Dim oMaterial_2 As Material
					oMaterial_2 = oOccDoc.Materials.Item("Silicone")
				Else If oProp.Value = "PVC" Then
					'Set the material
					Dim oMaterial_3 As Material
					oMaterial_3 = oOccDoc.Materials.Item("PVC")
				Else If oProp.Value = "1 inch IGU" Then
					'Set the material
					Dim oMaterial_4 As Material
					oMaterial_4 = oOccDoc.Materials.Item("1 inch IGU")
				Else If oProp.Value = "Steel" Then
					'Set the material
					Dim oMaterial_5 As Material
					oMaterial_5 = oOccDoc.Materials.Item("Steel")
				End If
			End If
		Next
	End If
Next
0 Likes
1,334 Views
1 Reply
Reply (1)
Message 2 of 2

marcin_otręba
Advisor
Advisor
0 Likes