Swap a Material for another Material within the project doc

Swap a Material for another Material within the project doc

FrankHolidaytoiling
Advocate Advocate
457 Views
1 Reply
Message 1 of 2

Swap a Material for another Material within the project doc

FrankHolidaytoiling
Advocate
Advocate

I would like to swap one material for another material. I tried setting the original material by material, by category and material class. None of these approaches seems to have any effect.

Also I am collection the system.type Material for my filtered element collector.

thanx

 

using (Transaction trans = new Transaction(_doc, "Material Swap"))
{
trans.Start();
Material oldMaterial = elemType as Material;
oldMaterial.MaterialClass = newMatType(strStyle_New).MaterialClass;
trans.Commit();
}

458 Views
1 Reply
Reply (1)
Message 2 of 2

jeremytammik
Autodesk
Autodesk

Frank,

 

This question is impossible to answer without more detail and context. What is the object you are trying to set the material on? Is is a Revit BIM element? What kind of element? Some ways to set materials are provided by the MaterialId properties defined on on many different Revit API classes. Look at them the Revit API help file RevitAPI.chm! The CompoundStructure class also provides a SetMaterialId method. The best place to understand the issue in context is the Revit API developer guide:

 

http://help.autodesk.com/view/RVT/2016/ENU/?guid=GUID-FD067FA5-623D-474B-98FB-686C096F0165

 

The Building Coder provides some discussion on controlling element materials here:

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#5.24

 

I hope this helps.

 

Best regards,

 

Jeremy

 

P.S. Who gave you a kudo for this question?

 

You also raised the same issue on StackOverflow:

 

http://stackoverflow.com/questions/35677102/how-to-swap-one-material-for-another-material-in-the-rev...

 

Somebody gave your question there an upvote as well, even though it was later rejected as being too broad in scope.

 

What is going on here?

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes