/// <summary> /// Search for the In-Place family instance's properties data to be listed /// and graphics data to be drawn. /// </summary> /// <param name="inPlaceMember">properties data to be listed</param> /// <param name="model">graphics data to be draw</param> /// <returns>Returns true if retrieved this data</returns> private bool PrepareData(ref FamilyInstance inPlaceMember, ref AnalyticalModel model) { ElementSet selected = new ElementSet(); foreach (ElementId elementId in m_commandData.Application.ActiveUIDocument.Selection.GetElementIds()) { selected.Insert(m_commandData.Application.ActiveUIDocument.Document.GetElement(elementId)); } if (selected.Size != 1) { return(false); } foreach (object o in selected) { inPlaceMember = o as FamilyInstance; if (null == inPlaceMember) { return(false); } } model = inPlaceMember.GetAnalyticalModel(); if (null == model) { return(false); } return(true); }
/// <summary> /// create truss in Revit /// </summary> /// <returns>new created truss</returns> public Autodesk.Revit.DB.Structure.Truss CreateTruss() { Autodesk.Revit.Creation.Document createDoc = m_commandData.Application.ActiveUIDocument.Document.Create; Autodesk.Revit.Creation.Application createApp = m_commandData.Application.Application.Create; //sketchPlane Autodesk.Revit.DB.XYZ origin = new Autodesk.Revit.DB.XYZ(0, 0, 0); Autodesk.Revit.DB.XYZ xDirection = new Autodesk.Revit.DB.XYZ(1, 0, 0); Autodesk.Revit.DB.XYZ yDirection = new Autodesk.Revit.DB.XYZ(0, 1, 0); Plane plane = createApp.NewPlane(xDirection, yDirection, origin); SketchPlane sketchPlane = createDoc.NewSketchPlane(plane); //new base Line AnalyticalModel frame1 = column1.GetAnalyticalModel(); Autodesk.Revit.DB.XYZ centerPoint1 = (frame1.GetCurve() as Line).get_EndPoint(0); AnalyticalModel frame2 = column2.GetAnalyticalModel(); Autodesk.Revit.DB.XYZ centerPoint2 = (frame2.GetCurve() as Line).get_EndPoint(0); Autodesk.Revit.DB.XYZ startPoint = new Autodesk.Revit.DB.XYZ(centerPoint1.X, centerPoint1.Y, 0); Autodesk.Revit.DB.XYZ endPoint = new Autodesk.Revit.DB.XYZ(centerPoint2.X, centerPoint2.Y, 0); Autodesk.Revit.DB.Line baseLine = null; try { baseLine = createApp.NewLineBound(startPoint, endPoint); } catch (System.ArgumentException) { MessageBox.Show("Two column you selected are too close to create truss."); } return(createDoc.NewTruss(m_selectedTrussType, sketchPlane, baseLine)); }
public static void UpdateSizingFactors(this Building building, AnalyticalModel analyticalModel) { if (building == null || analyticalModel == null) { return; } List <Space> spaces = analyticalModel.AdjacencyCluster?.GetSpaces(); if (spaces == null || spaces.Count == 0) { return; } double heatingSizingFactor = double.NaN; if (!analyticalModel.TryGetValue(AnalyticalModelParameter.HeatingSizingFactor, out heatingSizingFactor)) { heatingSizingFactor = double.NaN; } double coolingSizingFactor = double.NaN; if (!analyticalModel.TryGetValue(AnalyticalModelParameter.CoolingSizingFactor, out coolingSizingFactor)) { coolingSizingFactor = double.NaN; } UpdateSizingFactors(building, spaces, heatingSizingFactor, coolingSizingFactor); }
/// <summary> /// create GraphicsData of given AnalyticalModel3D /// </summary> /// <param name="model">AnalyticalModel3D contains geometry data</param> /// <returns></returns> public static GraphicsData CreateGraphicsData(AnalyticalModel model) { IList <Curve> curveList = model.GetCurves(AnalyticalCurveType.ActiveCurves); if (curveList.Count > 0) { GraphicsData data = new GraphicsData(); IEnumerator <Curve> curves = curveList.GetEnumerator(); curves.Reset(); while (curves.MoveNext()) { Curve curve = curves.Current as Curve; try { List <XYZ> points = curve.Tessellate() as List <XYZ>; data.InsertCurve(points); } catch { } } data.UpdataData(); return(data); } else { throw new Exception("Can't get curves."); } }
/// <summary> /// create truss in Revit /// </summary> /// <returns>new created truss</returns> public Autodesk.Revit.DB.Structure.Truss CreateTruss() { Autodesk.Revit.DB.Document document = m_commandData.Application.ActiveUIDocument.Document; Autodesk.Revit.Creation.Document createDoc = document.Create; Autodesk.Revit.Creation.Application createApp = m_commandData.Application.Application.Create; //sketchPlane Autodesk.Revit.DB.XYZ origin = new Autodesk.Revit.DB.XYZ(0, 0, 0); Autodesk.Revit.DB.XYZ xDirection = new Autodesk.Revit.DB.XYZ(1, 0, 0); Autodesk.Revit.DB.XYZ yDirection = new Autodesk.Revit.DB.XYZ(0, 1, 0); Plane plane = Plane.CreateByOriginAndBasis(xDirection, yDirection, origin); SketchPlane sketchPlane = SketchPlane.Create(document, plane); //new base Line AnalyticalModel frame1 = column1.GetAnalyticalModel(); Autodesk.Revit.DB.XYZ centerPoint1 = (frame1.GetCurve() as Line).GetEndPoint(0); AnalyticalModel frame2 = column2.GetAnalyticalModel(); Autodesk.Revit.DB.XYZ centerPoint2 = (frame2.GetCurve() as Line).GetEndPoint(0); Autodesk.Revit.DB.XYZ startPoint = new Autodesk.Revit.DB.XYZ(centerPoint1.X, centerPoint1.Y, 0); Autodesk.Revit.DB.XYZ endPoint = new Autodesk.Revit.DB.XYZ(centerPoint2.X, centerPoint2.Y, 0); Autodesk.Revit.DB.Line baseLine = null; try { baseLine = Line.CreateBound(startPoint, endPoint); } catch (System.ArgumentException) { TaskDialog.Show("Argument Exception", "Two column you selected are too close to create truss."); } return(Autodesk.Revit.DB.Structure.Truss.Create(document, m_selectedTrussType.Id, sketchPlane.Id, baseLine)); }
/***************************************************/ /**** Public methods ****/ /***************************************************/ public static List <ICurve> AnalyticalOutlines(this HostObject hostObject, RevitSettings settings = null) { AnalyticalModel analyticalModel = hostObject.GetAnalyticalModel(); if (analyticalModel == null) { //TODO: appropriate warning or not - physical preferred? return(null); } settings = settings.DefaultIfNull(); List <ICurve> wallCurves = analyticalModel.GetCurves(AnalyticalCurveType.ActiveCurves).ToList().FromRevit(); if (wallCurves.Any(x => x == null)) { hostObject.UnsupportedOutlineCurveWarning(); return(null); } List <ICurve> result = BH.Engine.Geometry.Compute.IJoin(wallCurves).ConvertAll(c => c as ICurve); if (result.Any(x => !x.IIsClosed())) { hostObject.NonClosedOutlineWarning(); return(null); } return(result); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="dataAccess">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess dataAccess) { dataAccess.SetData(1, false); bool run = false; if (!dataAccess.GetData(1, ref run)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } if (!run) { return; } string path_TBD = null; if (!dataAccess.GetData(0, ref path_TBD) || string.IsNullOrWhiteSpace(path_TBD)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } AnalyticalModel analyticalModel = null; using (SAMTBDDocument sAMTBDDocument = new SAMTBDDocument(path_TBD)) { analyticalModel = Analytical.Tas.Convert.ToSAM(sAMTBDDocument); } dataAccess.SetData(0, analyticalModel); dataAccess.SetData(1, analyticalModel != null); }
/// <summary> /// Get points of the truss /// </summary> /// <returns>points array stores all the points on truss</returns> public List <XYZ> GetTrussPoints() { List <XYZ> xyzArray = new List <XYZ>(); try { IEnumerator iter = m_truss.Members.GetEnumerator(); iter.Reset(); while (iter.MoveNext()) { Autodesk.Revit.DB.ElementId id = (Autodesk.Revit.DB.ElementId)(iter.Current); Autodesk.Revit.DB.Element elem = m_commandData.Application.ActiveUIDocument.Document.GetElement(id); FamilyInstance familyInstace = (FamilyInstance)(elem); AnalyticalModel frame = familyInstace.GetAnalyticalModel(); Line line = (Line)(frame.GetCurve()); xyzArray.Add(line.GetEndPoint(0)); xyzArray.Add(line.GetEndPoint(1)); } } catch (System.ArgumentException) { TaskDialog.Show("Revit", "The start point and the end point of the line are too close, please re-draw it."); } return(xyzArray); }
public static bool Sizing(this string path_TBD, AnalyticalModel analyticalModel = null, bool excludeOutdoorAir = false, bool excludePositiveInternalGains = false) { if (string.IsNullOrWhiteSpace(path_TBD)) { return(false); } if (!Sizing_PrepareDocument(path_TBD, excludeOutdoorAir)) { return(false); } string directory = global::System.IO.Path.GetDirectoryName(path_TBD); string path_TBD_Uncapped = global::System.IO.Path.Combine(directory, global::System.IO.Path.GetFileNameWithoutExtension(path_TBD) + "_Uncapped" + global::System.IO.Path.GetExtension(path_TBD)); global::System.IO.File.Copy(path_TBD, path_TBD_Uncapped, true); Sizing_ApplyAirGlass(path_TBD, excludePositiveInternalGains); string path_TBD_HDDCDD = global::System.IO.Path.Combine(directory, global::System.IO.Path.GetFileNameWithoutExtension(path_TBD) + "_HDDCDD" + global::System.IO.Path.GetExtension(path_TBD)); global::System.IO.File.Copy(path_TBD, path_TBD_HDDCDD, true); Sizing_ApplyOversizingFactors(path_TBD, analyticalModel); return(true); }
/// <summary> /// create GraphicsData of given AnalyticalModel3D /// </summary> /// <param name="model">AnalyticalModel3D contains geometry data</param> /// <returns></returns> public static GraphicsData CreateGraphicsData(AnalyticalModel model) { IList<Curve> curveList = model.GetCurves(AnalyticalCurveType.ActiveCurves); if (curveList.Count > 0) { GraphicsData data = new GraphicsData(); IEnumerator<Curve> curves = curveList.GetEnumerator(); curves.Reset(); while (curves.MoveNext()) { Curve curve = curves.Current as Curve; try { List<XYZ> points = curve.Tessellate() as List<XYZ>; data.InsertCurve(points); } catch { } } data.UpdataData(); return data; } else { throw new Exception("Can't get curves."); } }
public static List <Element> ToRevit(this AnalyticalModel analyticalModel, Document document, ConvertSettings convertSettings) { if (analyticalModel == null || document == null) { return(null); } List <Element> result = convertSettings?.GetObjects <Element>(analyticalModel.Guid); if (result != null) { return(result); } result = ToRevit(analyticalModel.AdjacencyCluster, document, convertSettings); if (convertSettings.ConvertParameters) { ProjectInfo projectInfo = document.ProjectInformation; if (projectInfo != null) { if (result.Find(x => x.Id == projectInfo.Id) == null) { result.Add(projectInfo); } Core.Revit.Modify.SetValues(projectInfo, analyticalModel); Core.Revit.Modify.SetValues(projectInfo, analyticalModel, ActiveSetting.Setting, convertSettings.GetParameters()); } } convertSettings?.Add(analyticalModel.Guid, result); return(result); }
/// <summary> /// Create a new Point BoundaryConditions Element. /// All the parameter default as Fixed. /// </summary> /// <param name="hostElement"> /// structural element which provide the analytical line end reference /// </param> /// <returns> the created Point BoundaryConditions Element</returns> private Autodesk.Revit.DB.BoundaryConditions CreatePointBC(Autodesk.Revit.DB.Element hostElement) { if (!(hostElement is FamilyInstance)) { return(null); } FamilyInstance familyInstance = hostElement as FamilyInstance; AnalyticalModel analyticalModel = familyInstance.GetAnalyticalModel(); Reference endReference = null; Curve refCurve = analyticalModel.GetCurve(); if (null != refCurve) { endReference = analyticalModel.GetReference(new AnalyticalModelSelector(refCurve, AnalyticalCurveSelector.EndPoint)); } else { return(null); } Autodesk.Revit.Creation.Document createDoc = hostElement.Document.Create; // invoke Document.NewPointBoundaryConditions Method Autodesk.Revit.DB.BoundaryConditions createdBC = createDoc.NewPointBoundaryConditions(endReference, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); return(createdBC); }
/// <summary> /// get necessary data when create AreaReinforcement on a horizontal floor /// </summary> /// <param name="floor">floor on which to create AreaReinforcemen</param> /// <param name="refer">reference of the horizontal face on the floor</param> /// <param name="curves">curves compose the horizontal face of the floor</param> /// <returns>is successful</returns> public bool GetFloorGeom(Floor floor, ref Reference refer, ref IList <Curve> curves) { //get horizontal face reference FaceArray faces = GeomUtil.GetFaces(floor); foreach (Face face in faces) { if (GeomUtil.IsHorizontalFace(face)) { refer = face.Reference; break; } } //no proper reference if (null == refer) { return(false); } //check the analytical model profile is rectangular AnalyticalModel model = floor.GetAnalyticalModel(); if (null == model) { return(false); } curves = model.GetCurves(AnalyticalCurveType.ActiveCurves); if (!GeomUtil.IsRectangular(curves)) { return(false); } return(true); }
public static bool UpdateBuildingElements(this TBDDocument tBDDocument, AnalyticalModel analyticalModel) { if (tBDDocument == null || analyticalModel == null) { return(false); } Building building = tBDDocument.Building; if (building == null) { return(false); } UpdateConstructions(tBDDocument, analyticalModel); List <buildingElement> buildingElements = building.BuildingElements(); if (buildingElements == null || buildingElements.Count == 0) { return(false); } List <TBD.Construction> constructions = building.Constructions(); if (constructions == null || constructions.Count == 0) { return(false); } foreach (buildingElement buildingElement in buildingElements) { string name = Query.Name(buildingElement); if (string.IsNullOrWhiteSpace(name)) { continue; } TBD.Construction construction = constructions.Find(x => name.Equals(x.name)); if (construction == null) { List <TBD.Construction> constructions_Temp = constructions.FindAll(x => name.EndsWith(x.name)); if (constructions_Temp != null && constructions_Temp.Count != 0) { constructions_Temp.Sort((x, y) => System.Math.Abs(x.name.Length - name.Length).CompareTo(System.Math.Abs(y.name.Length - name.Length))); construction = constructions_Temp.First(); } } if (construction == null) { continue; } buildingElement.AssignConstruction(construction); } return(true); }
/// <summary> /// get all the required information of selected elements and store them in a data table /// </summary> /// <param name="selectedElements"> /// all selected elements in Revit main program /// </param> /// <returns> /// a data table which store all the required information /// </returns> private DataTable StoreInformationInDataTable(ElementSet selectedElements) { DataTable informationTable = CreatDataTable(); foreach (Element element in selectedElements) { // Get AnalyticalModel analyticalModel = element.GetAnalyticalModel(); if (null == analyticalModel) // skip no AnalyticalModel element { continue; } DataRow newRow = informationTable.NewRow(); string idValue = element.Id.IntegerValue.ToString(); // store element Id value string typeName = ""; // store element type name string[] supportInformation = GetSupportInformation(analyticalModel); // store support information // get element type information switch (element.GetType().Name) { case "WallFoundation": WallFoundation wallFound = element as WallFoundation; ElementType wallFootSymbol = m_revit.Application.ActiveUIDocument.Document.GetElement(wallFound.GetTypeId()) as ElementType;// get element Type typeName = wallFootSymbol.Category.Name + ": " + wallFootSymbol.Name; break; case "FamilyInstance": FamilyInstance familyInstance = element as FamilyInstance; FamilySymbol symbol = m_revit.Application.ActiveUIDocument.Document.GetElement(familyInstance.GetTypeId()) as FamilySymbol; typeName = symbol.Family.Name + ": " + symbol.Name; break; case "Floor": Floor slab = element as Floor; FloorType slabType = m_revit.Application.ActiveUIDocument.Document.GetElement(slab.GetTypeId()) as FloorType; // get element type typeName = slabType.Category.Name + ": " + slabType.Name; break; case "Wall": Wall wall = element as Wall; WallType wallType = m_revit.Application.ActiveUIDocument.Document.GetElement(wall.GetTypeId()) as WallType; // get element type typeName = wallType.Kind.ToString() + ": " + wallType.Name; break; default: break; } // set the relative information of current element into the table. newRow["Id"] = idValue; newRow["Element Type"] = typeName; newRow["Support Type"] = supportInformation[0]; newRow["Remark"] = supportInformation[1]; informationTable.Rows.Add(newRow); } return(informationTable); }
protected override void SolveInstance(IGH_DataAccess dataAccess) { int index; index = Params.IndexOfInputParam("_analytical"); if (index == -1) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } Core.SAMObject sAMObject = null; if (!dataAccess.GetData(index, ref sAMObject) || sAMObject == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } AdjacencyCluster adjacencyCluster = null; if (sAMObject is AnalyticalModel) { adjacencyCluster = ((AnalyticalModel)sAMObject).AdjacencyCluster; } else if (sAMObject is AdjacencyCluster) { adjacencyCluster = new AdjacencyCluster((AdjacencyCluster)sAMObject); } List <Zone> zones = null; if (adjacencyCluster != null) { zones = adjacencyCluster.MapZones(); if (zones != null && zones.Count != 0) { if (sAMObject is AdjacencyCluster) { sAMObject = adjacencyCluster; } else if (sAMObject is AnalyticalModel) { sAMObject = new AnalyticalModel((AnalyticalModel)sAMObject, adjacencyCluster); } } } index = Params.IndexOfOutputParam("Analytical"); if (index != -1) { dataAccess.SetData(index, sAMObject); } index = Params.IndexOfOutputParam("Zones"); if (index != -1) { dataAccess.SetDataList(index, zones); } }
public static bool UpdateShading(this TBD.TBDDocument tBDDocument, AnalyticalModel analyticalModel, double tolerance = Core.Tolerance.Distance) { if (tBDDocument == null || analyticalModel == null) { return(false); } return(UpdateShading(tBDDocument?.Building, analyticalModel, tolerance)); }
public static Building ToT3D(this AnalyticalModel analyticalModel, T3DDocument t3DDocument) { if (t3DDocument == null || analyticalModel == null) { return(null); } return(ToT3D(analyticalModel.AdjacencyCluster, t3DDocument.Building)); }
public static AnalyticalModel UpdateFacingExternal(this AnalyticalModel analyticalModel, SAMTBDDocument sAMTBDDocument) { if (analyticalModel == null || sAMTBDDocument == null) { return(null); } return(UpdateFacingExternal(analyticalModel, sAMTBDDocument.TBDDocument)); }
public static bool UpdateZones(this AnalyticalModel analyticalModel, SAMTBDDocument sAMTBDDocument, bool includeHDD = false) { if (analyticalModel == null || sAMTBDDocument == null) { return(false); } return(UpdateZones(sAMTBDDocument.TBDDocument?.Building, analyticalModel, includeHDD)); }
public static AnalyticalModel UpdateFacingExternal(this AnalyticalModel analyticalModel, TBD.TBDDocument tBDDocument) { if (analyticalModel == null || tBDDocument == null) { return(null); } Dictionary <string, TBD.zone> zones = tBDDocument.Building?.ZoneDictionary(); if (zones == null) { return(null); } AdjacencyCluster adjacencyCluster = analyticalModel.AdjacencyCluster; if (adjacencyCluster == null) { return(null); } Dictionary <string, Space> spaces = adjacencyCluster.SpaceDictionary(); if (spaces == null) { return(null); } if (zones.Count == 0 || spaces.Count == 0) { return(new AnalyticalModel(analyticalModel)); } foreach (KeyValuePair <string, Space> keyValuePair in spaces) { TBD.zone zone = null; if (!zones.TryGetValue(keyValuePair.Key, out zone)) { continue; } if (zone == null) { continue; } Space space_New = UpdateFacingExternal(keyValuePair.Value, zone); if (space_New == null) { continue; } adjacencyCluster.AddObject(space_New); } return(new AnalyticalModel(analyticalModel, adjacencyCluster)); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="dataAccess">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess dataAccess) { int index_successful = Params.IndexOfOutputParam("successful"); if (index_successful != -1) { dataAccess.SetData(index_successful, false); } int index; bool run = false; index = Params.IndexOfInputParam("_run"); if (index == -1 || !dataAccess.GetData(index, ref run)) { run = false; } if (!run) { return; } string path_TBD = null; index = Params.IndexOfInputParam("_pathTasTBD"); if (index == -1 || !dataAccess.GetData(index, ref path_TBD) || string.IsNullOrWhiteSpace(path_TBD)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } AnalyticalModel analyticalModel = null; index = Params.IndexOfInputParam("_analyticalModel"); if (index == -1 || !dataAccess.GetData(index, ref analyticalModel) || analyticalModel == null) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data"); return; } bool result = Analytical.Tas.Modify.UpdateShading(path_TBD, analyticalModel); index = Params.IndexOfOutputParam("analyticalModel"); if (index != -1) { dataAccess.SetData(index, analyticalModel); } if (index_successful != -1) { dataAccess.SetData(index_successful, result); } }
/// <summary> /// get necessary data when create AreaReinforcement on a straight wall /// </summary> /// <param name="wall">wall on which to create AreaReinforcemen</param> /// <param name="refer">reference of the vertical straight face on the wall</param> /// <param name="curves">curves compose the vertical face of the wall</param> /// <returns>is successful</returns> public bool GetWallGeom(Wall wall, ref Reference refer, ref CurveArray curves) { FaceArray faces = GeomUtil.GetFaces(wall); LocationCurve locCurve = wall.Location as LocationCurve; //unless API has bug, locCurve can't be null if (null == locCurve) { return(false); } //check the location is line Line locLine = locCurve.Curve as Line; if (null == locLine) { return(false); } //get the face reference foreach (Face face in faces) { if (GeomUtil.IsParallel(face, locLine)) { refer = face.Reference; break; } } //can't find proper reference if (null == refer) { return(false); } //check the analytical model profile is rectangular AnalyticalModel model = wall.GetAnalyticalModel(); if (null == model) { return(false); } IList <Curve> curveList = model.GetCurves(AnalyticalCurveType.ActiveCurves); curves = m_currentDoc.Application.Create.NewCurveArray(); foreach (Curve curve in curveList) { curves.Append(curve); } if (!GeomUtil.IsRectangular(curves)) { return(false); } return(true); }
public static bool UpdateZones(this TBD.Building building, AnalyticalModel analyticalModel, bool includeHDD = false) { if (analyticalModel == null || building == null) { return(false); } building.name = analyticalModel.Name; return(UpdateZones(building, analyticalModel?.AdjacencyCluster, analyticalModel.ProfileLibrary, includeHDD)); }
static Transform _t = Transform.CreateTranslation(_offset); // 2014 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; List <Element> walls = new List <Element>(); if (!Util.GetSelectedElementsOrAll( walls, uidoc, typeof(Wall))) { Selection sel = uidoc.Selection; //message = ( 0 < sel.Elements.Size ) // 2014 message = (0 < sel.GetElementIds().Count) // 2015 ? "Please select some wall elements." : "No wall elements found."; return(Result.Failed); } using (Transaction tx = new Transaction(doc)) { tx.Start("Create model curve copies of analytical model curves"); Creator creator = new Creator(doc); foreach (Wall wall in walls) { AnalyticalModel am = wall.GetAnalyticalModel(); foreach (AnalyticalCurveType ct in _curveTypes) { IList <Curve> curves = am.GetCurves(ct); int n = curves.Count; Debug.Print("{0} {1} curve{2}.", n, ct, Util.PluralSuffix(n)); foreach (Curve curve in curves) { //creator.CreateModelCurve( curve.get_Transformed( _t ) ); // 2013 creator.CreateModelCurve(curve.CreateTransformed(_t)); // 2014 } } } tx.Commit(); } return(Result.Succeeded); }
/// <summary> /// Get a floor's profile. /// </summary> /// <param name="floor">The floor whose profile you want to get.</param> /// <returns>The profile of the floor.</returns> private CurveArray GetFloorProfile(Floor floor) { CurveArray floorProfile = new CurveArray(); // Structural slab's profile can be found in it's AnalyticalModel. if (null != floor.GetAnalyticalModel()) { AnalyticalModel analyticalModel = floor.GetAnalyticalModel(); IList <Curve> curveList = analyticalModel.GetCurves(AnalyticalCurveType.ActiveCurves); for (int i = 0; i < curveList.Count; i++) { floorProfile.Append(curveList[i]); } return(floorProfile); } // Nonstructural floor's profile can be formed through it's Geometry. Options aOptions = m_revit.Application.Create.NewGeometryOptions(); Autodesk.Revit.DB.GeometryElement aElementOfGeometry = floor.get_Geometry(aOptions); //GeometryObjectArray geometryObjects = aElementOfGeometry.Objects; IEnumerator <GeometryObject> Objects = aElementOfGeometry.GetEnumerator(); //foreach (GeometryObject o in geometryObjects) while (Objects.MoveNext()) { GeometryObject o = Objects.Current; Solid solid = o as Solid; if (null == solid) { continue; } // Form the floor's profile through solid's edges. EdgeArray edges = solid.Edges; for (int i = 0; i < (edges.Size) / 3; i++) { Edge edge = edges.get_Item(i); List <XYZ> xyzArray = edge.Tessellate() as List <XYZ>; // A set of points. for (int j = 0; j < (xyzArray.Count - 1); j++) { Autodesk.Revit.DB.XYZ startPoint = xyzArray[j]; Autodesk.Revit.DB.XYZ endPoint = xyzArray[j + 1]; Line line = Line.CreateBound(startPoint, endPoint); floorProfile.Append(line); } } } return(floorProfile); }
/// <summary> /// Run this sample /// </summary> public void Run() { try { //iterate through the selection picking out family instances that have a 3D analytical model ICollection <ElementId> selElements = m_doc.Selection.GetElementIds(); if (0 == selElements.Count) { MessageBox.Show("Please selected some in-place family instance with AnalyticalMode.", "InplaceFamilyAnalyticalModel3D"); return; } foreach (Autodesk.Revit.DB.ElementId elementid in selElements) { FamilyInstance familyInstance = m_doc.Document.GetElement(elementid) as FamilyInstance; if (null == familyInstance) { MessageBox.Show("This macro depends on Revit Structure to function properly. Please open this document in Revit Structure to run this macro.", "InplaceFamilyAnaliticalModel3D"); continue; } AnalyticalModel analyticalModel = familyInstance.GetAnalyticalModel(); if (null == analyticalModel) { MessageBox.Show("This macro depends on Revit Structure to function properly. Please open this document in Revit Structure to run this macro.", "InplaceFamilyAnaliticalModel3D"); continue; } AnalyticalModel analyticalModel3D = analyticalModel as AnalyticalModel; if (null == analyticalModel3D) { MessageBox.Show("we should select analytical model 3D family instance, but this familyInstance.AnalyticalModel type is " + analyticalModel.GetType().Name, "InplaceFamilyAnaliticalModel3D"); continue; } //Output the family instance information and the curves of the analytical model. DumpFamilyInstance(familyInstance); DumpAnalyticalModel3D(analyticalModel3D); MessageBox.Show(m_message, "InplaceFamilyAnaliticalModel3D"); } } catch (Exception ee) { MessageBox.Show(ee.ToString()); } return; }
CollectEvent(object sender, CollectorEventArgs e) { // cast the sender object to the SnoopCollector we are expecting Collector snoopCollector = sender as Collector; if (snoopCollector == null) { Debug.Assert(false); // why did someone else send us the message? return; } // see if it is a type we are responsible for AnalyticalModel aModel = e.ObjToSnoop as AnalyticalModel; if (aModel != null) { Stream(snoopCollector.Data(), aModel); return; } CompoundStructure compStruct = e.ObjToSnoop as CompoundStructure; if (compStruct != null) { Stream(snoopCollector.Data(), compStruct); return; } CompoundStructureLayer compStructLayer = e.ObjToSnoop as CompoundStructureLayer; if (compStructLayer != null) { Stream(snoopCollector.Data(), compStructLayer); return; } AnalyticalModelSupport supportData = e.ObjToSnoop as AnalyticalModelSupport; if (supportData != null) { Stream(snoopCollector.Data(), supportData); return; } RebarInSystem barDesc = e.ObjToSnoop as RebarInSystem; if (barDesc != null) { Stream(snoopCollector.Data(), barDesc); return; } }
/// <summary> /// create GraphicsData of give AnalyticalModel /// </summary> /// <param name="model">AnalyticalModel contains geometry data</param> /// <returns>A graphics data object appropriate for GDI.</returns> private void GetModelData(AnalyticalModel model) { foreach (Curve curve in model.GetCurves(AnalyticalCurveType.RawCurves)) { try { m_curve3Ds.Add(curve.Tessellate() as List <XYZ>); } catch { } } }
/// <summary> /// Creates maps based on surface results. The maps can be displayed in the documentation. /// </summary> /// <param name="element">Revit element for which result document is built</param> /// <param name="resultsInPoints">Result in point collection</param> /// <param name="resultTypes">The type of results, values and description that can be displayed on the maps.</param> /// <returns>Returns list of documets maps based on results that can be displayed in the documentation</returns> private List <DocumentMap> CreateResultMapSeriesForSurfaceElements(Element element, ICollection <ResultInPointSurface> resultsInPoints, IEnumerable <Tuple <ResultTypeSurface, string> > resultTypes) { List <DocumentMap> vDocMap = new List <DocumentMap>(); MapDataGenerator mapPoints = new MapDataGenerator(); foreach (Tuple <ResultTypeSurface, string> forceDesc in resultTypes) { List <double> resData = resultsInPoints.Select(s => s[forceDesc.Item1]).ToList(); if (resData.Max(s => (Math.Abs(s))) < 1.0e-8) { continue; } AnalyticalModel slab = element as AnalyticalModel; DisplayUnit displayUnit = DisplayUnit.IMPERIAL; if (Server.UnitSystem == Autodesk.Revit.DB.ResultsBuilder.UnitsSystem.Metric) { displayUnit = DisplayUnit.METRIC; } ElementAnalyser elementAnalyser = new ElementAnalyser(displayUnit); ElementInfo info = elementAnalyser.Analyse(element); XYZ xyz = new XYZ(); if (info != null) { foreach (ResultInPointSurface resInPt in resultsInPoints) { mapPoints.AddPoint(new XYZ(resInPt[ResultTypeSurface.X], resInPt[ResultTypeSurface.Y], resInPt[ResultTypeSurface.Z]), resInPt[forceDesc.Item1]); } var contourAndHoles = getContourAndHolePoints(info); contourAndHoles.Item1.ForEach(s => mapPoints.AddPointToContour(s)); contourAndHoles.Item2.ForEach(s => mapPoints.AddHole(s)); UnitType ut = forceDesc.Item1.GetUnitType(); DocumentMap docMap = new DocumentMap(ut, UnitsConverter.GetInternalUnit(ut)); docMap.Title = forceDesc.Item2; int nofPoints = mapPoints.Count; for (int ptId = 0; ptId < nofPoints; ptId++) { UV pt = mapPoints.GetPoint(ptId); docMap.AddPoint(pt.U, pt.V, mapPoints.GetValue(ptId)); } List <List <int> > holes = mapPoints.Holes; foreach (List <int> hole in holes) { docMap.AddHole(hole); } docMap.DefineContour(mapPoints.Contour); vDocMap.Add(docMap); } mapPoints.Clear(); } return(vDocMap); }
/// <summary> /// Generate a Transform instance which as Transform property of BoundingBoxXYZ, /// when the user select a beam, this method will be called /// </summary> /// <returns>the reference of Transform, return null if it can't be generated</returns> Transform GenerateBeamTransform() { Transform transform = null; FamilyInstance instance = m_currentComponent as FamilyInstance; // First check whether the beam is horizontal. // In order to predigest the calculation, only allow it to be horizontal double startOffset = instance.get_Parameter(BuiltInParameter.STRUCTURAL_BEAM_END0_ELEVATION).AsDouble(); double endOffset = instance.get_Parameter(BuiltInParameter.STRUCTURAL_BEAM_END1_ELEVATION).AsDouble(); if (-PRECISION > startOffset - endOffset || PRECISION < startOffset - endOffset) { m_errorInformation = "Please select a horizontal beam."; return(transform); } // Second get the Analytical Model line. AnalyticalModel model = instance.GetAnalyticalModel(); if (null == model) { m_errorInformation = "The selected beam doesn't have Analytical Model line."; return(transform); } Curve curve = model.GetCurve(); if (null == curve) { m_errorInformation = "The program should never go here."; return(transform); } // Now I am sure I can create a transform instance. transform = Transform.Identity; // Third find the middle point of the line and set it as Origin property. Autodesk.Revit.DB.XYZ startPoint = curve.GetEndPoint(0); Autodesk.Revit.DB.XYZ endPoint = curve.GetEndPoint(1); Autodesk.Revit.DB.XYZ midPoint = XYZMath.FindMidPoint(startPoint, endPoint); transform.Origin = midPoint; // At last find out the directions of the created view, and set it as Basis property. Autodesk.Revit.DB.XYZ basisZ = XYZMath.FindDirection(startPoint, endPoint); Autodesk.Revit.DB.XYZ basisX = XYZMath.FindRightDirection(basisZ); Autodesk.Revit.DB.XYZ basisY = XYZMath.FindUpDirection(basisZ); transform.set_Basis(0, basisX); transform.set_Basis(1, basisY); transform.set_Basis(2, basisZ); return(transform); }
// works in Revit Structure 2010 API, but not in 2011: // works in Revit Structure, but not in other flavours of Revit: bool ContainsArc( AnalyticalModel a ) { bool rc = false; AnalyticalModel amp = a.Profile; Profile p = amp.SweptProfile; foreach( Curve c in p.Curves ) { if( c is Arc ) { rc = true; break; } } return rc; }
Stream(ArrayList data, AnalyticalModel aModel) { data.Add(new Snoop.Data.ClassSeparator(typeof(AnalyticalModel))); try { data.Add(new Snoop.Data.Object("GetCurve", aModel.GetCurve())); } catch (System.Exception ex){ data.Add(new Snoop.Data.Exception("GetCurve", ex)); } data.Add(new Snoop.Data.Enumerable("GetCurves", aModel.GetCurves(AnalyticalCurveType.ActiveCurves))); try { data.Add(new Snoop.Data.Xyz("GetPoint", aModel.GetPoint())); } catch (System.Exception ex){ data.Add(new Snoop.Data.Exception("GetPoint", ex)); } data.Add(new Snoop.Data.Enumerable("GetAnalyticalModelSupports", aModel.GetAnalyticalModelSupports())); }
/// <summary> /// create GraphicsData of give AnalyticalModel /// </summary> /// <param name="model">AnalyticalModel contains geometry data</param> /// <returns>A graphics data object appropriate for GDI.</returns> private void GetModelData(AnalyticalModel model) { foreach (Curve curve in model.GetCurves(AnalyticalCurveType.RawCurves)) { try { m_curve3Ds.Add(curve.Tessellate() as List<XYZ>); } catch { } } }
/// <summary> /// Search for the In-Place family instance's properties data to be listed /// and graphics data to be drawn. /// </summary> /// <param name="inPlaceMember">properties data to be listed</param> /// <param name="model">graphics data to be draw</param> /// <returns>Returns true if retrieved this data</returns> private bool PrepareData(ref FamilyInstance inPlaceMember, ref AnalyticalModel model) { ElementSet selected = m_commandData.Application.ActiveUIDocument.Selection.Elements; if (selected.Size != 1) { return false; } foreach (object o in selected) { inPlaceMember = o as FamilyInstance; if (null == inPlaceMember) { return false; } } model = inPlaceMember.GetAnalyticalModel(); if (null==model) { return false; } return true; }
/// <summary> /// get element's support information /// </summary> /// <param name="analyticalModel"> element's analytical model</param> /// <returns></returns> private string[] GetSupportInformation(AnalyticalModel analyticalModel) { // supportInformation[0] store supportType // supportInformation[1] store other informations string[] supportInformations = new string[2] { "", "" }; IList<AnalyticalModelSupport> supports = analyticalModel.GetAnalyticalModelSupports(); // "Supported" flag indicates if the Element is completely supported. // AnalyticalModel Support list keeps track of all supports. if (!analyticalModel.IsElementFullySupported())// judge if supported { if (0 == supports.Count) { supportInformations[0] = "not supported"; } else { foreach (AnalyticalModelSupport support in supports) { supportInformations[0] = supportInformations[0] + support.GetSupportType().ToString() + ", "; } } } else { if (0 == supports.Count) { supportInformations[1] = "supported but no more information"; } else { foreach (AnalyticalModelSupport support in supports) { supportInformations[0] = supportInformations[0] + support.GetSupportType().ToString() + ", "; } } } return supportInformations; }
private void Stream(ArrayList data, AnalyticalModel aModel) { data.Add(new Snoop.Data.ClassSeparator(typeof(AnalyticalModel))); try { data.Add(new Snoop.Data.Object("GetCurve", aModel.GetCurve())); } catch (System.Exception ex){ data.Add(new Snoop.Data.Exception("GetCurve", ex)); } data.Add(new Snoop.Data.Enumerable("GetCurves", aModel.GetCurves(AnalyticalCurveType.ActiveCurves))); try { data.Add(new Snoop.Data.Xyz("GetPoint", aModel.GetPoint())); } catch (System.Exception ex){ data.Add(new Snoop.Data.Exception("GetPoint", ex)); } data.Add(new Snoop.Data.Enumerable("GetAnalyticalModelSupports", aModel.GetAnalyticalModelSupports())); data.Add(new Snoop.Data.Bool("CanApproximate", aModel.CanApproximate())); //data.Add(new Snoop.Data.Bool("CanDisable", aModel.CanDisable())); //data.Add(new Snoop.Data.Bool("CanDisableAutoDetect", aModel.CanDisableAutoDetect())); data.Add(new Snoop.Data.Bool("CanHaveRigidLinks", aModel.CanHaveRigidLinks())); //TF data.Add(new Snoop.Data.Bool("CanSetAnalyticalOffset", aModel.CanSetAnalyticalOffset())); data.Add(new Snoop.Data.Bool("CanUseHardPoints", aModel.CanUseHardPoints())); data.Add(new Snoop.Data.Enumerable("Analytical Model Supports", aModel.GetAnalyticalModelSupports())); data.Add(new Snoop.Data.Object("Analyze As", aModel.GetAnalyzeAs())); try { data.Add(new Snoop.Data.Xyz("Offset EndOrTop", aModel.GetOffset(AnalyticalElementSelector.EndOrTop))); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("Offset EndOrTop", ex)); } try { data.Add(new Snoop.Data.Xyz("Offset StartOrBase", aModel.GetOffset(AnalyticalElementSelector.StartOrBase))); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("Offset StartOrBase", ex)); } try { data.Add(new Snoop.Data.Xyz("Offset Whole", aModel.GetOffset(AnalyticalElementSelector.Whole))); } catch (System.Exception ex) { data.Add(new Snoop.Data.Exception("Offset Whole", ex)); } /* TF if (aModel.HasSweptProfile()) data.Add(new Snoop.Data.Object("Swept profile", aModel.GetSweptProfile())); else data.Add(new Snoop.Data.String("Swept profile", "No swept profile.")); */ if (aModel is AnalyticalModelSurface) Stream(data, (AnalyticalModelSurface)aModel); if (aModel is AnalyticalModelStick) Stream(data, (AnalyticalModelStick)aModel); }