public Autodesk.Revit.UI.Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { try { // get the active document and view UIDocument revitDoc = commandData.Application.ActiveUIDocument; Autodesk.Revit.DB.View view = revitDoc.ActiveView; Document dbDoc = revitDoc.Document; ElementId currentTextTypeId = dbDoc.GetDefaultElementTypeId(ElementTypeGroup.TextNoteType); foreach (ElementId elemId in revitDoc.Selection.GetElementIds()) { Element elem = dbDoc.GetElement(elemId); if (elem.GetType() == typeof(Autodesk.Revit.DB.Structure.Rebar)) { // cast to Rebar and get its first curve Autodesk.Revit.DB.Structure.Rebar rebar = (Autodesk.Revit.DB.Structure.Rebar)elem; Autodesk.Revit.DB.Curve curve = rebar.GetCenterlineCurves(false, false, false, MultiplanarOption.IncludeAllMultiplanarCurves, 0)[0]; // calculate necessary arguments Autodesk.Revit.DB.XYZ origin = new XYZ( curve.GetEndPoint(0).X + curve.Length, curve.GetEndPoint(0).Y, curve.GetEndPoint(0).Z); string strText = "This is " + rebar.Category.Name + " : " + rebar.Name; // create the text using (Transaction t = new Transaction(dbDoc)) { t.Start("New text note"); TextNote.Create(dbDoc, view.Id, origin, strText, currentTextTypeId); t.Commit(); } return(Autodesk.Revit.UI.Result.Succeeded); } } message = "No rebar selected!"; return(Autodesk.Revit.UI.Result.Failed); } catch (Exception e) { message = e.Message; return(Autodesk.Revit.UI.Result.Failed); } }
public Autodesk.Revit.UI.Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { try { // Get the active document and view UIDocument revitDoc = commandData.Application.ActiveUIDocument; Autodesk.Revit.DB.View view = revitDoc.Document.ActiveView; foreach (ElementId elemId in revitDoc.Selection.GetElementIds()) { Element elem = revitDoc.Document.GetElement(elemId); if (elem.GetType() == typeof(Autodesk.Revit.DB.Structure.Rebar)) { // cast to Rebar and get its first curve Autodesk.Revit.DB.Structure.Rebar rebar = (Autodesk.Revit.DB.Structure.Rebar)elem; Autodesk.Revit.DB.Curve curve = rebar.GetCenterlineCurves(false, false, false, MultiplanarOption.IncludeAllMultiplanarCurves, 0)[0]; // create a rebar tag at the first end point of the first curve using (Transaction t = new Transaction(revitDoc.Document)) { t.Start("Create new tag"); IndependentTag tag = IndependentTag.Create(revitDoc.Document, view.Id, new Reference(rebar), true, Autodesk.Revit.DB.TagMode.TM_ADDBY_CATEGORY, Autodesk.Revit.DB.TagOrientation.Horizontal, curve.GetEndPoint(0)); t.Commit(); } return(Autodesk.Revit.UI.Result.Succeeded); } } message = "No rebar selected!"; return(Autodesk.Revit.UI.Result.Failed); } catch (Exception e) { message = e.Message; return(Autodesk.Revit.UI.Result.Failed); } }
public Autodesk.Revit.UI.Result Execute( ExternalCommandData revit, ref string message, ElementSet elements) { try { // Get the active document and view UIDocument revitDoc = revit.Application.ActiveUIDocument; Autodesk.Revit.DB.View view = revitDoc.Document.ActiveView; foreach (Autodesk.Revit.DB.Element elem in revitDoc.Selection.Elements) { //if( elem.GetType() == typeof( Autodesk.Revit.DB.Structure.Rebar ) ) if (elem is Rebar) { string str = ""; Autodesk.Revit.DB.Structure.Rebar rebar = (Autodesk.Revit.DB.Structure.Rebar)elem; ParameterSet pars = rebar.Parameters; foreach (Parameter param in pars) { string val = ""; string name = param.Definition.Name; Autodesk.Revit.DB.StorageType type = param.StorageType; switch (type) { case Autodesk.Revit.DB.StorageType.Double: val = param.AsDouble().ToString(); break; case Autodesk.Revit.DB.StorageType.ElementId: Autodesk.Revit.DB.ElementId id = param.AsElementId(); Autodesk.Revit.DB.Element paraElem = revitDoc.Document.get_Element(id); if (paraElem != null) { val = paraElem.Name; } break; case Autodesk.Revit.DB.StorageType.Integer: val = param.AsInteger().ToString(); break; case Autodesk.Revit.DB.StorageType.String: val = param.AsString(); break; default: break; } str = str + name + ": " + val + "\r\n"; } MessageBox.Show(str, "Rebar parameters"); return(Autodesk.Revit.UI.Result.Succeeded); } } message = "No rebar selected!"; return(Autodesk.Revit.UI.Result.Failed); } catch (Exception e) { message = e.Message; return(Autodesk.Revit.UI.Result.Failed); } }