There was a recent question on the Fusion 360 Customization forum about using an RGB value to set the color of a body. Fusion 360 only allows you to assign an appearance to a body, occurrence, or face. You can’t just assign an RGB value but you can assign an appearance that is the color you want. Another limitation with appearances in Fusion 360 is that you can’t create a new appearance from scratch but instead, you create a new appearance by copying an existing one. And one final limitation is that to use an appearance it must exist in the design; you can’t directly use an appearance from a library. It all seems a bit complicated, and I would agree, but below is some example code that works around these issues to create a new appearance that’s red in color and assigns it to a selected body.
The code above first checks to see if there is already an appearance called “MyRedColor” in the design. If it already exists, it uses it. If it doesn’t, then it copies the appearance named “Paint – Enamel Glossy (Yellow)” from the “Fusion 360 Appearance Library” into the design and as part of the copy operation, it names the copy to “MyRedColor”. It then edits the color of the new appearance to a red color and assigns it to the body.
To make the above work, I had to first find an appearance that was close to what I wanted, except for the color. For example, do you want something that is transparent or opaque? How shiny should it be? There are a lot of settings that control how something is rendered. These settings allow for some nice renderings but also significantly complicate things when you just want something to be red or yellow or blue. Once you’ve identified an existing appearance that is similar to what you want, you can modify the code above to copy that appearance from the library and change its properties to be the way you want it.
Appearances are quite complex and have a lot of settings that control how they render. One of the reasons I chose the paint appearance is because it is a simpler appearance and is mostly defined by a single color. In the example above, I’m getting a property from the appearance that’s named “Color” and using an RGB value to set it. Not all types of appearances will have the same properties. The best way to determine what an appearance supports is to edit in the user interface and click the “Advanced” button to see all of the settings. You can see the result from various appearances below and how they have very different properties.
The edit dialog gives you a nice view of what’s available but then you need to be able to access and change those values using the API. Each appearance is really just a list of properties of various types. The script below will dump information about all the appearances into a text file. You can use this to determine the specific properties of an appearance that you might want to edit. Running the script below will create a big file and it isn’t even dumping out all of the information that is available but should be enough detail in most cases. You can find the appearance in the file and determine the names of the properties that you need to edit. Then by using code similar to the first program above you can do a bit of trial and error to determine the values to use when setting the properties of the appearance.
The approach I use is to use the user interface to find an appearance that’s close to what you want and then use with the Edit dialog to determine if the kind of edits I want to make are possible.