I am wondering if there is a way to control the visibility of the different types of rebars separately. The rebars are created by calling Rebar.CreateFromCurves. Could subcategory be used for this purpose?
Thank you very much!
Solved! Go to Solution.
Solved by StefanDobre. Go to Solution.
You can use subcategories for this. Here is a sample code that creates a new subcategory for Rebar, set line color to red and apply it to a RebarBarType (with name #4 in my example). The result will be that all bars with type named "#4" will be colored with red.
using (Transaction tran = new Transaction(m_doc, "Subcategories"))
{
tran.Start();
//get Rebar category
Category rebarCat = Category.GetCategory(m_doc, BuiltInCategory.OST_Rebar);
//create the new subcategory
Category subCat = m_doc.Settings.Categories.NewSubcategory(rebarCat, "1" /* the name of the new sub category*/);
// set visibility propeties to subcategory
subCat.LineColor = new Color(255, 0, 0);
// find the rebar type that you need
FilteredElementCollector fec = new FilteredElementCollector(m_doc).OfClass(typeof(RebarBarType));
foreach ( ElementId barType in fec.ToElementIds())
{
RebarBarType rebarType = m_doc.GetElement(barType) as RebarBarType;
if (rebarType.Name == "#4") // In this sample I want type that have name #4
{
// Set subcategory for the chosen Rebar Type.
Parameter paramSubcat = rebarType.get_Parameter(BuiltInParameter.REBAR_BAR_STYLE);
paramSubcat.Set(subCat.Id);
}
}
tran.Commit();
}
Can't find what you're looking for? Ask the community or share your knowledge.