Changing colors on entire iassembly

Changing colors on entire iassembly

kschaffroth1
Contributor Contributor
1,245 Views
4 Replies
Message 1 of 5

Changing colors on entire iassembly

kschaffroth1
Contributor
Contributor

Hello,

 

I'm currently working on an iAssembly that has 3 different variations and I am trying to figure out how to change the entire iAssembly color. The problem I'm running into is since I'm trying to color more than one assembly, it doesn't know where parts on a different row in the iAssembly are and gives me an error code. 

 

My original code to just test if it would even do anything looks something like this:

 

Component.Color("PART1-BOTTOM:1") = ColorSelect
Component.Color("PART2-BOTTOM:1") = ColorSelect
Component.Color("PART3-BOTTOM:1") = ColorSelect

 ColorSelect is a user parameter that I have a bunch of different colors linked.

 

So I guess to recap I am essentially trying to get the entire iAssembly to change colors based on ColorSelect, but when I try to run my rule it just says that the part is missing from the assembly.

 

More Info stuff in the error pop-up looks like this: 

System.ArgumentException: Component: The component named "PART2-BOTTOM:1" was not found.
at iLogic.ComponentInRule.FindComponents(Object componentName, Boolean topLevelOnly, Boolean inTopLevelContext)
at iLogic.ComponentInRule.set_Color(Object componentName, String value)
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

0 Likes
Accepted solutions (1)
1,246 Views
4 Replies
Replies (4)
Message 2 of 5

WCrihfield
Mentor
Mentor

I'm not 100% sure, but I don't think using that Component.Color() line is going to get you where you want to go.  I believe that is a 'shortcut' line for accessing/working with the 'active' assembly document.  And if the specified component name isn't actually placed within the 'active' assembly somewhere (not just a line of data in a table), I don't think it will work.  I believe you will have to go the longer route for changing the color of each iAssembly member in an iAssembly factory's table.

Assuming you have a column within your iAssembly factory table with its heading as "Color", I think something like this should do what you are trying to do.

Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oAFact As iAssemblyFactory = oADoc.ComponentDefinition.iAssemblyFactory
'oAFact.MemberEditScope = MemberEditScopeEnum.kEditAllMembers
For Each oRow As iAssemblyTableRow In oAFact.TableRows
	'Color is specifying the column's Header value to specify which column's cell your accessing in that row
	oRow.Item("Color").Value = ColorSelect 'assuming ColorSelect contains the String name of a Color or existing Appearance
Next

But I don't use iAssemblys, so I haven't tested it.

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 5

kschaffroth1
Contributor
Contributor

Do you think you could explain your code? I am new to iLogic and am not quite sure what it is those lines you wrote are actually doing. I would like to be able to know what my code is doing and not just running what someone writes me on a forum. 

 

Thanks!

0 Likes
Message 4 of 5

WCrihfield
Mentor
Mentor
Accepted solution

OK. I guess it can be complicated.  I will try to elaborate further on everything.

First of all, an assembly doesn't have a material or an appearance of its own, but the Part type components within it can and do, so there's not really a one shot way to change the appearance of the whole assembly.

You appear to be attempting to change the appearance of 'each' component within the assembly, which is definitely doable, both manually and by code.   Manually, you can select the component, then either change the value in the Appearance drop-down menu (Tools tab > Material and Appearance panel), or right-click on it > then choose iProperties > then on the Occurrence tab > change the value in the appearance drop-down list.

 

By code, if you want to change the appearance of all occurrences that have been placed within a 'normal' assembly, you can 'loop' through them all (don't need to know their names), and do one of the following.  1) Within the 'loop' you can use that shortcut line of code to change its 'color' by supplying a String (text) name of the color or appearance you want to set it to.  2) You can go the longer route of attempting to set the component's ComponentOccurrence.AppearanceSourceType to 'kComponentOccurrenceAppearance' and its ComponentOccurrence.Appearance to an appearance type Asset (a pre-existing named appearance in your document's appearances list).  But this may not work if the component is 'assosiatively' set to a design view representation (DesignViewRepresentation).  You can check if the component is 'associatively' set using its ComponentOccurrence.IsAssociativeToDesignViewRepresentation Property, but it's not as easy to turn that associative setting off (it is possible though).

 

An example iLogic rule code using the shortcut method you were using would look something like this:

Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
For Each oOcc As ComponentOccurrence In oADef.Occurrences
	Component.Color(oOcc.Name) = ColorSelect 'or something simple like "Red"
Next

 The first line of code in that example, is attempting to get the 'local' or 'active' assembly document object.  The next line of code is retrieving the assembly document's component definition, which is where all the components are within.  Then the For Each...Next terms are used to 'loop' through a set of objects...in this case the set of all component occurrences that are within the assemblies component definition.  Then the Component.Color() line is a shortcut line of code to help you get or set the 'color' of whichever component name you supply (as long as that component is found within the 'active' assembly.)  If either it doesn't find the specified component, or if it doesn't recognize the 'color' name you specified, it will throw an error.

 

You said in your first post that the word "ColorSelect" you used in your rule represented a local user parameter (within the main assembly document), right?  And you said that it has "a bunch of different colors linked".  Do you mean it is a multi-value 'text' type user parameter,  and it has a list of names of colors within it?  If so, that should work OK with this simpler example code above, because it is asking for us to specify a color name.

 

The original iLogic code I posted was attempting to access the iAssembly's configuration table, so it could be edited, and I assumed it might have a column within it that specified the 'color' of components in the iAssembly member rows.  I also assumed I could just edit that table cell's text based value to change it to the name of the color you wanted them to be.   Since I'm not very familiar with iAssemblies, did a bit of guessing there.  Since this is an iAssembly, I do know it has a table where you can change Parameter values, iProperty Values, Exclusions, iMates, BOM stuff, etc, so I assumed you might have a column within the table that you set-up using this 'ColorSelect' user parameter.  That way you can change its value individually for each row (member) of the table.  However, the code I originally posted still wouldn't have looped through each component within each one of those members (iAssemblyMember) to change the color of all components within each of them.  I'm honestly not sure if that can be done in one shot from the iAssemblyFactory document.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 5

kschaffroth1
Contributor
Contributor

Wow, thank you for your detailed response!


Yes, it is a user parameter within my assembly with multiple values of all the materials I want to use. I tried to see if I could add User text parameters to my iAssembly factory but from my research online it appears you cannot add text parameters to either iPart or iAssembly factories.

0 Likes