/// <summary> /// Find the nearby walls on specific point and in specific height /// </summary> /// <param name="point">The given point</param> /// <param name="height">The given height</param> /// <param name="radius">The radius in which walls can be detected</param> /// <returns>The detection result</returns> private FilteredElementCollector nearbyWallsFilter(XYZ point, double height, double radius) { // build cylindrical shape around wall endpoint List <CurveLoop> curveloops = new List <CurveLoop>(); CurveLoop circle = new CurveLoop(); circle.Append(Arc.Create(point, radius , 0, Math.PI, XYZ.BasisX, XYZ.BasisY)); circle.Append(Arc.Create(point, radius , Math.PI, 2 * Math.PI, XYZ.BasisX, XYZ.BasisY)); curveloops.Add(circle); Solid wallEndCylinder = GeometryCreationUtilities.CreateExtrusionGeometry(curveloops, XYZ.BasisZ, height); // Iterate document to find walls FilteredElementCollector collector = new FilteredElementCollector(m_doc); collector.OfCategory(BuiltInCategory.OST_Walls); // Apply geometric filter ElementIntersectsSolidFilter testElementIntersectsSolidFilter = new ElementIntersectsSolidFilter(wallEndCylinder); collector.WherePasses(testElementIntersectsSolidFilter); return(collector); }
//Build solid public void incrementIntercetor(Document doc, XYZ startOfInterest, Parameter zOffsetVar, out ElementId columnId, out ElementId beamId) { columnId = null; beamId = null; double radius = 0; double limit = 0.75; double zOffset = zOffsetVar.AsDouble(); //lower arc center double centerZ = (startOfInterest.Z + zOffset) - 0.25; XYZ arcCenter = new XYZ(startOfInterest.X, startOfInterest.Y, centerZ); //Build a solid cylinder for (radius = .125; radius < limit; radius = radius + 0.1) { // Create a vertical half-circle loop in the frame location. List <CurveLoop> curveloops = new List <CurveLoop>(); CurveLoop circle = new CurveLoop(); circle.Append(Arc.Create(arcCenter, radius, 0, Math.PI, XYZ.BasisX, XYZ.BasisY)); circle.Append(Arc.Create(arcCenter, radius, Math.PI, 2 * Math.PI, XYZ.BasisX, XYZ.BasisY)); curveloops.Add(circle); Solid cylinder = GeometryCreationUtilities.CreateExtrusionGeometry(curveloops, XYZ.BasisZ, (0.25)); //PaintSolid(commandData, cylinder, 5); //Find column IEnumerable <Element> columns = new FilteredElementCollector(doc) .OfClass(typeof(FamilyInstance)) .OfCategory(BuiltInCategory.OST_StructuralColumns) .WherePasses(new ElementIntersectsSolidFilter(cylinder)); if (columns.Count() > 0) { foreach (Element e in columns) { FamilyInstance fi = e as FamilyInstance; FamilySymbol fs = fi.Symbol; columnId = e.Id; } break; } //Find beam IEnumerable <Element> beams = new FilteredElementCollector(doc) .OfClass(typeof(FamilyInstance)) .OfCategory(BuiltInCategory.OST_StructuralFraming) .WherePasses(new ElementIntersectsSolidFilter(cylinder)); if (beams.Count() > 0) { foreach (Element e in beams) { FamilyInstance fi = e as FamilyInstance; FamilySymbol fs = fi.Symbol; beamId = e.Id; } break; } } //End of loop }
internal static Solid CreateSolidFromBox(Autodesk.Revit.ApplicationServices.Application app, BoundingBoxXYZ box) { // create a set of curves from the base of the box. // presumes an untransformed box. XYZ A1 = box.Min; XYZ A2 = new XYZ(box.Max.X, box.Min.Y, box.Min.Z); XYZ A3 = new XYZ(box.Max.X, box.Max.Y, box.Min.Z); XYZ A4 = new XYZ(box.Min.X, box.Max.Y, box.Min.Z); List <Curve> crvs = new List <Curve>(); crvs.Add(Line.CreateBound(A1, A2)); crvs.Add(Line.CreateBound(A2, A3)); crvs.Add(Line.CreateBound(A3, A4)); crvs.Add(Line.CreateBound(A4, A1)); CurveLoop loop = CurveLoop.Create(crvs); List <CurveLoop> loops = new List <CurveLoop>() { loop }; Solid s = GeometryCreationUtilities.CreateExtrusionGeometry(loops, XYZ.BasisZ, (box.Max.Z - box.Min.Z)); return(s); }
public static Solid CreateSolidFromBoundingBox(Solid inputSolid) { BoundingBoxXYZ boundingBox = inputSolid.GetBoundingBox(); XYZ xyz = new XYZ(boundingBox.Min.X, boundingBox.Min.Y, boundingBox.Min.Z); XYZ xyz2 = new XYZ(boundingBox.Max.X, boundingBox.Min.Y, boundingBox.Min.Z); XYZ xyz3 = new XYZ(boundingBox.Max.X, boundingBox.Max.Y, boundingBox.Min.Z); XYZ xyz4 = new XYZ(boundingBox.Min.X, boundingBox.Max.Y, boundingBox.Min.Z); Line item = Line.CreateBound(xyz, xyz2); Line item2 = Line.CreateBound(xyz2, xyz3); Line item3 = Line.CreateBound(xyz3, xyz4); Line item4 = Line.CreateBound(xyz4, xyz); List <Curve> list = new List <Curve>(); list.Add(item); list.Add(item2); list.Add(item3); list.Add(item4); double num = boundingBox.Max.Z - boundingBox.Min.Z; CurveLoop item5 = CurveLoop.Create(list); Solid solid = GeometryCreationUtilities.CreateExtrusionGeometry(new List <CurveLoop> { item5 }, XYZ.BasisZ, num); return(SolidUtils.CreateTransformed(solid, boundingBox.Transform)); }
public Solid solidBoundingBox(Solid inputSolid) { BoundingBoxXYZ bbox = inputSolid.GetBoundingBox(); // corners in BBox coords XYZ pt0 = new XYZ(bbox.Min.X, bbox.Min.Y, bbox.Min.Z); XYZ pt1 = new XYZ(bbox.Max.X, bbox.Min.Y, bbox.Min.Z); XYZ pt2 = new XYZ(bbox.Max.X, bbox.Max.Y, bbox.Min.Z); XYZ pt3 = new XYZ(bbox.Min.X, bbox.Max.Y, bbox.Min.Z); //edges in BBox coords Line edge0 = Line.CreateBound(pt0, pt1); Line edge1 = Line.CreateBound(pt1, pt2); Line edge2 = Line.CreateBound(pt2, pt3); Line edge3 = Line.CreateBound(pt3, pt0); //create loop, still in BBox coords List <Curve> edges = new List <Curve>(); edges.Add(edge0); edges.Add(edge1); edges.Add(edge2); edges.Add(edge3); Double height = bbox.Max.Z - bbox.Min.Z; CurveLoop baseLoop = CurveLoop.Create(edges); List <CurveLoop> loopList = new List <CurveLoop>(); loopList.Add(baseLoop); Solid preTransformBox = GeometryCreationUtilities.CreateExtrusionGeometry(loopList, XYZ.BasisZ, height); Transform transform = bbox.Transform.ScaleBasis(1.01); Solid transformBox = SolidUtils.CreateTransformed(preTransformBox, transform); return(transformBox); }
public Solid GetSolidFromBoundingBoxXYZ(BoundingBoxXYZ bbox) { XYZ pt0 = new XYZ(bbox.Min.X, bbox.Min.Y, bbox.Min.Z); XYZ pt1 = new XYZ(bbox.Max.X, bbox.Min.Y, bbox.Min.Z); XYZ pt2 = new XYZ(bbox.Max.X, bbox.Max.Y, bbox.Min.Z); XYZ pt3 = new XYZ(bbox.Min.X, bbox.Max.Y, bbox.Min.Z); //edges in BBox coords Line edge0 = Line.CreateBound(pt0, pt1); Line edge1 = Line.CreateBound(pt1, pt2); Line edge2 = Line.CreateBound(pt2, pt3); Line edge3 = Line.CreateBound(pt3, pt0); //create loop, still in BBox coords List <Curve> edges = new List <Curve>(); edges.Add(edge0); edges.Add(edge1); edges.Add(edge2); edges.Add(edge3); Double height = bbox.Max.Z - bbox.Min.Z; CurveLoop baseLoop = CurveLoop.Create(edges); List <CurveLoop> loopList = new List <CurveLoop>(); loopList.Add(baseLoop); Solid preTransformBox = GeometryCreationUtilities.CreateExtrusionGeometry(loopList, XYZ.BasisZ, height); return(preTransformBox); }
public void solidBeamFinder(Document doc, XYZ startOfInterest, double solidHeight, out List <ElementId> beamIds) { beamIds = new List <ElementId>(); double radius = 0.1; XYZ arcCenter = new XYZ(startOfInterest.X, startOfInterest.Y, startOfInterest.Z); //Build a solid cylinder // Create a vertical half-circle loop in the frame location. List <CurveLoop> curveloops = new List <CurveLoop>(); CurveLoop circle = new CurveLoop(); circle.Append(Arc.Create(arcCenter, radius, 0, Math.PI, XYZ.BasisX, XYZ.BasisY)); circle.Append(Arc.Create(arcCenter, radius, Math.PI, 2 * Math.PI, XYZ.BasisX, XYZ.BasisY)); curveloops.Add(circle); Solid cylinder = GeometryCreationUtilities.CreateExtrusionGeometry(curveloops, XYZ.BasisZ, (solidHeight)); //PaintSolid(commandData, cylinder, 5); //Find beam IEnumerable <Element> beams = new FilteredElementCollector(doc) .OfClass(typeof(FamilyInstance)) .OfCategory(BuiltInCategory.OST_StructuralFraming) .WherePasses(new ElementIntersectsSolidFilter(cylinder)); if (beams.Count() > 0) { foreach (Element e in beams) { beamIds.Add(e.Id); } } }
public static Solid Box( ) { XYZ btmLeft = new XYZ(-0.5, -0.5, 0); XYZ topRight = new XYZ(0.5, 0.5, 0); XYZ btmRight = new XYZ(topRight.X, btmLeft.Y, 0); XYZ topLeft = new XYZ(btmLeft.X, topRight.Y, 0); Curve btm = Line.CreateBound(btmLeft, btmRight) as Curve; Curve right = Line.CreateBound(btmRight, topRight) as Curve; Curve top = Line.CreateBound(topRight, topLeft) as Curve; Curve left = Line.CreateBound(topLeft, btmLeft) as Curve; CurveLoop crvLoop = new CurveLoop(); crvLoop.Append(btm); crvLoop.Append(right); crvLoop.Append(top); crvLoop.Append(left); IList <CurveLoop> cl = new List <CurveLoop>(); cl.Add(crvLoop); Solid box = GeometryCreationUtilities.CreateExtrusionGeometry(cl, XYZ.BasisZ, 1); return(box); }
/// <summary> /// Create a centerbased box /// </summary> /// <param name="center">The given box center</param> /// <param name="edgelength">The given box's edge length</param> /// <returns>The created box</returns> public Solid CreateCenterbasedBox(XYZ center, double edgelength) { double halfedgelength = edgelength / 2.0; List <CurveLoop> profileloops = new List <CurveLoop>(); CurveLoop profileloop = new CurveLoop(); profileloop.Append(Line.CreateBound( new XYZ(center.X - halfedgelength, center.Y - halfedgelength, center.Z - halfedgelength), new XYZ(center.X - halfedgelength, center.Y + halfedgelength, center.Z - halfedgelength))); profileloop.Append(Line.CreateBound( new XYZ(center.X - halfedgelength, center.Y + halfedgelength, center.Z - halfedgelength), new XYZ(center.X + halfedgelength, center.Y + halfedgelength, center.Z - halfedgelength))); profileloop.Append(Line.CreateBound( new XYZ(center.X + halfedgelength, center.Y + halfedgelength, center.Z - halfedgelength), new XYZ(center.X + halfedgelength, center.Y - halfedgelength, center.Z - halfedgelength))); profileloop.Append(Line.CreateBound( new XYZ(center.X + halfedgelength, center.Y - halfedgelength, center.Z - halfedgelength), new XYZ(center.X - halfedgelength, center.Y - halfedgelength, center.Z - halfedgelength))); profileloops.Add(profileloop); XYZ extrusiondir = new XYZ(0, 0, 1); // orthogonal double extrusiondist = edgelength; return(GeometryCreationUtilities.CreateExtrusionGeometry(profileloops, extrusiondir, extrusiondist)); }
/// <summary> /// Create and return a rectangular prism of the /// given side lengths centered at the given point. /// </summary> static Solid CreateRectangularPrism( XYZ center, double d1, double d2, double d3) { List <Curve> profile = new List <Curve>(); XYZ profile00 = new XYZ(-d1 / 2, -d2 / 2, -d3 / 2); XYZ profile01 = new XYZ(-d1 / 2, d2 / 2, -d3 / 2); XYZ profile11 = new XYZ(d1 / 2, d2 / 2, -d3 / 2); XYZ profile10 = new XYZ(d1 / 2, -d2 / 2, -d3 / 2); profile.Add(Line.CreateBound(profile00, profile01)); profile.Add(Line.CreateBound(profile01, profile11)); profile.Add(Line.CreateBound(profile11, profile10)); profile.Add(Line.CreateBound(profile10, profile00)); CurveLoop curveLoop = CurveLoop.Create(profile); SolidOptions options = new SolidOptions( ElementId.InvalidElementId, ElementId.InvalidElementId); return(GeometryCreationUtilities .CreateExtrusionGeometry( new CurveLoop[] { curveLoop }, XYZ.BasisZ, d3, options)); }
/// <summary> /// 根据指定的平面与变换关系拉伸出一个实体 /// </summary> /// <param name="face"> </param> /// <param name="transform"> 将 face 对象 转换到模型空间中所需要进行的变换</param> /// <param name="thickNess"> 面层的厚度,单位为米 </param> /// <returns></returns> private Solid ExtrudeSolid(PlanarFace face, Transform transform, double thickNess) { Solid solid = null; IList <CurveLoop> curveLoops = face.GetEdgesAsCurveLoops(); //drawCurve(curveLoops); // 要在实体还未创建之前就定位好其在模型空间中的位置,因为后面要依据此位置来进行相交判断。 foreach (CurveLoop curveLoop in curveLoops) { curveLoop.Transform(transform); } //IList<CurveLoop> curveLoops; //CurvesFormator.GetContiguousCurvesFromEdgeArrArray(face.EdgeLoops, out curveLoops); XYZ extrusionDir = transform.OfVector(face.FaceNormal); solid = GeometryCreationUtilities.CreateExtrusionGeometry( profileLoops: curveLoops, extrusionDir: extrusionDir, extrusionDist: UnitUtils.ConvertToInternalUnits(thickNess, DisplayUnitType.DUT_METERS)); return(solid); }
// Token: 0x06000274 RID: 628 RVA: 0x00010210 File Offset: 0x0000E410 private Solid GetWCSSolid() { XYZ endPoint = this._curve.GetEndPoint(0); XYZ endPoint2 = this._curve.GetEndPoint(1); XYZ xyz = endPoint2 - endPoint; IList<CurveLoop> extrusionProfile = this.GetExtrusionProfile(xyz, endPoint); return GeometryCreationUtilities.CreateExtrusionGeometry(extrusionProfile, xyz, xyz.GetLength()); }
public bool CreateGeometry() { bool result = false; try { for (int i = 0; i < objMeshes.Count; i++) { ObjMesh mesh = objMeshes[i]; List <Curve> curveList = new List <Curve>(); ObjVertice startV = mesh.ObjVertex[mesh.ObjVertex.Count - 1]; ObjVertice endV = mesh.ObjVertex[0]; XYZ startPoint = new XYZ(startV.XValue, startV.YValue, startV.ZValue); XYZ endPoint = new XYZ(endV.XValue, endV.YValue, endV.ZValue); Line line = Line.CreateBound(startPoint, endPoint); curveList.Add(line); for (int j = 0; j < mesh.ObjVertex.Count - 1; j++) { startV = mesh.ObjVertex[j]; endV = mesh.ObjVertex[j + 1]; startPoint = new XYZ(startV.XValue, startV.YValue, startV.ZValue); endPoint = new XYZ(endV.XValue, endV.YValue, endV.ZValue); line = Line.CreateBound(startPoint, endPoint); curveList.Add(line); } CurveLoop curveLoop = CurveLoop.Create(curveList); List <CurveLoop> profile = new List <CurveLoop>(); profile.Add(curveLoop); Solid extrusion = GeometryCreationUtilities.CreateExtrusionGeometry(profile, new XYZ(0, 0, 1), 1); if (null != extrusion) { foreach (Face face in extrusion.Faces) { XYZ normal = face.ComputeNormal(new UV(0, 0)); if (normal.Z > 0) { displayingFaces.Add(face); break; } } } } result = true; } catch (Exception ex) { MessageBox.Show("Failed to create geometry for surfaces to be visulized with data.\n" + ex.Message, "Analysis Data Manager - Create Geometry", MessageBoxButtons.OK, MessageBoxIcon.Warning); result = false; } return(result); }
public static bool CreateAreaSolid(Document doc, AreaProperties ap, out MassProperties createdMass) { bool created = false; createdMass = null; try { string appGuid = doc.Application.ActiveAddInId.GetGUID().ToString(); if (null != ap.Linked3dMass) { //delete existing mass first MassProperties existingMass = ap.Linked3dMass; doc.Delete(new ElementId(existingMass.MassId)); } IList <GeometryObject> areaGeometries = new List <GeometryObject>(); if (ap.AreaProfile.Count > 0) { XYZ extrusionDir = new XYZ(0, 0, 1); Solid areaSolid = GeometryCreationUtilities.CreateExtrusionGeometry(ap.AreaProfile, extrusionDir, ap.UserHeight); if (null != areaSolid) { areaGeometries.Add(areaSolid); } } #if RELEASE2015 || RELEASE2016 DirectShape createdShape = DirectShape.CreateElement(doc, new ElementId(massCategory), appGuid, ap.AreaId.ToString()); #else DirectShape createdShape = DirectShape.CreateElement(doc, new ElementId(massCategory)); createdShape.ApplicationId = appGuid; createdShape.ApplicationDataId = ap.AreaId.ToString(); #endif #if RELEASE2016 DirectShapeOptions options = createdShape.GetOptions(); options.ReferencingOption = DirectShapeReferencingOption.Referenceable; createdShape.SetOptions(options); #endif createdShape.SetShape(areaGeometries); createdShape.SetName(ap.AreaName); Element massElement = doc.GetElement(createdShape.Id); if (null != massElement) { createdMass = new MassProperties(massElement); createdMass.SetHostInfo(ap.AreaUniqueId, SourceType.Areas, ap.AreaCenterPoint, ap.UserHeight); bool stored = MassDataStorageUtil.SetLinkedHostInfo(massElement, SourceType.Areas.ToString(), ap.AreaUniqueId, ap.AreaCenterPoint, ap.UserHeight); created = true; } } catch (Exception ex) { MessageBox.Show("Failed to create area solid.\n" + ex.Message, "Create Area Solid", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(created); }
private Solid FindCeilingSolid(Element ceiling) { Solid ceilingSolid = null; try { var opt = m_app.Application.Create.NewGeometryOptions(); opt.ComputeReferences = true; opt.IncludeNonVisibleObjects = true; var geomElem = ceiling.get_Geometry(opt); foreach (var obj in geomElem) { var solid = obj as Solid; if (null != solid) { if (solid.Volume > 0) { ceilingSolid = solid; break; } else { var curveLoopList = new List <CurveLoop>(); XYZ normal = null; foreach (Face face in solid.Faces) { if (face.EdgeLoops.Size > 0) { normal = face.ComputeNormal(new UV(0, 0)); foreach (EdgeArray edgeArray in face.EdgeLoops) { var curveLoop = new CurveLoop(); foreach (Edge edge in edgeArray) { curveLoop.Append(edge.AsCurve()); } curveLoopList.Add(curveLoop); } } } var extrusion = GeometryCreationUtilities.CreateExtrusionGeometry(curveLoopList, normal, 1); if (extrusion.Volume > 0) { ceilingSolid = extrusion; break; } } } } } catch (Exception ex) { MessageBox.Show("Could not find the solid of the ceiling.\n" + ex.Message, "FindCeilingSolid", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(ceilingSolid); }
XYZ Createsolid(Document doc, IList <CurveLoop> looplist) { View view = doc.ActiveView; XYZ point = view.ViewDirection; Solid solid = GeometryCreationUtilities.CreateExtrusionGeometry(looplist, point, 0.1); XYZ center = solid.ComputeCentroid(); return(center); }
public static Face CreateFacebyFMEData(List <FMEArea> fmeAreaList) { Face faceCreated = null; try { List <CurveLoop> curveLoopList = new List <CurveLoop>(); foreach (FMEArea fmeArea in fmeAreaList) { List <XYZ> pointList = new List <XYZ>(); string[] points = fmeArea.Coordinates.Split(' '); foreach (string point in points) { string[] coordinates = point.Split(','); if (coordinates.Length == 3) { XYZ xyz = new XYZ(double.Parse(coordinates[0]), double.Parse(coordinates[1]), double.Parse(coordinates[2])); pointList.Add(xyz); } } if (pointList.Count > 0) { List <Curve> curveList = new List <Curve>(); for (int i = 0; i < pointList.Count - 1; i++) { Line line = Line.CreateBound(pointList[i], pointList[i + 1]); curveList.Add(line); } curveList.Add(Line.CreateBound(pointList[pointList.Count - 1], pointList[0])); CurveLoop curveLoop = CurveLoop.Create(curveList); curveLoopList.Add(curveLoop); } } Solid solid = GeometryCreationUtilities.CreateExtrusionGeometry(curveLoopList, new XYZ(0, 0, 1), 1); if (null != solid) { foreach (Face face in solid.Faces) { XYZ normal = face.ComputeNormal(new UV(0, 0)); if (normal.Z < 0) { faceCreated = face; break; } } } } catch (Exception ex) { string message = ex.Message; } return(faceCreated); }
public static Solid CreateCylindricalSolidFromLine(this Line line, double radius = 0.1) { line = line.Fix(); Plane plane = Plane.CreateByNormalAndOrigin(line.Direction, line.Origin); CurveLoop profile = CurveLoop.Create(new[] { Arc.Create(plane, radius, 0, Math.PI), Arc.Create(plane, radius, Math.PI, 2 * Math.PI) }); return(GeometryCreationUtilities.CreateExtrusionGeometry(new[] { profile }, line.Direction, line.Length)); }
/// <summary> /// Return a solid corresponding to the volume represented by boundingBoxXYZ. /// </summary> /// <param name="lcs">The local coordinate system of the bounding box; if null, assume the Identity transform.</param> /// <param name="boundingBoxXYZ">The bounding box.</param> /// <param name="solidOptions">The options for creating the solid. Allow null to mean default.</param> /// <returns>A solid of the same size and orientation as boundingBoxXYZ, or null if boundingBoxXYZ is invalid or null.</returns> /// <remarks>We don't do any checking on the input transform, which could have non-uniform scaling and/or mirroring. /// This could potentially lead to unexpected results, which we can examine if and when such cases arise.</remarks> public static Solid CreateSolidFromBoundingBox(Transform lcs, BoundingBoxXYZ boundingBoxXYZ, SolidOptions solidOptions) { // Check that the bounding box is valid. if (boundingBoxXYZ == null || !boundingBoxXYZ.Enabled) { return(null); } try { // Create a transform based on the incoming local coordinate system and the bounding box coordinate system. Transform bboxTransform = (lcs == null) ? boundingBoxXYZ.Transform : lcs.Multiply(boundingBoxXYZ.Transform); XYZ[] profilePts = new XYZ[4]; profilePts[0] = bboxTransform.OfPoint(boundingBoxXYZ.Min); profilePts[1] = bboxTransform.OfPoint(new XYZ(boundingBoxXYZ.Max.X, boundingBoxXYZ.Min.Y, boundingBoxXYZ.Min.Z)); profilePts[2] = bboxTransform.OfPoint(new XYZ(boundingBoxXYZ.Max.X, boundingBoxXYZ.Max.Y, boundingBoxXYZ.Min.Z)); profilePts[3] = bboxTransform.OfPoint(new XYZ(boundingBoxXYZ.Min.X, boundingBoxXYZ.Max.Y, boundingBoxXYZ.Min.Z)); XYZ upperRightXYZ = bboxTransform.OfPoint(boundingBoxXYZ.Max); // If we assumed that the transforms had no scaling, // then we could simply take boundingBoxXYZ.Max.Z - boundingBoxXYZ.Min.Z. // This code removes that assumption. XYZ origExtrusionVector = new XYZ(boundingBoxXYZ.Min.X, boundingBoxXYZ.Min.Y, boundingBoxXYZ.Max.Z) - boundingBoxXYZ.Min; XYZ extrusionVector = bboxTransform.OfVector(origExtrusionVector); double extrusionDistance = extrusionVector.GetLength(); XYZ extrusionDirection = extrusionVector.Normalize(); CurveLoop baseLoop = new CurveLoop(); for (int ii = 0; ii < 4; ii++) { baseLoop.Append(Line.CreateBound(profilePts[ii], profilePts[(ii + 1) % 4])); } IList <CurveLoop> baseLoops = new List <CurveLoop>(); baseLoops.Add(baseLoop); if (solidOptions == null) { return(GeometryCreationUtilities.CreateExtrusionGeometry(baseLoops, extrusionDirection, extrusionDistance)); } else { return(GeometryCreationUtilities.CreateExtrusionGeometry(baseLoops, extrusionDirection, extrusionDistance, solidOptions)); } } catch { return(null); } }
/// <summary> /// 获得房间的拉伸实体Solid /// </summary> /// <param name="room"></param> /// <param name="currDoc">当前文件</param> /// <returns></returns> /// <remarks>当房间是连接文件中的房间,但是没有传递当前文件currDocument参数时,跳过射线法计算房间高度</remarks> public static Solid GetRoomActualSolid(this Room room, Document currDoc = null) { var loops = GetRoomBoundaryAsCurveLoopArray(room); if (loops == null) { return(null); } TryGetRoomHeight(room, out double roomHeight, currDoc); return(GeometryCreationUtilities.CreateExtrusionGeometry(loops, XYZ.BasisZ, roomHeight)); }
private bool CreateRoomMassByBoundingBox(Room room) { try { var bb = room.get_BoundingBox(null); var eid = new ElementId(BuiltInCategory.OST_Mass); if (bb == null) { return(false); } #if REVIT2019 || REVIT2018 || REVIT2017 || REVIT2020 || REVIT2021 DirectShape roomShape = DirectShape.CreateElement(doc, eid); #else DirectShape roomShape = DirectShape.CreateElement(doc, eid, "A", "B"); #endif var curves = new List <Curve>(); var bl = new XYZ(bb.Min.X, bb.Min.Y, bb.Min.Z); var br = new XYZ(bb.Max.X, bb.Min.Y, bb.Min.Z); var tr = new XYZ(bb.Max.X, bb.Max.Y, bb.Min.Z); var tl = new XYZ(bb.Min.X, bb.Max.Y, bb.Min.Z); var height = bb.Max.Z - bb.Min.Z; curves.Add(Line.CreateBound(bl, br)); curves.Add(Line.CreateBound(br, tr)); curves.Add(Line.CreateBound(tr, tl)); curves.Add(Line.CreateBound(tl, bl)); var loop = CurveLoop.Create(curves); var options = new SolidOptions(ElementId.InvalidElementId, ElementId.InvalidElementId); var roomSolid = GeometryCreationUtilities.CreateExtrusionGeometry(new[] { loop }, new XYZ(0, 0, 1), height, options); if (roomSolid != null) { var geomObj = new GeometryObject[] { roomSolid }; if (geomObj.Length > 0) { roomShape.SetShape(geomObj); CopyAllRoomParametersToMasses(room, roomShape); return(true); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } return(false); }
/// <summary> /// 获得房间边界及边界组成元素 /// </summary> /// <param name="room"></param> /// <param name="currDocument">当前文件,射线法需要用到</param> /// <returns>内层List为CurveLoop组成Curve,外层IList是组成CurveLoop的个数</returns> public static IList <List <RoomBoundary> > GetRoomSurroundingElements(this Room room, Document currDocument) { if (room.Document.IsLinked && currDocument == null) { throw new InvalidOperationException("currDocument为空,如果房间是链接文件中的房间,必须传递当前文件currDocument参数"); } IList <IList <BoundarySegment> > segmentsloops = null; IList <CurveLoop> curveLoop = null; var bndOpt = new SpatialElementBoundaryOptions(); foreach (SpatialElementBoundaryLocation spl in Enum.GetValues(typeof(SpatialElementBoundaryLocation))) { //获取房间边界的定位点,可以是边界、中心、核心层中心、核心层边界等 bndOpt.SpatialElementBoundaryLocation = spl; try { segmentsloops = room.GetBoundarySegments(bndOpt); if (segmentsloops != null) { curveLoop = segmentsloops.Select(e => { var curves = e.Select(l => l.GetCurve()).ToList(); return(CurveLoop.Create(curves)); }).ToList(); // 验证CurveLoop是否合法(因为有可能存在自交的情况) GeometryCreationUtilities.CreateExtrusionGeometry(curveLoop, XYZ.BasisZ, 10); break; } } catch (Exception) { } } if (segmentsloops == null) { return(null); } IList <List <RoomBoundary> > rstBoundaryList = new List <List <RoomBoundary> >(); for (int i = 0; i < segmentsloops.Count; i++) { bool isCounterclockwise = curveLoop[i].IsCounterclockwise(XYZ.BasisZ); var elements = GetElementsByBoundarySegments(currDocument, segmentsloops[i], isCounterclockwise); rstBoundaryList.Add(elements); } return(rstBoundaryList); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { UIApplication uiapp = commandData.Application; UIDocument uidoc = uiapp.ActiveUIDocument; Document doc = uidoc.Document; Selection sel = uidoc.Selection; var acview = doc.ActiveView; var beamrefs = sel.PickObjects(ObjectType.Element, doc.GetSelectionFilter(m => m.Category.Id.IntegerValue == (int)BuiltInCategory.OST_StructuralFraming), "选择生成板的梁"); var beams = beamrefs.Select(m => m.GetElement(doc)); //var ele = sel.PickObject(ObjectType.Element).GetElement(doc); //var solid = ele.get_Geometry(new Options()).GetSolidOfGeometryObject().First(); //var trans = Transform.Identity; //trans.Origin = new XYZ(-10, 0, 0); //doc.Invoke(m => //{ // var newsolid = SolidUtils.CreateTransformed(solid, trans); // var directshape = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel)); // directshape.AppendShape(new List<GeometryObject>() {newsolid}); //}, "test"); //doc.Create.NewFloor() var upfaces = beams.Select(m => m.get_Geometry(new Options() { DetailLevel = ViewDetailLevel.Fine }).Getupfaces().First()); MessageBox.Show(upfaces.Count().ToString()); var solids = upfaces.Select(m => GeometryCreationUtilities.CreateExtrusionGeometry(m.GetEdgesAsCurveLoops(), XYZ.BasisZ, 10)).ToList(); MessageBox.Show("solids count" + solids.Count().ToString()); var targetsolid = MergeSolids(solids); List <GeometryObject> geoobjs = solids.Cast <GeometryObject>().ToList(); doc.Invoke(m => { var directshape = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel)); //directshape.AppendShape(new List<GeometryObject>(){targetsolid}); directshape.AppendShape(geoobjs); }, "temsolid"); return(Result.Succeeded); }
public static IList <Solid> CreateSolid(Document doc, FamilyInstance familyInstance, Transform transform) { IList <Solid> solids = new List <Solid>(); try { Curve curve = GetCurvemaxfamily(familyInstance); Element ele = doc.GetElement(familyInstance.Id); string[] parameters = new string[] { "DIM_WWF_YY", "DIM_LENGTH" }; Parameter pa = LookupElementParameter(ele, parameters); double lengthcurve = pa.AsDouble(); XYZ starpointfa = new XYZ(lengthcurve / 2, 0, 0); XYZ endpointfa = new XYZ(-lengthcurve / 2, 0, 0); XYZ startpoint = transform.OfPoint(starpointfa); XYZ endpoint = transform.OfPoint(endpointfa); XYZ norm = new XYZ((startpoint.X - endpoint.X), (startpoint.Y - endpoint.Y), (startpoint.Z - endpoint.Z)); Plane plane = Plane.CreateByNormalAndOrigin(norm, startpoint); Transaction newtran = new Transaction(doc, "ss"); newtran.Start(); SketchPlane stk = SketchPlane.Create(doc, plane); XYZ pt1 = startpoint.Add(0.01 * plane.XVec).Add(0.01 * plane.YVec); XYZ pt2 = startpoint.Add(0.01 * plane.YVec); XYZ pt3 = startpoint.Add(-0.01 * plane.YVec); XYZ pt4 = startpoint.Add(0.01 * plane.XVec).Add(-0.01 * plane.YVec); XYZ pt5 = (-1) * norm; Line lineleft = Line.CreateBound(pt1, pt2); Line linetop = Line.CreateBound(pt2, pt3); Line lineright = Line.CreateBound(pt3, pt4); Line linebot = Line.CreateBound(pt4, pt1); CurveLoop profile = new CurveLoop(); profile.Append(lineleft); profile.Append(linetop); profile.Append(lineright); profile.Append(linebot); IList <CurveLoop> listloop1 = new List <CurveLoop>(); listloop1.Add(profile); Solid solid = GeometryCreationUtilities.CreateExtrusionGeometry(listloop1, pt5, lengthcurve); newtran.Commit(); solids.Add(solid); } catch { solids = null; } return(solids); }
public DirectShape Build(Document doc, List <CurveLoop> profile, double height, ElementId catId) { try { var solid = GeometryCreationUtilities.CreateExtrusionGeometry(profile, XYZ.BasisZ, height); var directShape = DirectShape.CreateElement(doc, catId); directShape.AppendShape(new List <GeometryObject> { solid }); return(directShape); } catch (Exception e) { Console.WriteLine($"Caught exception while building Direct Shape {e.Message}"); return(null); } }
public Autodesk.Revit.DB.Solid CreateSolidFromBoundingBox(Autodesk.Revit.DB.Solid inputSolid) { BoundingBoxXYZ bbox = inputSolid.GetBoundingBox(); // Corners in BBox coords XYZ pt0 = new XYZ(bbox.Min.X, bbox.Min.Y, bbox.Min.Z); XYZ pt1 = new XYZ(bbox.Max.X, bbox.Min.Y, bbox.Min.Z); XYZ pt2 = new XYZ(bbox.Max.X, bbox.Max.Y, bbox.Min.Z); XYZ pt3 = new XYZ(bbox.Min.X, bbox.Max.Y, bbox.Min.Z); // Edges in BBox coords Autodesk.Revit.DB.Line edge0 = Autodesk.Revit.DB.Line.CreateBound(pt0, pt1); Autodesk.Revit.DB.Line edge1 = Autodesk.Revit.DB.Line.CreateBound(pt1, pt2); Autodesk.Revit.DB.Line edge2 = Autodesk.Revit.DB.Line.CreateBound(pt2, pt3); Autodesk.Revit.DB.Line edge3 = Autodesk.Revit.DB.Line.CreateBound(pt3, pt0); // Create loop, still in BBox coords List <Autodesk.Revit.DB.Curve> edges = new List <Autodesk.Revit.DB.Curve>(); edges.Add(edge0); edges.Add(edge1); edges.Add(edge2); edges.Add(edge3); double height = bbox.Max.Z - bbox.Min.Z; CurveLoop baseLoop = CurveLoop.Create(edges); List <CurveLoop> loopList = new List <CurveLoop>(); loopList.Add(baseLoop); Autodesk.Revit.DB.Solid preTransformBox = GeometryCreationUtilities .CreateExtrusionGeometry(loopList, XYZ.BasisZ, height); Autodesk.Revit.DB.Solid transformBox = SolidUtils.CreateTransformed( preTransformBox, bbox.Transform); return(preTransformBox); }
private void CalculateCenterPoint() { try { if (areaProfile.Count > 0) { XYZ extrusionDir = new XYZ(0, 0, 1); using (Transaction trans = new Transaction(m_area.Document)) { trans.Start("Compute centroid"); try { Solid tempSolid = GeometryCreationUtilities.CreateExtrusionGeometry(areaProfile, extrusionDir, 1); if (null != tempSolid) { areaCenterPoint = tempSolid.ComputeCentroid(); foreach (Face face in tempSolid.Faces) { XYZ normal = face.ComputeNormal(new UV(0, 0)); if (normal.Z < 0) { if (Math.Abs(normal.Z) > Math.Abs(normal.X) && Math.Abs(normal.Z) > Math.Abs(normal.Y)) { areaFace = face; break; } } } } } catch (Exception ex) { string message = ex.Message; } finally { trans.RollBack(); } } } } catch (Exception ex) { string message = ex.Message; } }
public static Solid CreateRectangularPrism(XYZ center, double d1, double d2, double d3) { List<Curve> list = new List<Curve>(); XYZ xYZ = new XYZ((0.0 - d1) / 2.0, (0.0 - d2) / 2.0, (0.0 - d3) / 2.0); XYZ xYZ2 = new XYZ((0.0 - d1) / 2.0, d2 / 2.0, (0.0 - d3) / 2.0); XYZ xYZ3 = new XYZ(d1 / 2.0, d2 / 2.0, (0.0 - d3) / 2.0); XYZ xYZ4 = new XYZ(d1 / 2.0, (0.0 - d2) / 2.0, (0.0 - d3) / 2.0); list.Add(Line.CreateBound(xYZ, xYZ2)); list.Add(Line.CreateBound(xYZ2, xYZ3)); list.Add(Line.CreateBound(xYZ3, xYZ4)); list.Add(Line.CreateBound(xYZ4, xYZ)); CurveLoop curveLoop = CurveLoop.Create(list); SolidOptions solidOptions = new SolidOptions(ElementId.InvalidElementId, ElementId.InvalidElementId); return GeometryCreationUtilities.CreateExtrusionGeometry(new CurveLoop[1] { curveLoop }, XYZ.BasisZ, d3, solidOptions); }
public static Solid CreateCylinder(Autodesk.Revit.ApplicationServices.Application app, XYZ origin, XYZ vector, double radius, double height) { Plane p = Plane.CreateByNormalAndOrigin(vector, origin); // need to create this as two arcs rather than one! Curve circle1 = Arc.Create(p, radius, 0, Math.PI); Curve circle2 = Arc.Create(p, radius, Math.PI, Math.PI * 2.0); CurveLoop profile = CurveLoop.Create(new List <Curve>(new Curve[2] { circle1, circle2 })); List <CurveLoop> loops = new List <CurveLoop>(new CurveLoop[1] { profile }); Solid cyl = GeometryCreationUtilities.CreateExtrusionGeometry(loops, vector, height); return(cyl); }
private bool CreateSimpleRoomMassByExtrusion(Room room) { try { var height = room.LookupParameter("Limit Offset"); var curves = new List <CurveLoop>(); var spatialBoundaryOptions = new SpatialElementBoundaryOptions { StoreFreeBoundaryFaces = true }; var loop = new CurveLoop(); var boundarySegments = room.GetBoundarySegments(spatialBoundaryOptions); var biggestList = boundarySegments.OrderByDescending(item => item.Count).First(); foreach (var seg in biggestList) { loop.Append(seg.GetCurve()); } curves.Add(loop); var options = new SolidOptions(ElementId.InvalidElementId, ElementId.InvalidElementId); var roomSolid = GeometryCreationUtilities.CreateExtrusionGeometry(curves, new XYZ(0, 0, 1), height.AsDouble(), options); if (roomSolid == null) { return(false); } var eid = new ElementId(BuiltInCategory.OST_Mass); #if REVIT2019 || REVIT2018 || REVIT2017 || REVIT2020 || REVIT2021 DirectShape roomShape = DirectShape.CreateElement(doc, eid); #else DirectShape roomShape = DirectShape.CreateElement(doc, eid, "A", "B"); #endif roomShape.SetShape(new GeometryObject[] { roomSolid }); CopyAllRoomParametersToMasses(room, roomShape); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); return(false); } return(true); }