How to change or set the path of material appearance with a newly created material .

867902359
Participant

How to change or set the path of material appearance with a newly created material .

867902359
Participant
Participant

Hello everyone, I am a programming novice. I want to set the appearance map of the newly created material in the secondary development of Revit2020, but the AppearanceAssetId is empty. Unfortunately, there is no example of the replacement of the newly created material appearance map on the Internet. Please give a case or point out my mistake.

Snipaste_2022-09-17_20-09-23.jpg

0 Likes
Reply
Accepted solutions (1)
1,178 Views
14 Replies
Replies (14)

867902359
Participant
Participant

Snipaste_2022-09-21_21-12-20.jpg

0 Likes

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @867902359 ,

 

Are you looking for this one?

Material material;
using (AppearanceAssetEditScope editScope = new AppearanceAssetEditScope(doc))
    {
      Asset editableAsset = editScope.Start(material.AppearanceAssetId);
      AssetProperty assetProperty = editableAsset.FindByName("generic_diffuse");
      Asset connectedAsset = assetProperty.GetConnectedProperty(0) as Asset;
      if (connectedAsset.Name == "UnifiedBitmapSchema")
         {
           AssetPropertyString path = connectedAsset.FindByName(UnifiedBitmap.UnifiedbitmapBitmap) as AssetPropertyString;
            path.Value ="Image Path";
          }
          editScope.Commit(true);
      }

Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes

naveen.kumar.t
Autodesk Support
Autodesk Support
Ok, Now I understood your issue.

You are saying the sample code is not working for newly created material.

I am working on this. I will come back to you soon.

Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes

naveen.kumar.t
Autodesk Support
Autodesk Support
Accepted solution

Hi @867902359 ,

 

The newly created Material might not have an AppearanceAssetId set. Thus, it should be set explicitly.

I think the easier way to create new Material is to duplicate one and then modify it.

Please take a look at the below link

https://www.revitapidocs.com/2023/96d557aa-e446-49c5-11cd-59fda2459e82.htm 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

867902359
Participant
Participant
oh! Thank you !you've provided me with a new approach.
0 Likes

KM_Yotsuha
Advocate
Advocate

How can I change the color of Apperence?

KM_Yotsuha
Advocate
Advocate

KM_Yotsuha_0-1665563883208.png

 

NGM_AiYo
Advocate
Advocate

copy a new material and set it's color.

 

Material material = orimaterial.Duplicate(name);
material.Color = color;
material.AppearanceAssetId = orimaterial.AppearanceAssetId;
material.SurfaceForegroundPatternColor = color;

KM_Yotsuha
Advocate
Advocate

I want to change the color in Appearance Tab,the code you provided seem to modify color in Graphics only

 

KM_Yotsuha_0-1665565703946.png

 

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @KM_Yotsuha ,

 

please use the below sample code

Material mat;
if(mat!=null)
  {
    ElementId appearanceAssetId = mat.AppearanceAssetId;
    AppearanceAssetElement assetElem = doc.GetElement(appearanceAssetId) as AppearanceAssetElement;
    using (Transaction t2 = new Transaction(doc))
        {
          t2.Start("transaction name");
          using (AppearanceAssetEditScope editScope=new AppearanceAssetEditScope(assetElem.Document))
           {
             // returns an editable copy of the appearance asset
                Asset editableAsset = editScope.Start(assetElem.Id);
             // Diffuse image
                AssetPropertyDoubleArray4d genericDiffuseProperty = ediableAsset.FindByName("generic_diffuse") as AssetPropertyDoubleArray4d;
               genericDiffuseProperty.SetValueAsColor(new Autodesk.Revit.DB.Color(100,100,100));
                editScope.Commit(true);
            }
            t2.Commit();
      }
}

 Result

Screenshot (15).png


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

KM_Yotsuha
Advocate
Advocate

thank you so much~~

0 Likes

KM_Yotsuha
Advocate
Advocate

our company is in China, what is the parameter of FindByName method when the UI language is Chinese?

I tried  GetAllConnectedProperties Method ,and didn't get any names。

KM_Yotsuha_0-1665627589039.png

 

0 Likes

KM_Yotsuha
Advocate
Advocate

the code works well in English UI,  how can i apply to Chinese UI ? what string for FindByName method?

KM_Yotsuha_0-1665627820853.png

 

 

0 Likes

KM_Yotsuha
Advocate
Advocate

the code works in Chinese UI as well ,thank you~~~ no need to reply my privious post~~~

0 Likes