Hi
I have found an Ilogic from Clint Brown website:
https://clintbrown.co.uk/2019/05/04/ilogic-set-every-part-to-a-different-colour/
I would like to have the same thing (random colors) but the same color for the same part or subassy in order to distinguish the components with the same Part Number.
Would it be possible?
Thank you.
Solved! Go to Solution.
Solved by JelteDeJong. Go to Solution.
try this iLogic rule:
Dim topAsm As AssemblyDocument = ThisDoc.Document Dim trans As Transaction = ThisApplication.TransactionManager.StartTransaction(topAsm, "Unique Colors") Dim ucRep As DesignViewRepresentation Try ucRep = topAsm.ComponentDefinition.RepresentationsManager.DesignViewRepresentations("Unique Colors") Catch ex As Exception ucRep = topAsm.ComponentDefinition.RepresentationsManager.DesignViewRepresentations.Add("Unique Colors") End Try ucRep.Activate() Dim knowOcc As Dictionary(Of String, Asset) = New Dictionary(Of String, Asset) Dim compOcc As ComponentOccurrence For Each compOcc In topAsm.ComponentDefinition.Occurrences Dim occName As String = compOcc.ReferencedFileDescriptor.FullFileName If (knowOcc.ContainsKey(occName)) Then compOcc.Appearance = knowOcc.Item(occName) Else Dim uAppearance As Asset = topAsm.Assets.Add(AssetTypeEnum.kAssetTypeAppearance, "Generic", "appearances") Dim uColor As ColorAssetValue = uAppearance.Item("generic_diffuse") Dim RNG = Math.Round(Rnd() * 255) Dim RNG1 = Math.Round(Rnd() * 255) Dim RNG2 = Math.Round(Rnd() * 255) uColor.Value = ThisApplication.TransientObjects.CreateColor(RNG, RNG1, RNG2) compOcc.Appearance = uAppearance knowOcc.Add(occName, uAppearance) End If Next trans.End()
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Blog: hjalte.nl - github.com
Hi! If the color is assigned in the part (ipt) or subassembly (iam) file, the color should be on a per PN basis.
Many thanks!
@johnsonshiue i missed the part about the partnumber but here is the code based on the part number.
Dim topAsm As AssemblyDocument = ThisDoc.Document Dim trans As Transaction = ThisApplication.TransactionManager.StartTransaction(topAsm, "Unique Colors") Dim ucRep As DesignViewRepresentation Try ucRep = topAsm.ComponentDefinition.RepresentationsManager.DesignViewRepresentations("Unique Colors") Catch ex As Exception ucRep = topAsm.ComponentDefinition.RepresentationsManager.DesignViewRepresentations.Add("Unique Colors") End Try ucRep.Activate() Dim knowOcc As Dictionary(Of String, Asset) = New Dictionary(Of String, Asset) Dim compOcc As ComponentOccurrence For Each compOcc In topAsm.ComponentDefinition.Occurrences Dim occDoc As Document = compOcc.Definition.Document Dim occPropSet As PropertySet = occDoc.PropertySets.Item("Design Tracking Properties") Dim propert As [Property] = occPropSet.Item("Part Number") Dim occName As String = propert.Value If (knowOcc.ContainsKey(occName)) Then compOcc.Appearance = knowOcc.Item(occName) Else Dim uAppearance As Asset = topAsm.Assets.Add(AssetTypeEnum.kAssetTypeAppearance, "Generic", "appearances") Dim uColor As ColorAssetValue = uAppearance.Item("generic_diffuse") Dim RNG = Math.Round(Rnd() * 255) Dim RNG1 = Math.Round(Rnd() * 255) Dim RNG2 = Math.Round(Rnd() * 255) uColor.Value = ThisApplication.TransientObjects.CreateColor(RNG, RNG1, RNG2) compOcc.Appearance = uAppearance knowOcc.Add(occName, uAppearance) End If Next trans.End()
Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Blog: hjalte.nl - github.com
Thank you very much @JelteDeJong
It does what I asked, even when the Part Number is overwritten manually.
I wonder if it would be possible to change it to have the choice between setting a unique color to all the subassies or the single parts.
Before asking to this forum I was trying to change a rule that uses the BOM
Dim oBOMView As BOMView = oBOM.BOMViews.Item("Parts Only") Dim oBOMRow As BOMRow For Each oBOMRow In oBOMView.BOMRows
I wanted to have the choice between the "Parts only" or "Structured" depending on the need.
Is it possible to change the random RGB value to a fixed RAL color chosen from a text parameter that is in the appearance RAL library?