Revit Structure Forum
Welcome to Autodesk’s Revit Structure Forums. Share your knowledge, ask questions, and explore popular Revit Structure topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Control the visibility of different types of rebars

1 REPLY 1
SOLVED
Reply
Message 1 of 2
Anonymous
410 Views, 1 Reply

Control the visibility of different types of rebars

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!

1 REPLY 1
Message 2 of 2
StefanDobre
in reply to: Anonymous

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.

Post to forums  

Autodesk Design & Make Report