Material: Use Render Appearance for Shading

Material: Use Render Appearance for Shading

khanh_phamWU8FK
Participant Participant
1,235 Views
15 Replies
Message 1 of 16

Material: Use Render Appearance for Shading

khanh_phamWU8FK
Participant
Participant

I have used the API to update the color in the Appearance tab. It's okay, however, the Shading color remains the old color. How can I fix this?

 

Material.jpg

 

0 Likes
Accepted solutions (2)
1,236 Views
15 Replies
Replies (15)
Message 2 of 16

jeremy_tammik
Alumni
Alumni

How do you achieve the desired setting manually in the user interface?

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 16

khanh_phamWU8FK
Participant
Participant

Hi Jeremy,

Thanks for response. If "Use Render Appearance" is checked, whenever you change the color of Appearance, the Shading color is changed accordingly.

0 Likes
Message 4 of 16

jeremy_tammik
Alumni
Alumni

OK, thanks; I asked the development team for you.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 5 of 16

GaryOrrMBI
Collaborator
Collaborator
There's a Property for that:
[yourmaterial].UseRenderAppearanceForShading = True

see the API help: Autodesk.Revit.DB -> Material Class
-G
Gary J. Orr
GaryOrrMBI (MBI Companies 2014-Current)
aka (past user names):
Gary_J_Orr (GOMO Stuff 2008-2014);
OrrG (Forum Studio 2005-2008);
Gary J. Orr (LHB Inc 2002-2005);
Orr, Gary J. (Gossen Livingston 1997-2002)
0 Likes
Message 6 of 16

jeremy_tammik
Alumni
Alumni

Hi Gary, 

  

oh wow, thank you for picking that up!

  

Cheers

  

Jeremy

   

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 7 of 16

GaryOrrMBI
Collaborator
Collaborator

It takes a village (or in this case a "Community" 🙂 )

 

Looking back at the screenshot in the OP however, I'm wondering if the issue is that setting it isn't producing the desired result since the box is checked but the color is incorrect.

 

-G

 

 

Gary J. Orr
GaryOrrMBI (MBI Companies 2014-Current)
aka (past user names):
Gary_J_Orr (GOMO Stuff 2008-2014);
OrrG (Forum Studio 2005-2008);
Gary J. Orr (LHB Inc 2002-2005);
Orr, Gary J. (Gossen Livingston 1997-2002)
0 Likes
Message 8 of 16

khanh_phamWU8FK
Participant
Participant

Hi Gary,

Thank you, "the box is checked but the color is incorrect." => That's what I'm talking about

0 Likes
Message 9 of 16

jeremy_tammik
Alumni
Alumni

OK, so maybe we should start from scratch. What is the problem please?

  

The toggle can be set both manually in the UI and programmatically in the API. Both of those methods work for setting the toggle.

  

Correct?

  

If yes:

  

When you set this toggle manually n the UI, it has the desired effect.

  

Correct?

  

When you set this toggle programmatically n the API, it has the desired effect.

  

Correct?

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 10 of 16

khanh_phamWU8FK
Participant
Participant

The toggle can be set both manually in the UI and programmatically in the API. Both of those methods work for setting the toggle.
=> Correct.


When you set this toggle manually n the UI, it has the desired effect.
=> Correct.


When you set this toggle programmatically n the API, it has the desired effect.
=> I did not set this toggle programmatically. It's true by default.
I've just set the Appearance color programmatically and my expectation is the Shading color will be changed to the same, but Shading color is incorrect. The result as you can see from the screenshot.

0 Likes
Message 11 of 16

jeremy_tammik
Alumni
Alumni

I understand now and reported this to the development team.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 12 of 16

GaryOrrMBI
Collaborator
Collaborator
Accepted solution

I just ran a test using the Revit 2023 API and I can confirm this behavior.

 

Test 1: created a new material programmatically with thisMaterial.UseRenderAppearanceForShading = False

result as expected (direct control of shading color):

GaryOrrMBI_0-1698927101183.png

 

Test 2: created a new material programmatically with thisMaterial.UseRenderAppearanceForShading = False,

then manually checked the box in the UI. The resulting color and transparency values were generated as usual when creating a material in the UI (the shading color being derived by a combination of the color and bitmap properties that are set in the Appearance Asset):

GaryOrrMBI_1-1698927315502.png

 

Test 3: created a new material programmatically with thisMaterial.UseRenderAppearanceForShading = True

The resulting color was different than that generated in test 2 (even though all properties of the Appearance Asset were identical):

GaryOrrMBI_2-1698927609143.png

 

Test 4: Duplicated the material created in test 3 in the UI, using the same Appearance Asset as the test 3 material:

The result was the same as test 3. Unchecked the Use Render... in the UI. Hit apply. changed the Shading color. hit apply. checked Use Render... and: the color reverted to the unexpected color in Material 3 (expected result was the resulting color in Material 2).

 

Test 5: Duplicated Material 1 in the UI, using the same Appearance Asset as Material 1. Checked Use Render... and the result was the same as Test 2 (the expected derived color).

 

Test 6: Changed the Appearance Asset in Material 3 to use the one created in test 2. The derived Shading color was the same as in Test 2 (the expected derived color).

 

Continued changing Appearance Assets in the different test materials between those created programmatically as well as manually duplicating those Appearance Assets and assigning them using the UI.


As a final test, I moved the setting of the material properties to later in the code (after the creation of the Appearance Asset) and...

bingo!!! we have a winner. Everything started acting as it should act.

 

The final result and conclusion: The bug comes in the form of an Appearance Asset that is created programmatically after the Use Render Appearance value is enabled programmatically in the Material itself. This specific combination sets the derived color value to an unexpected value that somehow becomes cached in the Appearance asset.

 

@khanh_phamWU8FK,

Try creating and assigning the Appearance Asset before setting the Use Render... property on the material.

 

-G

Gary J. Orr
GaryOrrMBI (MBI Companies 2014-Current)
aka (past user names):
Gary_J_Orr (GOMO Stuff 2008-2014);
OrrG (Forum Studio 2005-2008);
Gary J. Orr (LHB Inc 2002-2005);
Orr, Gary J. (Gossen Livingston 1997-2002)
Message 13 of 16

khanh_phamWU8FK
Participant
Participant
Accepted solution

Hi Garry,

The solution you suggested worked remarkably well, and I am pleased with the outcome. Thank you once again for your outstanding support.

0 Likes
Message 14 of 16

GaryOrrMBI
Collaborator
Collaborator
I wouldn't actually call it a solution, more of a workaround while we hope for a solution.

One additional note:
It might not hurt (especially if duplicating a Material and/or Render Asset) to set the UseRender... property to False immediately after creating/duplicating the Material,
then create/duplicate the Appearance Asset,
then if so desired, change the UseRender... property to True.

This would help ensure that your new Appearance Asset doesn't get the "bug" to start with.

I'm making this change to my base Material creation routine now.

-G
Gary J. Orr
GaryOrrMBI (MBI Companies 2014-Current)
aka (past user names):
Gary_J_Orr (GOMO Stuff 2008-2014);
OrrG (Forum Studio 2005-2008);
Gary J. Orr (LHB Inc 2002-2005);
Orr, Gary J. (Gossen Livingston 1997-2002)
Message 15 of 16

c_hanschen
Advocate
Advocate
Hello!

khanh_phamWU8FK started the post with "used the API to update the color in the Appearance tab", that's just were I am looking for! It's easy to change all colors of the Material, but this is a Asset Color, Right?

Can you share some code how to change the Appearance color of the Asset?
(without changing to a other existing asset)

Thanks in Advance!

Chris Hanschen
LKSVDD architecten
The Netherlands

0 Likes