iLogic to change material doesn't actually change material but thinks it does?

iLogic to change material doesn't actually change material but thinks it does?

Stephan.Osterhaus
Contributor Contributor
792 Views
3 Replies
Message 1 of 4

iLogic to change material doesn't actually change material but thinks it does?

Stephan.Osterhaus
Contributor
Contributor

I have an assembly with multiple sheet metal parts that I'm trying to use iLogic to change the material of. The log indicates that the material change command went through, and the BOM when accessed from the assembly level seems to corroborate that. However if I open the actual part file the material doesn't change. What's interesting is that the material saves in this state - if I close everything and open again I still get an assembly and part that disagree on the material of the part. Any ideas what I'm doing wrong?

Dim MaterialChangeDocList As New ArrayList
Dim oAssemDoc As AssemblyDocument = odoc
Dim oLeafOcc As ComponentOccurrence
For Each oOcc In odoc.ComponentDefinition.Occurrences.AllLeafOccurrences
	If Left(oOcc.Definition.Document.FullFileName,"<FILE DIRECTORY STRING>".Length) = "<FILE DIRECTORY STRING>"
		If oOcc.Definition.Document.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
			If oOcc.Definition.Document.PropertySets.Item("Design Tracking Properties").Item("Material").Value = "Fiberglass"
			Else
				If MaterialChangeDocList.Contains(oOcc.Definition.Document.FullFileName) Or oOcc.Definition.Document.FullFileName = "<FILE DIRECTORY STRING>Custom_Builder_00.ipt"
				Else
					MaterialChangeDocList.Add(oOcc.Definition.Document.FullFileName)
					Logger.Debug("PRE - " & oOcc.Definition.Document.PropertySets.Item("Design Tracking Properties").Item("Material").Value)
					
					If (oOcc.Definition.Document.FullFileName = "<FILE DIRECTORY STRING>Custom_Builder_FG_01.ipt") And (MaterialGradeForRails = "PO A36 MS")
						oOcc.Definition.Document.PropertySets.Item("Design Tracking Properties").Item("Material").Value = "AP A36 MS"
					Else
						oOcc.Definition.Document.PropertySets.Item("Design Tracking Properties").Item("Material").Value = MaterialGradeForRails
					End If
					iLogicVb.RunRule(oOcc.Name, "Identify Sheet Stock Code")
					
					Logger.Debug("POST - " & oOcc.Definition.Document.PropertySets.Item("Design Tracking Properties").Item("Material").Value)
					oOcc.Definition.Document.Update
					oOcc.Definition.Document.Save
					oOcc.Definition.Document.Close
				End If
			End If
		End If
	End If
Next

 

(IT has been on a security crackdown recently so I took out the file directories because they mention company info). It's pretty simple, checks a bunch of conditions to find the exact parts that need their materials changed (eventually I'll clean up that block of if statements) then change the materials of the part directly through the iProperties.

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

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @Stephan.Osterhaus 

 

Try replacing this:

oOcc.Definition.Document.PropertySets.Item("Design Tracking Properties").Item("Material").Value = MaterialGradeForRails

with this:

iProperties.MaterialOfComponent(oOcc.name)  = MaterialGradeForRails

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes
Message 3 of 4

Stephan.Osterhaus
Contributor
Contributor

That works perfectly TYVM. I'm still curious as to what exactly was happening with my original code since it doesn't throw any errors. Am I changing material of the instance of the part in the assembly separately from the actual part material? If so I wasn't aware inventor even supported such a feature. May throw it in my back pocket as an option on future projects if I know this is intended behavior and not just a bug. 

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

Hi @Stephan.Osterhaus.  Just to add to the conversation.  That iProperty simply records the name of the material that you set the part to...it doesn't set the material to the part.  In order to set the a new material to a part the normal way (API), you would get the PartDocument object, then use its ActiveMaterial property.  That is a Read/Write property, which is requesting an 'Asset' object, not simply the name of a material.  So, you would find the actual material (an Asset or MaterialAsset object) within the material library, then supply that object to that property.  The iLogic shortcut snippet that Curtis pointed out is, just that...a shortcut way to do that task in the setting of an assembly.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes