/// <summary> /// Creates an Analytiocal Panel /// </summary> /// <param name="revitDoc">Revit documenr</param> /// <returns></returns> public static AnalyticalPanel CreateAMPanel(Document revitDoc) { AnalyticalPanel analyticalPanel = null; using (Transaction transaction = new Transaction(revitDoc, "Create Analytical Panel")) { transaction.Start(); //create curveloop which will be assigned to the analytical panel CurveLoop profileloop = new CurveLoop(); profileloop.Append(Line.CreateBound( new XYZ(0, 0, 0), new XYZ(5, 0, 0))); profileloop.Append(Line.CreateBound( new XYZ(5, 0, 0), new XYZ(5, 5, 0))); profileloop.Append(Line.CreateBound( new XYZ(5, 5, 0), new XYZ(0, 5, 0))); profileloop.Append(Line.CreateBound( new XYZ(0, 5, 0), new XYZ(0, 0, 0))); //create the AnalyticalPanel analyticalPanel = AnalyticalPanel.Create(revitDoc, profileloop); analyticalPanel.StructuralRole = AnalyticalStructuralRole.StructuralRoleFloor; analyticalPanel.AnalyzeAs = AnalyzeAs.SlabOneWay; transaction.Commit(); } return(analyticalPanel); }
/// <summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="commandData">An object that is passed to the external application /// which contains data related to the command, /// such as the application object and active view.</param> /// <param name="message">A message that can be set by the external application /// which will be displayed if a failure or cancellation is returned by /// the external command.</param> /// <param name="elements">A set of elements to which the external application /// can add elements that are to be highlighted in case of failure or cancellation.</param> /// <returns>Return the status of the external command. /// A result of Succeeded means that the API external method functioned as expected. /// Cancelled can be used to signify that the user cancelled the external operation /// at some point. Failure should be returned if the application is unable to proceed with /// the operation.</returns> public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { //Expected results: The Analytical Panel has been moved and the connection with the Analytical Member was kept try { // Get the Document Document document = commandData.Application.ActiveUIDocument.Document; // Create Analytical Panel AnalyticalPanel analyticalPanel = CreateAnalyticalPanel.CreateAMPanel(document); // Create an Analytical Member connected with the Analytical Panel above AnalyticalMember analyticalMember = CreateAnalyticalMember.CreateMember(document); // Move the Analytical Panel using ElementTransformUtils using (Transaction transaction = new Transaction(document, "Move panel with ElementTransformUtils")) { transaction.Start(); ElementTransformUtils.MoveElement(document, analyticalPanel.Id, new XYZ(5, 5, 0)); transaction.Commit(); } return(Result.Succeeded); } catch (Exception ex) { message = ex.Message; return(Result.Failed); } }
/// <summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="commandData">An object that is passed to the external application /// which contains data related to the command, /// such as the application object and active view.</param> /// <param name="message">A message that can be set by the external application /// which will be displayed if a failure or cancellation is returned by /// the external command.</param> /// <param name="elements">A set of elements to which the external application /// can add elements that are to be highlighted in case of failure or cancellation.</param> /// <returns>Return the status of the external command. /// A result of Succeeded means that the API external method functioned as expected. /// Cancelled can be used to signify that the user cancelled the external operation /// at some point. Failure should be returned if the application is unable to proceed with /// the operation.</returns> public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { //Expected results: The Analytical Node has been moved and the connection has been kept try { // Get the Document UIDocument activeDoc = commandData.Application.ActiveUIDocument; Autodesk.Revit.DB.Document document = activeDoc.Document; // Create Analytical Panel AnalyticalPanel analyticalPanel = CreateAnalyticalPanel.CreateAMPanel(document); // Create the connected Analytical Member AnalyticalMember analyticalMember = CreateAnalyticalMember.CreateMember(document); // Select the node Reference eRef = activeDoc.Selection.PickObject(ObjectType.PointOnElement, "Select an Analytical Node"); // Move the Analytical Panel using ElementTransformUtils using (Transaction transaction = new Transaction(document, "Move panel with ElementTransformUtils")) { transaction.Start(); ElementTransformUtils.MoveElement(document, eRef.ElementId, new XYZ(-5, -5, 0)); transaction.Commit(); } return(Result.Succeeded); } catch (Exception ex) { message = ex.Message; return(Result.Failed); } }
/// <summary> /// Generate a Transform instance which as Transform property of BoundingBoxXYZ, /// when the user select a floor, this method will be called /// </summary> /// <returns>the reference of Transform, return null if it can't be generated</returns> Transform GenerateFloorTransform() { Transform transform = null; Floor floor = m_currentComponent as Floor; // First get the Analytical Model lines AnalyticalPanel model = null; Document document = floor.Document; AnalyticalToPhysicalAssociationManager assocManager = AnalyticalToPhysicalAssociationManager.GetAnalyticalToPhysicalAssociationManager(document); if (assocManager != null) { ElementId associatedElementId = assocManager.GetAssociatedElementId(floor.Id); if (associatedElementId != ElementId.InvalidElementId) { Element associatedElement = document.GetElement(associatedElementId); if (associatedElement != null && associatedElement is AnalyticalPanel) { model = associatedElement as AnalyticalPanel; } } } if (null == model) { m_errorInformation = "Please select a structural floor."; return(transform); } CurveArray curves = m_project.Document.Application.Create.NewCurveArray(); IList <Curve> curveList = model.GetOuterContour().ToList(); foreach (Curve curve in curveList) { curves.Append(curve); } if (null == curves || true == curves.IsEmpty) { 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 floor and set it as Origin property. Autodesk.Revit.DB.XYZ midPoint = XYZMath.FindMiddlePoint(curves); 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.FindFloorViewDirection(curves); 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); }
/// <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 //check the analytical model profile is rectangular Document document = floor.Document; AnalyticalToPhysicalAssociationManager assocManager = AnalyticalToPhysicalAssociationManager.GetAnalyticalToPhysicalAssociationManager(document); AnalyticalPanel model = null; if (assocManager != null) { ElementId associatedElementId = assocManager.GetAssociatedElementId(floor.Id); if (associatedElementId != ElementId.InvalidElementId) { Element associatedElement = document.GetElement(associatedElementId); if (associatedElement != null && associatedElement is AnalyticalPanel) { model = associatedElement as AnalyticalPanel; } } } if (null == model) { return(false); } curves = model.GetOuterContour().ToList(); if (!GeomUtil.IsRectangular(curves)) { return(false); } return(true); }
public virtual Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { Document document = commandData.Application.ActiveUIDocument.Document; //create analytical panel AnalyticalPanel analyticalPanel = CreateAnalyticalPanel.CreateAMPanel(document); if (analyticalPanel != null) { using (Transaction transaction = new Transaction(document, "Edit Analytical Panel outer contour")) { transaction.Start(); //create a new curve loop CurveLoop profileloop = new CurveLoop(); profileloop.Append(Line.CreateBound( new XYZ(0, 0, 0), new XYZ(5, 0, 0))); profileloop.Append(Line.CreateBound( new XYZ(5, 0, 0), new XYZ(5, 5, 0))); profileloop.Append(Line.CreateBound( new XYZ(5, 5, 0), new XYZ(-2, 5, 0))); profileloop.Append(Line.CreateBound( new XYZ(-2, 5, 0), new XYZ(0, 0, 0))); //Sets the new contour for analytical panel analyticalPanel.SetOuterContour(profileloop); transaction.Commit(); } } return(Result.Succeeded); } catch (Exception ex) { message = ex.Message; return(Result.Failed); } }
/// <summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="commandData">An object that is passed to the external application /// which contains data related to the command, /// such as the application object and active view.</param> /// <param name="message">A message that can be set by the external application /// which will be displayed if a failure or cancellation is returned by /// the external command.</param> /// <param name="elements">A set of elements to which the external application /// can add elements that are to be highlighted in case of failure or cancellation.</param> /// <returns>Return the status of the external command. /// A result of Succeeded means that the API external method functioned as expected. /// Cancelled can be used to signify that the user cancelled the external operation /// at some point. Failure should be returned if the application is unable to proceed with /// the operation.</returns> public virtual Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { Document document = commandData.Application.ActiveUIDocument.Document; //create analytical panel AnalyticalPanel analyticalPanel = CreateAMPanel(document); if (analyticalPanel != null) { //create analytical opening on the panel we've just created CreateAMOpening(document, analyticalPanel.Id); } return(Result.Succeeded); } catch (Exception ex) { message = ex.Message; return(Result.Failed); } }
/// <summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="commandData">An object that is passed to the external application /// which contains data related to the command, /// such as the application object and active view.</param> /// <param name="message">A message that can be set by the external application /// which will be displayed if a failure or cancellation is returned by /// the external command.</param> /// <param name="elements">A set of elements to which the external application /// can add elements that are to be highlighted in case of failure or cancellation.</param> /// <returns>Return the status of the external command. /// A result of Succeeded means that the API external method functioned as expected. /// Cancelled can be used to signify that the user cancelled the external operation /// at some point. Failure should be returned if the application is unable to proceed with /// the operation.</returns> public virtual Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { try { Document document = commandData.Application.ActiveUIDocument.Document; //create analytical panel AnalyticalPanel analyticalPanel = CreateAnalyticalPanel.CreateAMPanel(document); if (analyticalPanel != null) { // Start a sketch edit scope SketchEditScope sketchEditScope = new SketchEditScope(document, "Replace line with an arc"); sketchEditScope.StartWithNewSketch(analyticalPanel.Id); using (Transaction transaction = new Transaction(document, "Modify sketch")) { transaction.Start(); //replace a boundary line with an arc Line line = null; Sketch sketch = document.GetElement(analyticalPanel.SketchId) as Sketch; if (sketch != null) { foreach (CurveArray curveArray in sketch.Profile) { foreach (Curve curve in curveArray) { line = curve as Line; if (line != null) { break; } } if (line != null) { break; } } } // Create arc XYZ normal = line.Direction.CrossProduct(XYZ.BasisZ).Normalize().Negate(); XYZ middle = line.GetEndPoint(0).Add(line.Direction.Multiply(line.Length / 2)); Curve arc = Arc.Create(line.GetEndPoint(0), line.GetEndPoint(1), middle.Add(normal.Multiply(20))); // Remove element referenced by the found line. document.Delete(line.Reference.ElementId); // Model curve creation automatically puts the curve into the sketch, if sketch edit scope is running. document.Create.NewModelCurve(arc, sketch.SketchPlane); transaction.Commit(); } sketchEditScope.Commit(new FailurePreproccessor()); } return(Result.Succeeded); } catch (Exception ex) { message = ex.Message; return(Result.Failed); } }
/// <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 IList <Curve> 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 Document document = wall.Document; AnalyticalToPhysicalAssociationManager assocManager = AnalyticalToPhysicalAssociationManager.GetAnalyticalToPhysicalAssociationManager(document); AnalyticalPanel model = null; if (assocManager != null) { ElementId associatedElementId = assocManager.GetAssociatedElementId(wall.Id); if (associatedElementId != ElementId.InvalidElementId) { Element associatedElement = document.GetElement(associatedElementId); if (associatedElement != null && associatedElement is AnalyticalPanel) { model = associatedElement as AnalyticalPanel; } } } if (null == model) { return(false); } curves = model.GetOuterContour().ToList(); if (!GeomUtil.IsRectangular(curves)) { return(false); } return(true); }
/// <summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="commandData">An object that is passed to the external application /// which contains data related to the command, /// such as the application object and active view.</param> /// <param name="message">A message that can be set by the external application /// which will be displayed if a failure or cancellation is returned by /// the external command.</param> /// <param name="elements">A set of elements to which the external application /// can add elements that are to be highlighted in case of failure or cancellation.</param> /// <returns>Return the status of the external command. /// A result of Succeeded means that the API external method functioned as expected. /// Cancelled can be used to signify that the user cancelled the external operation /// at some point. Failure should be returned if the application is unable to proceed with /// the operation.</returns> public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { //Expected results: the Analytical Panel has been moved and the connection with the Analytical Member has been broken try { //Get the Document Document document = commandData.Application.ActiveUIDocument.Document; // Create Analytical Panel AnalyticalPanel analyticalPanel = CreateAnalyticalPanel.CreateAMPanel(document); // Create an Analytical Member connected with the Analytical Panel above AnalyticalMember analyticalMember = CreateAnalyticalMember.CreateMember(document); // Move the Analytical Panel using SketchEditScope SketchEditScope sketchEditScope = new SketchEditScope(document, "Move panel with SketchEditScope"); sketchEditScope.StartWithNewSketch(analyticalPanel.Id); // Start transaction using (Transaction transaction = new Transaction(document, "Offset panel")) { transaction.Start(); // Get Sketch if (document.GetElement(analyticalPanel.SketchId) is Sketch sketch) { foreach (CurveArray curveArray in sketch.Profile) { // Iterate through the Curves forming the Analytical Panel and // create new ones with a slight offset from the original ones before deleting them foreach (Curve curve in curveArray) { Line line = curve as Line; if (line != null) { // Create new offseted Start and End points from the original line coordinates double offset = 5.0; XYZ newLineStart = new XYZ(line.GetEndPoint(0).X + offset, line.GetEndPoint(0).Y + offset, 0); XYZ newLineEnd = new XYZ(line.GetEndPoint(1).X + offset, line.GetEndPoint(1).Y + offset, 0); // Define the new line with offseted coordinates Curve offsetedLine = Line.CreateBound(newLineStart, newLineEnd); // Remove the old line document.Delete(line.Reference.ElementId); // Create the new line document.Create.NewModelCurve(offsetedLine, sketch.SketchPlane); } } } } transaction.Commit(); } sketchEditScope.Commit(new FailurePreproccessor()); return(Result.Succeeded); } catch (Exception ex) { message = ex.Message; return(Result.Failed); } }
/// <summary> /// find out every wall in the selection and add a dimension from the start of the wall to its end /// </summary> /// <returns>if add successfully, true will be returned, else false will be returned</returns> public bool AddDimension() { if (!initialize()) { return false; } Transaction transaction = new Transaction(m_revit.Application.ActiveUIDocument.Document, "Add Dimensions"); transaction.Start(); //get out all the walls in this array, and create a dimension from its start to its end for (int i = 0; i < m_walls.Count; i++) { Wall wallTemp = m_walls[i] as Wall; if (null == wallTemp) { continue; } //get location curve Location location = wallTemp.Location; LocationCurve locationline = location as LocationCurve; if (null == locationline) { continue; } //New Line Line newLine = null; //get reference ReferenceArray referenceArray = new ReferenceArray(); AnalyticalPanel analyticalModel = null; Document document = wallTemp.Document; AnalyticalToPhysicalAssociationManager assocManager = AnalyticalToPhysicalAssociationManager.GetAnalyticalToPhysicalAssociationManager(document); if (assocManager != null) { ElementId associatedElementId = assocManager.GetAssociatedElementId(wallTemp.Id); if (associatedElementId != ElementId.InvalidElementId) { Element associatedElement = document.GetElement(associatedElementId); if (associatedElement != null && associatedElement is AnalyticalPanel) { analyticalModel = associatedElement as AnalyticalPanel; } } } IList<Curve> activeCurveList = analyticalModel.GetOuterContour().ToList(); foreach (Curve aCurve in activeCurveList) { // find non-vertical curve from analytical model if (aCurve.GetEndPoint(0).Z == aCurve.GetEndPoint(1).Z) newLine = aCurve as Line; if (aCurve.GetEndPoint(0).Z != aCurve.GetEndPoint(1).Z) { AnalyticalModelSelector amSelector = new AnalyticalModelSelector(aCurve); amSelector.CurveSelector = AnalyticalCurveSelector.StartPoint; referenceArray.Append(analyticalModel.GetReference(amSelector)); } if (2 == referenceArray.Size) break; } if (referenceArray.Size != 2) { m_errorMessage += "Did not find two references"; return false; } try { //try to add new a dimension Autodesk.Revit.UI.UIApplication app = m_revit.Application; Document doc = app.ActiveUIDocument.Document; Autodesk.Revit.DB.XYZ p1 = new XYZ( newLine.GetEndPoint(0).X + 5, newLine.GetEndPoint(0).Y + 5, newLine.GetEndPoint(0).Z); Autodesk.Revit.DB.XYZ p2 = new XYZ( newLine.GetEndPoint(1).X + 5, newLine.GetEndPoint(1).Y + 5, newLine.GetEndPoint(1).Z); Line newLine2 = Line.CreateBound(p1, p2); Dimension newDimension = doc.Create.NewDimension( doc.ActiveView, newLine2, referenceArray); } // catch the exceptions catch (Exception ex) { m_errorMessage += ex.ToString(); return false; } } transaction.Commit(); return true; }
/// <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 analytical element. Document document = floor.Document; AnalyticalPanel analyticalModel = null; AnalyticalToPhysicalAssociationManager relManager = AnalyticalToPhysicalAssociationManager.GetAnalyticalToPhysicalAssociationManager(document); if (relManager != null) { ElementId associatedElementId = relManager.GetAssociatedElementId(floor.Id); if (associatedElementId != ElementId.InvalidElementId) { Element associatedElement = document.GetElement(associatedElementId); if (associatedElement != null && associatedElement is AnalyticalPanel) { analyticalModel = associatedElement as AnalyticalPanel; } } } if (null != analyticalModel) { IList <Curve> curveList = analyticalModel.GetOuterContour().ToList(); 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); }