Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create new appearance with RGB color

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
dave.whiteley
739 Views, 2 Replies

Create new appearance with RGB color

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);

2 REPLIES 2
Message 2 of 3

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);
}

Message 3 of 3
BrianEkins
in reply to: dave.whiteley

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report