Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.
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.
Solved! Go to Solution.
Solved by WCrihfield. Go to Solution.
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
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.
You mention you want to use Document.DisplayName.
It is different from Document.FullFileName, Document.FullDocumentName, ComponentOccurrence.Name, iLogic function FileName, etc.
Which "display name" you want to use?
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
(Not an Autodesk Employee)
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.