/// <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); }
public static Solid CreateSphereAt(XYZ center, double radius) { Frame frame = new Frame(center, XYZ.BasisX, XYZ.BasisY, XYZ.BasisZ); // Create a vertical half-circle loop; // this must be in the frame location. Arc arc = Arc.Create( center - radius * XYZ.BasisZ, center + radius * XYZ.BasisZ, center + radius * XYZ.BasisX); Line line = Line.CreateBound( arc.GetEndPoint(1), arc.GetEndPoint(0)); CurveLoop halfCircle = new CurveLoop(); halfCircle.Append(arc); halfCircle.Append(line); List <CurveLoop> loops = new List <CurveLoop>(1); loops.Add(halfCircle); return(GeometryCreationUtilities .CreateRevolvedGeometry( frame, loops, 0, 2 * Math.PI)); }
/// <summary> /// Return geometry for a particular representation item. /// </summary> /// <param name="shapeEditScope">The geometry creation scope.</param> /// <param name="unscaledLcs">Local coordinate system for the geometry, without scale.</param> /// <param name="scaledLcs">Local coordinate system for the geometry, including scale, potentially non-uniform.</param> /// <param name="guid">The guid of an element for which represntation is being created.</param> /// <returns>Zero or more created geometries.</returns> protected override IList <GeometryObject> CreateGeometryInternal( IFCImportShapeEditScope shapeEditScope, Transform unscaledLcs, Transform scaledLcs, string guid) { Transform unscaledSweptDiskPosition = (unscaledLcs == null) ? Transform.Identity : unscaledLcs; Transform scaledSweptDiskPosition = (scaledLcs == null) ? Transform.Identity : scaledLcs; CurveLoop trimmedDirectrix = IFCGeometryUtil.TrimCurveLoop(Id, Directrix, StartParameter, EndParameter); if (trimmedDirectrix == null) { return(null); } CurveLoop trimmedDirectrixInWCS = IFCGeometryUtil.CreateTransformed(trimmedDirectrix, Id, unscaledSweptDiskPosition, scaledSweptDiskPosition); // Create the disk. Curve firstCurve = null; foreach (Curve curve in trimmedDirectrixInWCS) { firstCurve = curve; break; } double startParam = 0.0; IList <CurveLoop> profileCurveLoops = CreateProfileCurveLoopsForDirectrix(firstCurve, out startParam); if (profileCurveLoops == null) { return(null); } SolidOptions solidOptions = new SolidOptions(GetMaterialElementId(shapeEditScope), shapeEditScope.GraphicsStyleId); IList <GeometryObject> myObjs = new List <GeometryObject>(); try { Solid sweptDiskSolid = GeometryCreationUtilities.CreateSweptGeometry(trimmedDirectrixInWCS, 0, startParam, profileCurveLoops, solidOptions); if (sweptDiskSolid != null) { myObjs.Add(sweptDiskSolid); } } catch (Exception ex) { // If we can't create a solid, we will attempt to split the Solid into valid pieces (that will likely have some overlap). if (ex.Message.Contains("self-intersections")) { Importer.TheLog.LogWarning(Id, "The IfcSweptDiskSolid definition does not define a valid solid, likely due to self-intersections or other such problems; the profile probably extends too far toward the inner curvature of the sweep path. Creating the minimum number of solids possible to represent the geometry.", false); myObjs = SplitSweptDiskIntoValidPieces(trimmedDirectrixInWCS, profileCurveLoops, solidOptions); } else { throw ex; } } return(myObjs); }
//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 }
/// <summary> /// creates a DirectShape instance of which shape is Sphere. /// Sphere is defined by its center and radius. /// </summary> /// <param name="document">The Revit document where the instance to be drawn</param> /// <param name="name">The name of this instance</param> /// <param name="center">Position of the center</param> /// <param name="radius">Radius of the circle</param> /// <param name="line_color">Outline color of Circle</param> /// <param name="surface_transparency">Surface transparency; ranged from 0 (transparent) to 100 (opaque)</param> public DirectSphere(Document document, string name, XYZ center, double radius, Color line_color, int surface_transparency) : base(document, name) { m_shape_type = ShapeTypes.Sphere; Center = center; Radius = radius; XYZ top = center + radius * XYZ.BasisZ; XYZ bottom = center - radius * XYZ.BasisZ; XYZ right = center + radius * XYZ.BasisX; Frame frame = new Frame(center, XYZ.BasisX, XYZ.BasisY, XYZ.BasisZ); List <Curve> profile = new List <Curve>(); profile.Add(Line.CreateBound(top, bottom)); profile.Add(Arc.Create(bottom, top, right)); CurveLoop curve_loop = CurveLoop.Create(profile); SolidOptions options = new SolidOptions(ElementId.InvalidElementId, ElementId.InvalidElementId); if (Frame.CanDefineRevitGeometry(frame) == true) { Solid sphere = GeometryCreationUtilities.CreateRevolvedGeometry(frame, new CurveLoop[] { curve_loop }, 0, 2 * Math.PI, options); using (Transaction t = new Transaction(document, "Create sphere direct shape.")) { t.Start(); DirectShape shape = DirectShape.CreateElement(document, new ElementId(BuiltInCategory.OST_GenericModel)); shape.SetShape(new GeometryObject[] { sphere }); shape.SetName(name); m_element_id = shape.Id; document.ActiveView.SetElementOverrides(shape.Id, new OverrideGraphicSettings().SetProjectionLineColor(line_color).SetSurfaceTransparency(surface_transparency)); t.Commit(); } } }
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 static void CreateSphereDirectShape(Document doc, XYZ center, float radius, string name) { List <Curve> profile = new List <Curve>(); // first create sphere with 2' radius XYZ profile00 = center; XYZ profilePlus = center + new XYZ(0, radius, 0); XYZ profileMinus = center - new XYZ(0, radius, 0); profile.Add(Line.CreateBound(profilePlus, profileMinus)); profile.Add(Arc.Create(profileMinus, profilePlus, center + new XYZ(radius, 0, 0))); CurveLoop curveLoop = CurveLoop.Create(profile); SolidOptions options = new SolidOptions(ElementId.InvalidElementId, ElementId.InvalidElementId); Frame frame = new Frame(center, XYZ.BasisX, -XYZ.BasisZ, XYZ.BasisY); Solid sphere = GeometryCreationUtilities.CreateRevolvedGeometry(frame, new CurveLoop[] { curveLoop }, 0, 2 * Math.PI, options); using (Transaction t = new Transaction(doc, "Create sphere direct shape")) { t.Start(); DirectShape ds = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel)); ds.SetShape(new GeometryObject[] { sphere }); ds.Name = name; t.Commit(); } }
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)); }
/// <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 a centerbased cylinder, only on X, Y, Z three axes forward direction /// </summary> /// <param name="center">The given cylinder center</param> /// <param name="bottomradius">The given cylinder's bottom radius</param> /// <param name="height">The given cylinder's height</param> /// <param name="cylinderdirection">Cylinder's extrusion direction</param> /// <returns>The created cylinder</returns> public Solid CreateCenterbasedCylinder(XYZ center, double bottomradius, double height, CylinderDirection cylinderdirection) { double halfheight = height / 2.0; XYZ bottomcenter = new XYZ( cylinderdirection == CylinderDirection.BasisX ? center.X - halfheight : center.X, cylinderdirection == CylinderDirection.BasisY ? center.Y - halfheight : center.Y, cylinderdirection == CylinderDirection.BasisZ ? center.Z - halfheight : center.Z); XYZ topcenter = new XYZ( cylinderdirection == CylinderDirection.BasisX ? center.X + halfheight : center.X, cylinderdirection == CylinderDirection.BasisY ? center.Y + halfheight : center.Y, cylinderdirection == CylinderDirection.BasisZ ? center.Z + halfheight : center.Z); CurveLoop sweepPath = new CurveLoop(); sweepPath.Append(Line.CreateBound(bottomcenter, topcenter)); List <CurveLoop> profileloops = new List <CurveLoop>(); CurveLoop profileloop = new CurveLoop(); Ellipse cemiEllipse1 = Ellipse.Create(bottomcenter, bottomradius, bottomradius, cylinderdirection == CylinderDirection.BasisX ? Autodesk.Revit.DB.XYZ.BasisY : Autodesk.Revit.DB.XYZ.BasisX, cylinderdirection == CylinderDirection.BasisZ ? Autodesk.Revit.DB.XYZ.BasisY : Autodesk.Revit.DB.XYZ.BasisZ, -Math.PI, 0); Ellipse cemiEllipse2 = Ellipse.Create(bottomcenter, bottomradius, bottomradius, cylinderdirection == CylinderDirection.BasisX ? Autodesk.Revit.DB.XYZ.BasisY : Autodesk.Revit.DB.XYZ.BasisX, cylinderdirection == CylinderDirection.BasisZ ? Autodesk.Revit.DB.XYZ.BasisY : Autodesk.Revit.DB.XYZ.BasisZ, 0, Math.PI); profileloop.Append(cemiEllipse1); profileloop.Append(cemiEllipse2); profileloops.Add(profileloop); return(GeometryCreationUtilities.CreateSweptGeometry(sweepPath, 0, 0, profileloops)); }
/// <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); }
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 Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var uiapp = commandData.Application; var uidoc = uiapp.ActiveUIDocument; var doc = uidoc.Document; const double scale = 0.2; const double length = 4.0 * Math.PI; const int steps = 8; var profile = CreateProfile(scale); var profiles = Enumerable .Range(0, steps + 1) .Select(x => x * length / steps) .Select(CreateSinusTransform) .Select(x => profile.CreateTransformed(x)) .ToList(); using (var transaction = new Transaction(doc, "create loft form with sinus path")) { transaction.Start(); var solid = GeometryCreationUtilities.CreateLoftGeometry(profiles, new SolidOptions(ElementId.InvalidElementId, ElementId.InvalidElementId)); var directShape = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel)); directShape.AppendShape(new GeometryObject[] { solid }); transaction.Commit(); } return(Result.Succeeded); }
// Create a DirectShape Sphere static public void CreateSphereDirectShape(Document doc) { List <Curve> profile = new List <Curve>(); // first create sphere with 2' radius XYZ center = XYZ.Zero; double radius = 2.0; //XYZ profile00 = center; XYZ profilePlus = center + new XYZ(0, radius, 0); XYZ profileMinus = center - new XYZ(0, radius, 0); profile.Add(Line.CreateBound(profilePlus, profileMinus)); profile.Add(Arc.Create(profileMinus, profilePlus, center + new XYZ(radius, 0, 0))); CurveLoop curveLoop = CurveLoop.Create(profile); SolidOptions options = new SolidOptions(ElementId.InvalidElementId, ElementId.InvalidElementId); Frame frame = new Frame(center, XYZ.BasisX, -XYZ.BasisZ, XYZ.BasisY); if (Frame.CanDefineRevitGeometry(frame) == true) { Solid sphere = GeometryCreationUtilities.CreateRevolvedGeometry(frame, new CurveLoop[] { curveLoop }, 0, 2 * Math.PI, options); using (Transaction t = new Transaction(doc, "Create sphere direct shape")) { t.Start(); // create direct shape and assign the sphere shape DirectShape ds = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel)); ds.ApplicationId = "Application id"; ds.ApplicationDataId = "Geometry object id"; ds.SetShape(new GeometryObject[] { sphere }); t.Commit(); } } }
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 static Solid Sphere() { XYZ center = new XYZ(0, 0, 0.5); double radius = 0.75; // Use the standard global coordinate system // as a frame, translated to the sphere bottom. Frame frame = new Frame(center, XYZ.BasisX, XYZ.BasisY, XYZ.BasisZ); // Create a vertical half-circle loop; // this must be in the frame location. XYZ start = center - radius * XYZ.BasisZ; XYZ end = center + radius * XYZ.BasisZ; XYZ XyzOnArc = center + radius * XYZ.BasisX; Arc arc = Arc.Create(start, end, XyzOnArc); Line line = Line.CreateBound(arc.GetEndPoint(1), arc.GetEndPoint(0)); CurveLoop halfCircle = new CurveLoop(); halfCircle.Append(arc); halfCircle.Append(line); List <CurveLoop> loops = new List <CurveLoop>(1); loops.Add(halfCircle); return(GeometryCreationUtilities.CreateRevolvedGeometry(frame, loops, 0, 2 * Math.PI)); }
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 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 and return a solid sphere with /// a given radius and centre point. /// </summary> public static Solid CreateSphereAt(XYZ centre, double radius) { // Use the standard global coordinate system // as a frame, translated to the sphere centre. Frame frame = new Frame(centre, XYZ.BasisX, XYZ.BasisY, XYZ.BasisZ); // Create a vertical half-circle loop; // this must be in the frame location. Arc arc = Arc.Create( centre - radius * XYZ.BasisZ, centre + radius * XYZ.BasisZ, centre + radius * XYZ.BasisX); Line line = Line.CreateBound( arc.GetEndPoint(1), arc.GetEndPoint(0)); CurveLoop halfCircle = new CurveLoop(); halfCircle.Append(arc); halfCircle.Append(line); List <CurveLoop> loops = new List <CurveLoop>(1); loops.Add(halfCircle); return(GeometryCreationUtilities .CreateRevolvedGeometry( frame, loops, 0, 2 * Math.PI)); }
/// <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)); }
// 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()); }
/// <summary> /// creates a DirectShape instance of which shape is a part of a torus (like elbow joint pipe). /// Torus is defined by center, axis, tube radius, and mean radius (the distance between center and tube center). /// The tube_begin and tube_end defines the angle between the two edges of the piece. /// </summary> /// <param name="document">The Revit document where the instance to be drawn</param> /// <param name="name">The name of this instance</param> /// <param name="center">Position of center of the torus' hole</param> /// <param name="axis">Vector passing through the center</param> /// <param name="mean_radius">The distance between torus center and its tube center</param> /// <param name="tube_radius">Radius of tube</param> /// <param name="tube_begin">The vector pointing to one of the torus' edge from its center</param> /// <param name="torus_angle">The angle between the tube begin and end</param> /// <param name="line_color">Outline color of the torus</param> /// <param name="surface_transparency">Surface transparency; ranged from 0 (transparent) to 100 (opaque)</param> public DirectTorus(Document document, string name, XYZ center, XYZ axis, double mean_radius, double tube_radius, XYZ tube_begin, double torus_angle, Color line_color, int surface_transparency) : base(document, name) { m_shape_type = ShapeTypes.Torus; Center = center; Axis = axis; MeanRadius = mean_radius; TubeRadius = tube_radius; HasAnElbow = true; TubeBegin = tube_begin; TubeAngle = torus_angle; XYZ tilting_axis = XYZ.BasisZ.CrossProduct(axis); double tilting_angle = FindSurfaceRevitPluginUtils.GetPositiveAngleBetween(XYZ.BasisZ, axis, tilting_axis); bool no_need_to_tilt = tilting_axis.IsAlmostEqualTo(XYZ.Zero); Transform tilting_torus = no_need_to_tilt ? Transform.Identity : Transform.CreateRotation(tilting_axis, tilting_angle); XYZ tilted_basis_x = tilting_torus.OfVector(XYZ.BasisX); // model space coordinates Frame frame = new Frame(XYZ.Zero, XYZ.BasisX, XYZ.BasisY, XYZ.BasisZ); XYZ model_tube_center = XYZ.BasisX * mean_radius; XYZ model_tube_top = model_tube_center + tube_radius * XYZ.BasisZ; XYZ model_tube_bottom = model_tube_center - tube_radius * XYZ.BasisZ; XYZ model_tube_outer = model_tube_center + tube_radius * XYZ.BasisX; XYZ model_tube_inner = model_tube_center - tube_radius * XYZ.BasisX; List <Curve> tube_circle = new List <Curve>(); tube_circle.Add(Arc.Create(model_tube_top, model_tube_bottom, model_tube_inner)); tube_circle.Add(Arc.Create(model_tube_bottom, model_tube_top, model_tube_outer)); CurveLoop curve_loop = CurveLoop.Create(tube_circle); SolidOptions options = new SolidOptions(ElementId.InvalidElementId, ElementId.InvalidElementId); if (Frame.CanDefineRevitGeometry(frame)) { Solid torus = GeometryCreationUtilities.CreateRevolvedGeometry(frame, new CurveLoop[] { curve_loop }, 0, torus_angle, options); using (Transaction t = new Transaction(document, "Create torus direct shape.")) { t.Start(); DirectShape shape = DirectShape.CreateElement(document, new ElementId(BuiltInCategory.OST_GenericModel)); shape.SetShape(new GeometryObject[] { torus }); shape.SetName(name); m_element_id = shape.Id; if (no_need_to_tilt == false) { shape.Location.Rotate(Line.CreateUnbound(XYZ.Zero, tilting_axis), tilting_angle); } shape.Location.Rotate(Line.CreateUnbound(XYZ.Zero, axis), FindSurfaceRevitPluginUtils.GetPositiveAngleBetween(tilted_basis_x, tube_begin, axis)); shape.Location.Move(center); document.ActiveView.SetElementOverrides(shape.Id, new OverrideGraphicSettings().SetProjectionLineColor(line_color).SetSurfaceTransparency(surface_transparency)); t.Commit(); } } }
public DirectShape GetTurningRadiusWithKneeAndToeClearanceDirectShape(XYZ centerPoint) { // The measurements are mentioned in the drawing in inches but we want it to be in internal units (feet) double inch9 = UnitUtils.ConvertToInternalUnits(9, DisplayUnitType.DUT_DECIMAL_INCHES); double inch13 = UnitUtils.ConvertToInternalUnits(13, DisplayUnitType.DUT_DECIMAL_INCHES); double inch21 = UnitUtils.ConvertToInternalUnits(21, DisplayUnitType.DUT_DECIMAL_INCHES); double inch24 = UnitUtils.ConvertToInternalUnits(24, DisplayUnitType.DUT_DECIMAL_INCHES); double inch27 = UnitUtils.ConvertToInternalUnits(27, DisplayUnitType.DUT_DECIMAL_INCHES); double inch30 = UnitUtils.ConvertToInternalUnits(30, DisplayUnitType.DUT_DECIMAL_INCHES); double inch54 = UnitUtils.ConvertToInternalUnits(54, DisplayUnitType.DUT_DECIMAL_INCHES); // First Create a profile to rotate // Let's take center point as the center of the turning circle. XYZ pt1 = new XYZ(0, 0, 0); XYZ pt2 = new XYZ(inch30, 0, 0); XYZ pt3 = new XYZ(inch30, 0, inch9); XYZ pt4 = new XYZ(inch24, 0, inch9); XYZ pt5 = new XYZ(inch21, 0, inch27); XYZ pt6 = new XYZ(inch13, 0, inch27); XYZ pt7 = new XYZ(inch13, 0, inch54); XYZ pt8 = new XYZ(0, 0, inch54); // Document doc = DocumentInterface.getInstance().GetDoc(); Document doc = this.ActiveUIDocument.Document; // Create the profile to rotate List <Curve> profile = new List <Curve>(); profile.Add(Line.CreateBound(pt1, pt2)); profile.Add(Line.CreateBound(pt2, pt3)); profile.Add(Line.CreateBound(pt3, pt4)); profile.Add(Line.CreateBound(pt4, pt5)); profile.Add(Line.CreateBound(pt5, pt6)); profile.Add(Line.CreateBound(pt6, pt7)); profile.Add(Line.CreateBound(pt7, pt8)); profile.Add(Line.CreateBound(pt8, pt1)); DirectShape ds = null; CurveLoop curveLoop = CurveLoop.Create(profile); Solid rotatedSolid = GeometryCreationUtilities.CreateRevolvedGeometry(new Frame(), new CurveLoop[] { curveLoop }, 0, Math.PI * 2.0); using (Transaction transaction = new Transaction(doc, "Create the clearance space solid")) { transaction.Start(); // create direct shape and assign the sphere shape ds = DirectShape.CreateElement(doc, new ElementId(BuiltInCategory.OST_GenericModel)); ds.ApplicationId = "Application id"; ds.ApplicationDataId = "Geometry object id"; ds.SetShape(new GeometryObject[] { rotatedSolid }); ds.Location.Move(centerPoint); // since we have added the solid on origin, the centerPoint - origin (zero) is the direction vector. transaction.Commit(); } return(ds); }
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); }
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); }
protected List <GeometryObject> CreateConformalGeometryIfPossible( IFCImportShapeEditScope shapeEditScope, Transform unscaledLcs) { Transform unscaledSweptDiskPosition = (unscaledLcs == null) ? Transform.Identity : unscaledLcs; IList <CurveLoop> trimmedDirectrices = IFCGeometryUtil.TrimCurveLoops(Id, Directrix, StartParameter, EndParameter); if (trimmedDirectrices == null) { return(null); } List <GeometryObject> myObjs = null; bool isIdentity = unscaledSweptDiskPosition.IsIdentity; foreach (CurveLoop trimmedDirectrix in trimmedDirectrices) { // Create the disk. Curve firstCurve = null; foreach (Curve curve in trimmedDirectrix) { firstCurve = curve; break; } double startParam = 0.0; IList <CurveLoop> profileCurveLoops = CreateProfileCurveLoopsForDirectrix(firstCurve, out startParam); if (profileCurveLoops == null) { return(null); } SolidOptions solidOptions = new SolidOptions(GetMaterialElementId(shapeEditScope), shapeEditScope.GraphicsStyleId); myObjs = new List <GeometryObject>(); try { Solid sweptDiskSolid = GeometryCreationUtilities.CreateSweptGeometry(trimmedDirectrix, 0, startParam, profileCurveLoops, solidOptions); if (!isIdentity) { sweptDiskSolid = SolidUtils.CreateTransformed(sweptDiskSolid, unscaledSweptDiskPosition); } if (sweptDiskSolid != null) { myObjs.Add(sweptDiskSolid); } } catch { return(null); } } return(myObjs); }
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); }
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); }
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); }
/// <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); } }