Hi there,
I am using Revit API 2013 to create a plugin for managing the materials.
I have followed the example from Autodesk WikiHelp under the Material Management topic (http://wikihelp.autodesk.com/Revit/enu/2013/Help/00006-API_Developer's_Guide/0074-Revit_Ge74/0118-Ma... by duplicate a material from the sample called "Default". I can duplicate the new materials and list them on the plugin form.
The problem was when I close the form and open the Material Browser, new materials were not there in the "In Document Materials", the list had been deleted and disappeared when I re-open the plugin form.
I guess it might need to update new materials thru the Material Browser but don't know how. Can anyone please help or give any suggestion?
Thanks in advance.
Hi
I am not sure why the behavior is happening, as described in your post. I did a quick check using the code snippet in the wiki, inlcuded below:
FilteredElementCollector elementCollector = newFilteredElementCollector(doc);
elementCollector.WherePasses(newElementClassFilter(typeof(Material)));
IList<Element> materials = elementCollector.ToElements();
Material floorMaterial = null;
string floorMaterialName = "brick";
foreach (Element materialElement in materials)
{
Material material = materialElement asMaterial;
if (floorMaterialName == material.Name)
{
floorMaterial = material;
break;
}
}
if (null != floorMaterial)
{
TaskDialog.Show("Revit", "Material found.");
}
using (Transaction trans = newTransaction(doc, "rotate"))
{
trans.Start();
//try to duplicate a new instance of Material class using duplicate method
//make sure the name of new material is unique in MaterailSet
string newName = "new" + floorMaterial.Name;
Material myMaterial = floorMaterial.Duplicate(newName);
if (null == myMaterial)
{
TaskDialog.Show("Revit", "Failed to duplicate a material!");
}
trans.Commit();
}
After executing the external command, I was able to see the new material (newbrick) added in the materials list as shown below:
Please try out this code and see if it works, If it does not, it might help to share a minimal buildable VS project using which we can investigate further. If an minimal RVT is important to be included, please do so. Please do ensure that none of the material you include contains cofidential information.
cheers
Thanks Saikat for your help! It works now and the transaction does the trick.
Could I ask for another question about the Color of material? Would it possible to assign the color (RGB) for the Appearance properties (rendering), I could set the color for graphics properties shading by :
mat.Color = new Autodesk.Revit.DB.Color(255,0,0);
But I couldn't find the method for the appearance color.
Thanks in advance
F.
Glad to know that the code snuppet helped and that transaction usage was the reason why it was not working previously at your end.
The render properties like color cannot be set using the API at the moment. Some other API users have also asked for this in the recent past and the development team is aware of this.
Sorry for the bad news.
cheers
I would like to copy all the materials from Document to the specific created library or favorites, how could we do that?
I could create files in Document Materials, which is the working document in the project(red zone (1) in the image), but don't know how to get to the libraries or favorite materials in (yellow zone (2))?
Please refer to the attached image. Thanks.