Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding

Create new appearance with RGB color

Anonymous
943 Views
2 Replies
Message 1 of 3

Create new appearance with RGB color

Anonymous
Not applicable

I'm trying to follow Mr Ekins' code to create a new appearance  and assign a color to it, then add this new appearance to a Brep face.

It's going wrong in the CAST line (and probably elsewhere.

 

HELP!

 

// create appearance first
Ptr<MaterialLibraries> matlib = app->materialLibraries();
Ptr<Appearance> yellowc = matlib->itemByName("Paint - Enamel Glossy (Yellow)");
Ptr<Appearance> newc = FA->addByCopy(yellowc, "MyGreen");
Ptr<Appearances> prop1 = newc->appearanceProperties();

Ptr<ColorProperty> cprop = adsk::core::ColorProperty::cast(prop1->itemByName("color"));  // WRONG HERE
cprop->value = adsk::core::Color::create(0, 255, 0,0);

bool retval = bfaceCyl->appearance(newc);

0 Likes
Accepted solutions (1)
944 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

OK - got the answer should anyone need it in the future:

 

// add RGB colour to cylinder
Ptr<Appearances> FA = design->appearances();
Ptr<Appearance> C1 = FA->itemByName("MyGreen");

if (C1) {
// appearance exists
bool retval = bfaceCyl->appearance(C1);

}else{
// create appearance first
Ptr<MaterialLibraries> matlibs = app->materialLibraries();
Ptr<MaterialLibrary> matlib = matlibs->itemByName("Fusion 360 Appearance Library");
Ptr<Appearances> apps = matlib->appearances();
Ptr<Appearance> yellowc = apps->itemByName("Paint - Enamel Glossy (Yellow)");
Ptr<Appearance> newc = FA->addByCopy(yellowc, "MyGreen");
Ptr<Properties> prop1 = newc->appearanceProperties();

Ptr<ColorProperty> cprop = prop1->itemByName("Color");
cprop->value(adsk::core::Color::create(0, 255, 0, 0));

bool retval = bfaceCyl->appearance(newc);
}

0 Likes
Message 3 of 3

BrianEkins
Mentor
Mentor
Accepted solution

Just catching up on the forum so I'm a little late to this but here's a blog post from a while ago that goes over this.

https://ekinssolutions.com/setting-colors-in-fusion-360/

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes