How to know what material elements in Revit project file are not used with Dynamo so I can delete safely?

Hello,

If I open Revit Material Manager window and I select show only Used Materials I see too many that I do not believe they are used. I tried to get all model elements of a 3d view that shows everything, but expluding annotative elements, cad imports and links.

After this I get the materials of those instance elements and then I take all unique material elements collected from all the element instances. In other side I get all material elements in the Revit file which are too many more than the model elements so I just set the difference and delete, but yeah the Revit crashed for an hour without response, so I suppose this is not the safe way to delete materials unused.

I tried Purge button of Revit but nothing appears that can be purged but I do not recognise many materials that are in the Material Manager Browser of the Revit file though.

So what is this no-sense? Maybe there are other materials applied somewhere else than the model elements? maybe object-styles or CAD-import objects? how to check that with dynamo or python code?

Would it be possible to get all material elements of a project and ask them where are they used? in what elements are used? like reverse process of this script I mean.


GetElementsofActiveViewMaterialsreport3.dyn (26.2 KB)

I tried this so far in this script and I do not understand why too many differences if the script is supposed to do the same of collecting elements and getting their materials, I tried in python and OOTB node I do not know the differences but anyway I tried to delete the differences and I see the materials in pipe types are deleted and the pipe types were visible in view, the same as other materials deleted that I do not know yet where they came from and maybe they are important and I do not know:

GetElementsofActiveViewMaterialsreport2.dyn (56.7 KB)

What is your definition of “used”?

There may be materials that are “used” in the families/type definitions but without a family instance placed in the 3D view. These materials cannot be purged until their unused families/types are purged.

Here is an example:
I have a lighting fixture family named “LightingFixture1”, and its types have a material parameter with the value “Plastic Material 1”. I have loaded this family and its types to my projects, but I never placed any in my model. In this case, although “Plastic Material 1” is not used in the 3D views, I still cannot delete it from my project until I remove the family types of “LightingFixture1” that use this material.

In my Revit file example all is 100% purged already and all family types have instances. In second script i did some different tests but i don’t understand yet where some materials come from, i suppose it’s not about element instances

I am not quite helpful here, but here are my two cents:
(1) your guess is right, 2D annotation components (e.g., Detail Items) may have material parameters too. Object styles may also have materials assigned (they are tied to Categories).

(2) I have seen some addins that use change trackers to identify where a material is used. For example, they delete material A to see what elements change as a result (e.g., a family, type, etc.). This requires registering elementChanged events, deleting each material to see what other changes occur, rolling-back the changes, and reporting out where each material is used. registering events is not feasible in Dynamo as far as I know, but pyRevit or a C# addin support this.

The old rule: If Revit can’t do it, Dynamo can’t do it either applies here i think.
I’ve seen a few special cases where this is not true (mobius shape). That fascinates me the the most in Dynamo land.
You can delete all Wall Types except one, have you tried that test?.

So the answer depends on the ‘why do you want to do this’ aspect.

If it’s about management at a higher level, not project specific, then you can start with your template, purge everything 3x, then set about tackling system families and then object styles.

For system families you’re best off going though the project browser and looking at what is left. All elements of class can help here, provided you build a list of all the classes, or you can dive into the API. From there you grab every parameter or assembly, remove and sub-elements you can (ie: all layers of the remaining wall type except the last one), and set the material of the remaining ones to “by category”, null, or the invalid element id. When you’re done there, purge unused again and have a look at what is left.

After that you move onto object styles. I don’t recommend managing these via the API in your template, as it’s a ‘one time’ thing for a handful of files. Prodding the graphic style elements is likely the best path forward on that front if you do want to use the Revit API though.

After that, purge unused again. When all is said and done you can get every material out but one this way… and even then that one can be deleted in the UI. It’s quite handy to have a ‘material free template’ for various purposes.

2 Likes

In practice, materials are “not definitive” until mister architect is happy,
Good one

To add on, my approach is generally more no mercy.

Purge unused materials until theyre gone, then I go to mat browser and delete any not named to company systems. Users learn fairly quickly this way.

Yes you’ll get a few grumblers at first but eventually they learn about model health and its a good outcome. Then they can police new team members etc.

1 Like

How about the 3d guys making presentations?
Are they not mad?

I find that most of the time we worry about materials too much. They have less impact on model health than the assets they use. Those are what take the effort to build (usually), and are what I recommend the ‘no mercy’ policy for. Users can then map to the company standard more readily in order to keep those, while still keeping the carbon calculations? Material schedules, and the documentation content working. Well unless someone was dimensioning to those hatch patterns, which is another sin to review…

1 Like

Yes, but they learn fast if I’m their model manager.

In time most of them are happy when their model opens 3x faster than the typical one.

Yes materials for me are an out of sight model bloat and just general mess. My argument to managers etc as to why it matters is that we often tie material specs to them so the more chaff in the model, the higher the risk we get a spec/code wrong on drawings.

They also tend to accompany rogue/revit city content when they become an issue, so they’re an indicator of more pressing health issues.

Yeah - and keeping the material in thenproject makes such issue so they can be found.

Also keeping them in the model keeps things so they can be reassigned, often rather easily compared to deleting them and having to find ‘unassigned’ materials. That’ll help with maintaining the spec too. So to me building the tool to ‘swap’ materials for stuff in the project standard (not firm; too many multi firm jobs and client driven specs to think a firm can have only one standard in play) goes pretty far and maintains the content.

Thanks for all the answers, very appreciated the perspectives. I don’t ask this for pleasure, it’s a need.

The reason of asking this is because when purged until the end, I still see materials that i don’t recognise and i don’t have a clue where they are used, and this is a template which is pretending to be very clean and the materials have product data description and appearance as much as similar of products, and testing with dynamo script i get around 300 materials but the materials from elements instance query is like 70,

so clearly I see more than 200 materials that i don’t know where they come from, not from the family used I suppose, so i guess i have to query more type of revit elements that are not family instances/types.

I was asking if there is a direct method to get the elements used by each unique material, i think i did somehow in the second script, the first time I am trying this with Dynamo so I supposed this is something more than known by dynamo users.

I need to know where are they used because if they are used are necessary but need to refine properly, but by reading a material name I don’t even know if the material is correct or what it is in the context of use.

I deleted with Dynamo all materials not used by family instances and i saw something is missing in system families and maybe object styles but not sure what has been deleted yet, so i am expecting the script could tell me that material is used in that setting of somewhere so I can find it myself in Revit and understand what it is.

The best solution short of developing a tool that can handle the heaviness of model combined with hunting all of the possible places materials are used is Ideate style manager. They’ve gone to the length of doing this and we use it where I work for these sorts of things. Yes it’s paid, need to assess time to research and build the tool vs take one off a shelf.

There is no API method to be smart enough to do this for you on its own unfortunately, so the solution will be to dig up all the things that could use materials (going right down to materials in families etc.) and then rename/reload, find and reassign subcats etc. It’s a lot of work and I haven’t even attempted it in dynamo (I have in pyRevit, but still doesn’t find everything). The tool would need to look into families first, rename their materials to replacement material names/reload, and then target project specific usege cases. Compound structures etc. are fun (have done these in pyRevit), the rest are generally a property of an object from its related collector. The document class is often the starting point for graphical ones such as categories and subcategories.

2 Likes