Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Change material of component in assembly

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
J_Dumont
413 Views, 5 Replies

Change material of component in assembly

Hello,

 

I could use some help with changing the material of certain parts in my assembly using iLogic.

 

I've seen various threads that can change all parts within an assembly, but I need to change parts using a specific Display Name. I need to use the Display Name because the file names can change when the assembly is copied using Vault's Copy Design.

 

I have a multi-value parameter at the assembly level, and when the user selects a new value, I need to change the corresponding component's material.

 

The materials are all local at the part level so I think this will simplify the coding.

 

 

 

Tags (2)
Labels (2)
5 REPLIES 5
Message 2 of 6
Michael.Navara
in reply to: J_Dumont

You can use something like this. You need to modify the conditions, parameter name

Sub Main
	Dim materialName As String = MaterialName ' Parameter("MaterialName") ' 
	Dim asm As AssemblyDocument = ThisDoc.Document

	'Iterate all parts
	For Each refDoc As Document In asm.AllReferencedDocuments
		
		'Skip non-part documents
		If refDoc.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then Continue For
			
		'Skip documents which display name doesn't match your criteria
		If Not DisplayNameMatch(refDoc.DisplayName) Then Continue For
			
		'Change the material
		ChangeMaterial(refDoc, materialName)
	Next
	asm.Update()
End Sub

Private Sub ChangeMaterial(part As PartDocument, materialName As String)
	part.ActiveMaterial = part.MaterialAssets(materialName)
End Sub

Private Function DisplayNameMatch(displayName As String) As Boolean
	'Implement your display name validation
	Return displayName.StartsWith("ExpectedDisplayNameHere")
End Function
Message 3 of 6
J_Dumont
in reply to: Michael.Navara

Hi Michael,

 

Thank you for your quick response.

The only issue I  have with your code is that 

refDoc.DisplayName

displays the file name and not the Display Name shown in the Model Browser.

 

Message 4 of 6
Michael.Navara
in reply to: J_Dumont

You mention you want to use Document.DisplayName.

It is different from Document.FullFileNameDocument.FullDocumentNameComponentOccurrence.Name, iLogic function FileName, etc.

 

Which "display name" you want to use?

Message 5 of 6
WCrihfield
in reply to: Michael.Navara

If ComponentOccurrence.Name is the appropriate 'display name' here, then we may be able to use the rather simplistic iLogic shortcut snippet here, like the example below:

iProperties.Material("Part1:1") = "MaterialName"

I do not recall if you can use the MakePath type specifications with that though, for accessing components down within sub assemblies.  I almost never use this myself.

iProperties.Material(MakePath("SubAssem1:1", "Part2:1")) = "MaterialName"

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 6
J_Dumont
in reply to: WCrihfield

Hi Wesley,

 

Thank you. This did the trick. I only need to change the material of two components that are not listed under a sub assembly, so the first suggestion worked perfectly.

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report