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

Get Rebar Layout Rule

1 REPLY 1
SOLVED
Reply
Message 1 of 2
tomragnarsson
222 Views, 1 Reply

Get Rebar Layout Rule

 

Hi.

 

I'm trying to create an addin which will update the IFC-parameter "IfcName" for all rebars in a project. However, I'm encountering a problem whenever I have a rebar set with the "Fixed number" layout. The barSpacing parameter is generating an error, because a rebar set with fixed numbers does not have any information about spacing, so it throws an error. I can not seem to find a good way to check if the layout rule is fixed numbers (or single). The Rebar class has a property named LayoutRule, which seems to be what I'm after, but it does not show up in my IDE (Visual Studio). Seems to me the property doesn't exist at all. Any suggestions how to solve this? 

 

 

Tom

using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.UI.Selection;
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using Autodesk.Revit.Attributes;
using System.Windows.Forms;

namespace RevitClassLibrary.Armering
{
    [Transaction(TransactionMode.Manual)]
    public class UpdateIfcName : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument uidoc = uiapp.ActiveUIDocument;
            Document doc = uidoc.Document;

            // Get all rebars in the document
            FilteredElementCollector collector = new FilteredElementCollector(doc);
            ICollection<Element> rebars = collector.OfClass(typeof(Rebar)).ToElements();

                // Iterate through each rebar and update IfcName parameter
                foreach (Element rebar in rebars)
                {
                    // Get the required parameters
                    var barQuantity = rebar.get_Parameter(BuiltInParameter.REBAR_ELEM_QUANTITY_OF_BARS).AsInteger();
                    var barSpacing = (barQuantity > 1) ? rebar.get_Parameter(BuiltInParameter.REBAR_ELEM_BAR_SPACING).AsValueString().TrimEnd('m').Trim() : null;
                    var barDiameter = rebar.get_Parameter(BuiltInParameter.REBAR_BAR_DIAMETER).AsValueString().TrimEnd('m').Trim();
                    var posisjonsnummer = rebar.LookupParameter("Postnummer").AsString();
                    var cqRebarSuffix = rebar.LookupParameter("CQRebarSuffix").AsString();

                    var ifcName = barQuantity + "ø" + barDiameter + "c" + barSpacing + ", " + posisjonsnummer + ", " + cqRebarSuffix;
                    
                    // Write to the IfcName parameter
                    Parameter ifcNameParameter = rebar.LookupParameter("IfcName");
                    if (ifcNameParameter != null && !ifcNameParameter.IsReadOnly)
                    {
                        using (Transaction transaction = new Transaction(doc, "Update IfcName"))
                        {
                            transaction.Start();
                            ifcNameParameter.Set(ifcName);
                            transaction.Commit();
                        }
                    }
                }
            return Result.Succeeded;
        
        }
    }
}

 

Labels (2)
1 REPLY 1
Message 2 of 2
RPTHOMAS108
in reply to: tomragnarsson

Check the layout rule parameter first on the instance i.e.

REBAR_ELEM_LAYOUT_RULE

 

This is an integer and the values are defined in

...DB.Structure.RebarLayoutRule

 

Should also be able to use class property Rebar.LayoutRule same way.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Forma Design Contest


Rail Community