public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; if (null == doc) { message = "Please run this command in a valid document."; return(Result.Failed); } View3D view = doc.ActiveView as View3D; if (null == view) { message = "Please run this command in a 3D view."; return(Result.Failed); } Element e = Util.SelectSingleElementOfType( uidoc, typeof(Wall), "wall", true); List <WallOpening2d> openings = GetWallOpenings( e as Wall, view); int n = openings.Count; string msg = string.Format( "{0} opening{1} found{2}", n, Util.PluralSuffix(n), Util.DotOrColon(n)); Util.InfoMsg2(msg, string.Join( "\r\n", openings)); return(Result.Succeeded); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Application app = uiapp.Application; Document doc = uidoc.Document; int n = uidoc.Selection.GetElementIds().Count; bool preselected = 0 < n; Element e = null; while (true) { try { e = Util.SelectSingleElementOfType( uidoc, typeof(Element), "an element", true); } catch (Autodesk.Revit.Exceptions.OperationCanceledException) { message = "No element selected"; break; } if (null == e) { break; } string s = "Not a duct."; Duct duct = e as Duct; if (null != duct) { ConnectorProfileType[] profileTypes = GetProfileTypes(duct); n = profileTypes.GetLength(0); s = string.Format("{0} connectors:\r\n", n) + string.Join("\r\n", profileTypes .Select <ConnectorProfileType, string>( a => a.ToString())); } string msg = string.Format( //"{0} is {1} {2} ({3})", "{0} is {1}-{2} ({3})", Util.ElementDescription(e), //MepElementShapeVersion3.GetElementShape( e ), GetElementShape4(e), MepElementShapeVersion2.GetElementShape(e), MepElementShapeV1.GetElementShape(e)); Util.InfoMsg2(msg, s); if (preselected) { break; } } return(Result.Succeeded); }
public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; // Interactively select elements of type Room, // either via pre-selection before launching the // command, or interactively via post-selection. JtSelectorMulti <Room> selector = new JtSelectorMulti <Room>( uidoc, BuiltInCategory.OST_Rooms, "room", e => e is Room); if (selector.IsEmpty) { return(selector.ShowResult()); } IList <Room> rooms = selector.Selected; List <string> msg = new List <string>(); int n = rooms.Count; msg.Add(string.Format( "{0} room{1} selected{2}\r\n", n, Util.PluralSuffix(n), Util.DotOrColon(n))); SpatialElementBoundaryOptions opt = new SpatialElementBoundaryOptions(); IList <IList <BoundarySegment> > loops; Room neighbour; int i = 0, j, k; foreach (Room room in rooms) { ++i; loops = room.GetBoundarySegments(opt); n = loops.Count; msg.Add(string.Format( "{0}. {1} has {2} loop{3}{4}", i, Util.ElementDescription(room), n, Util.PluralSuffix(n), Util.DotOrColon(n))); j = 0; foreach (IList <BoundarySegment> loop in loops) { ++j; n = loop.Count; msg.Add(string.Format( " {0}. Loop has {1} boundary segment{2}{3}", j, n, Util.PluralSuffix(n), Util.DotOrColon(n))); k = 0; foreach (BoundarySegment seg in loop) { ++k; neighbour = GetRoomNeighbourAt(seg, room); msg.Add(string.Format( " {0}. Boundary segment has neighbour {1}", k, (null == neighbour ? "<nil>" : Util.ElementDescription(neighbour)))); } } } Util.InfoMsg2("Room Neighbours", string.Join("\n", msg.ToArray())); return(Result.Succeeded); }