AppearanceAssetId not available

AppearanceAssetId not available

Anonymous
Not applicable
400 Views
1 Reply
Message 1 of 2

AppearanceAssetId not available

Anonymous
Not applicable

Hi,

I am trying to create a new material and set it appearance properties (in particular it's color).

I have tried to find and existing appearance asset and use it to create my own copy. However, when I loop over all materials using the following code:

            var materials = new FilteredElementCollector(modelDocument)
                .OfClass(typeof(Material))
                .ToElements()
                .Cast < Material > ().ToList();

and check the AppearanceAssetId property, I see that for all materials it's set to -1 (including all the default materials). 

How can I retrieve a valid asset to create my own instance?

 

0 Likes
Accepted solutions (1)
401 Views
1 Reply
Reply (1)
Message 2 of 2

franciscopossetto
Advocate
Advocate
Accepted solution

Hey,

 

I tested your code on the Revit sample house and it worked. I can read the AppearanceAssetId:

franciscopossetto_0-1629138789844.png

 

Then I tried on an empty project, without templates. Materials were created, but they all had -1 as ApparenceAssetId as your case. For some reason, the Generic AppearanceAsset applied has this Id. If you add a new one from the Library, then it has another id.

 

I would check how many appearanceAssetElements you have on the model. 

ICollection<Element> appearanceAssetElements = new FilteredElementCollector(doc).OfClass(typeof(Autodesk.Revit.DB.AppearanceAssetElement)).ToElements();

 

And then, get the one you need:

string appearanceAssetElementId= "144211";
ElementId appearanceAssetElement = new FilteredElementCollector(doc).OfClass(typeof(AppearanceAssetElement)).ToElementIds().Where(a => a.ToString().Equals(appearanceAssetElementId)).FirstOrDefault();

 

I hope it helps.

Kind regards.

Github:
https://github.com/franpossetto
0 Likes