//本来想在这里做一个放样的,但是放样用api做需要建立族文件,然后再在族文件中创建放样,再导入进来,比较麻烦暂时就不做了,详参: //https://blog.csdn.net/niaxiapia/article/details/80513595?ops_request_misc=%25257B%252522request%25255Fid%252522%25253A%252522161121330016780265434271%252522%25252C%252522scm%252522%25253A%25252220140713.130102334.pc%25255Fall.%252522%25257D&request_id=161121330016780265434271&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_v2~rank_v29-4-80513595.pc_search_result_cache&utm_term=revit%E4%BA%8C%E6%AC%A1%E5%BC%80%E5%8F%91%20%E6%94%BE%E6%A0%B7 private void createExtrusionProfile(ExternalCommandData commandData, Line line, Double radius) { Autodesk.Revit.DB.Document revitDoc = commandData.Application.ActiveUIDocument.Document; //取得文档 Application revitApp = commandData.Application.Application; //取得应用程序 UIDocument uiDoc = commandData.Application.ActiveUIDocument; //取得当前活动文档 Autodesk.Revit.DB.Document document = uiDoc.Document; //获取一个轮廓,此处就用圆形轮廓 Plane plane = Plane.CreateByNormalAndOrigin(XYZ.BasisZ, XYZ.Zero); SketchPlane sketchPlane = SketchPlane.Create(document, plane); Arc arc = Arc.Create(plane, radius, 0, Math.PI * 2); //为下面的放样准备参数 CurveArray curveArray = new CurveArray(); CurveArrArray curveArrArray = new CurveArrArray(); curveArray.Append(arc); curveArrArray.Append(curveArray); //放样所用的直线 ReferenceArray referenceArray = new ReferenceArray(); referenceArray.Append(line.Reference); Autodesk.Revit.Creation.Application application = uiDoc.Application.Application.Create; SweepProfile sweepProfile = application.NewCurveLoopsProfile(curveArrArray); //这句话是不对的,原因是在项目文档中无法拉伸,应该在族文档中实现 //Sweep sweep = document.FamilyCreate.NewSweep(true, referenceArray, sweepProfile, 0, ProfilePlaneLocation.Start); }
//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 }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { // get UIdocument UIDocument uidoc = commandData.Application.ActiveUIDocument; //get document Document doc = uidoc.Document; //get level Level level = new FilteredElementCollector(doc) .OfCategory(BuiltInCategory.OST_Levels) .WhereElementIsNotElementType() .Cast <Level>() .First(x => x.Name == "Ground Floor"); // create points XYZ p1 = new XYZ(-10, -10, 0); XYZ p2 = new XYZ(10, -10, 0); XYZ p3 = new XYZ(15, 0, 0); XYZ p4 = new XYZ(10, 10, 0); XYZ p5 = new XYZ(-10, 10, 0); // create curves List <Curve> curves = new List <Curve>(); Line l1 = Line.CreateBound(p1, p2); Arc l2 = Arc.Create(p2, p4, p3); Line l3 = Line.CreateBound(p4, p5); Line l4 = Line.CreateBound(p5, p1); curves.Add(l1); curves.Add(l2); curves.Add(l3); curves.Add(l4); //create curve loop CurveLoop crvLoop = CurveLoop.Create(curves); double offset = UnitUtils.ConvertToInternalUnits(135, DisplayUnitType.DUT_MILLIMETERS); CurveLoop offsetcrv = CurveLoop.CreateViaOffset(crvLoop, offset, new XYZ(0, 0, 1)); CurveArray cArray = new CurveArray(); foreach (Curve c in offsetcrv) { cArray.Append(c); } try { using (Transaction trans = new Transaction(doc, "Place Family")) { trans.Start(); doc.Create.NewFloor(cArray, false); trans.Commit(); } return(Result.Succeeded); } catch (Exception e) { message = e.Message; return(Result.Failed); } }
protected override void Process(IFCAnyHandle ifcCurve) { base.Process(ifcCurve); bool found = false; double radius = IFCImportHandleUtil.GetRequiredScaledLengthAttribute(ifcCurve, "Radius", out found); if (!found) { Importer.TheLog.LogError(ifcCurve.StepId, "Cannot find the radius of this circle", false); return; } try { Curve = Arc.Create(Position.Origin, radius, 0, 2.0 * Math.PI, Position.BasisX, Position.BasisY); } catch (Exception ex) { if (ex.Message.Contains("too small")) { string lengthAsString = UnitFormatUtils.Format(IFCImportFile.TheFile.Document.GetUnits(), UnitType.UT_Length, radius, true, false); Importer.TheLog.LogError(Id, "Found a circle with radius of " + lengthAsString + ", ignoring.", false); Curve = null; } else { Importer.TheLog.LogError(Id, ex.Message, false); } Curve = null; } }
public static Curve Offset(this Curve curve, double offset) { switch (curve) { case Line line: var start = line.GetEndPoint(0); var end = line.GetEndPoint(1); var oStart = new XYZ(start.X, start.Y, start.Z + offset); var oEnd = new XYZ(end.X, end.Y, end.Z + offset); return(Line.CreateBound(oStart, oEnd)); case Arc arc: var start1 = arc.Evaluate(0, true); var mid = arc.Evaluate(0.5, true); var end1 = arc.Evaluate(1, true); var oStart1 = new XYZ(start1.X, start1.Y, start1.Z + offset); var oMid = new XYZ(mid.X, mid.Y, mid.Z + offset); var oEnd1 = new XYZ(end1.X, end1.Y, end1.Z + offset); return(Arc.Create(oStart1, oEnd1, oMid)); case CylindricalHelix unused: case Ellipse unused1: case HermiteSpline unused2: case NurbSpline unused3: return(curve); default: return(curve); } }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { var uidoc = commandData.Application.ActiveUIDocument; var doc = uidoc.Document; var arc = Arc.Create(uidoc.ActiveView.SketchPlane.GetPlane(), 100, 0, Math.PI / 2); var points = arc.Tessellate().ToList(); var watch = new Stopwatch(); var sb = new StringBuilder(); watch.Start(); points = TestOneTransPerf(doc, points); watch.Stop(); sb.AppendLine("One Transaction: " + watch.Elapsed.TotalMilliseconds); watch.Start(); points = TestFourTransPerf(doc, points); watch.Stop(); sb.AppendLine("Four Transactions: " + watch.Elapsed.TotalMilliseconds); watch.Start(); TestSomeTransPerf(doc, points); watch.Stop(); sb.AppendLine("Some Transactions: " + watch.Elapsed.TotalMilliseconds); MessageBox.Show(sb.ToString(), "Transaction Pref Test"); return(Result.Succeeded); }
private void CreateWalls(List <Geometry> closedCurves, WallType Wall_type, Level targetLevel, string Height_Wall) { CurveArray curveArray = new CurveArray(); Curve Cr = null; foreach (Geometry item in closedCurves) { if (item.Type == "Line") { curveArray.Append(Line.CreateBound(item.startPoint, item.endPoint)); } else { Cr = Arc.Create(item.startPoint, item.endPoint, item.ThirdPoint); curveArray.Append(Cr); } } double Height_ = Convert.ToDouble(Height_Wall); double Height = UnitUtils.Convert(Height_, DisplayUnitType.DUT_MILLIMETERS, DisplayUnitType.DUT_DECIMAL_FEET); using (Transaction transaction = new Transaction(revitDoc)) { transaction.Start("Start "); foreach (Curve item in curveArray) { //Wall wall = Wall.Create(revitDoc, item, targetLevel.Id, false); //wall.WallType = Wall_type; Wall wall = Wall.Create(revitDoc, item, Wall_type.Id, targetLevel.Id, Height, 0, false, false); } transaction.Commit(); } }
private void CreateFloors(List <Geometry> closedCurves, FloorType floor_type, Level targetLevel) { CurveArray curveArray = new CurveArray(); Curve Cr = null; foreach (Geometry item in closedCurves) { if (item.Type == "Line") { curveArray.Append(Line.CreateBound(item.startPoint, item.endPoint)); } else { Cr = Arc.Create(item.startPoint, item.endPoint, item.ThirdPoint); curveArray.Append(Cr); } } using (Transaction transaction = new Transaction(revitDoc)) { transaction.Start("Start "); revitDoc.Create.NewFloor(curveArray, floor_type, targetLevel, false); transaction.Commit(); } }
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)); }
public static void DrawCircle(UIDocument ui_doc, XYZ CenterPoint, double radius, XYZ Normal) { Plane plane = Plane.CreateByNormalAndOrigin(Normal, CenterPoint); SketchPlane skplane = SketchPlane.Create(ui_doc.Document, plane); Arc arc = Arc.Create(plane, radius, 0.0F, 2 * 22 / 7.0); ModelCurve mc = ui_doc.Document.Create.NewModelCurve(arc, skplane); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { //获取当前文档 UIDocument uidoc = commandData.Application.ActiveUIDocument; Document doc = uidoc.Document; //获取CW 102-50-100p类型的墙体 FilteredElementCollector collector = new FilteredElementCollector(doc); Element ele = collector.OfCategory(BuiltInCategory.OST_Walls).OfClass(typeof(WallType)) .FirstOrDefault(e => e.Name == "CW 102-50-100p"); WallType walltype = ele as WallType; //获取标高 Level level = new FilteredElementCollector(doc).OfClass(typeof(Level)).FirstOrDefault(x => x.Name == "标高 1") as Level; //创建线 XYZ start = new XYZ(0, 0, 0); XYZ end = new XYZ(10, 10, 0); XYZ ptOnArc = new XYZ(10, 0, 0); Line geonline = Line.CreateBound(start, end); Arc geoArc = Arc.Create(start, end, ptOnArc); //创建墙体的高度和偏移量 double height = 15 / 0.3048;//英尺换算 double offset = 0; //创建墙 Transaction trans = new Transaction(doc, "创建墙体"); trans.Start(); //直线墙 // Wall wall = Wall.Create(doc, geonline, walltype.Id,level.Id,height,offset,false,false);//如果创建错了,会返回错误的东西,好像就是事务没有提交一样 //弧形墙 Wall arcwall = Wall.Create(doc, geoArc, walltype.Id, level.Id, height, offset, false, false);//如果创建错了,会返回错误的东西,好像就是事务没有提交一样 //弧形墙 trans.Commit(); return(Result.Succeeded); }
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); } } }
/// <summary> /// Create a new curve with the same /// geometry in the reverse direction. /// </summary> /// <param name="orig">The original curve.</param> /// <returns>The reversed curve.</returns> /// <throws cref="NotImplementedException">If the /// curve type is not supported by this utility.</throws> static Curve CreateReversedCurve( Autodesk.Revit.Creation.Application creapp, Curve orig) { if (!IsSupported(orig)) { throw new NotImplementedException( "CreateReversedCurve for type " + orig.GetType().Name); } if (orig is Line) { return(Line.CreateBound( orig.GetEndPoint(1), orig.GetEndPoint(0))); } else if (orig is Arc) { return(Arc.Create(orig.GetEndPoint(1), orig.GetEndPoint(0), orig.Evaluate(0.5, true))); } else { throw new Exception( "CreateReversedCurve - Unreachable"); } }
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> /// 把两个相交L、V型线段,如果不是,则基于交点进行裁剪 只留下L、V型,进行倒角处理 /// </summary> /// <param name="_line1"></param> /// <param name="_line2"></param> /// <param name="radius"></param> /// <param name="_newline1"></param> /// <param name="_newline2"></param> /// <returns></returns> public static Arc Chamfer(Line _line1, Line _line2, double radius, out Line _newline1, out Line _newline2) { List <Line> lines = CutOffTwoLineByIntersectionPoint(_line1, _line2); //把两个相交线段,基于交点进行裁剪 只留下L、V型,进行倒角处理 该处处理,可以保证线的起点与终点的先后位置 XYZ intersectionPoint = GetIntersetionPointFromTwoLines(_line1, _line2); //求出L or V交点 XYZ direction_line1 = lines[0].Direction; //求方向,再求角度 XYZ direction_line2 = lines[1].Direction; double angle = direction_line1.AngleTo(direction_line2); if (angle > Math.PI) { angle = Math.PI * 2 - angle; } //求圆弧的三角函数问题,需要深究—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————— XYZ point_arc_start = intersectionPoint.Add(direction_line1.Multiply(radius / (Math.Tan(angle / 2))));//使用正切三角函数,求出,圆弧与倒角直线相切点的位置 XYZ point_arc_end = intersectionPoint.Add(direction_line2.Multiply(radius / (Math.Tan(angle / 2)))); XYZ direction_line3 = direction_line1.Add(direction_line2).Normalize(); XYZ point_arc_middle = intersectionPoint.Add(direction_line3.Multiply((radius / Math.Sin(angle / 2)) - radius));// 使用正弦三角函数,求出,圆弧与倒角直线相切点的位置 Arc arc = Arc.Create(point_arc_start, point_arc_end, point_arc_middle); _newline1 = Line.CreateBound(point_arc_start, lines[0].GetEndPoint(1)); _newline2 = Line.CreateBound(point_arc_end, lines[1].GetEndPoint(1)); return(arc); }
// Token: 0x060001F0 RID: 496 RVA: 0x0000DB14 File Offset: 0x0000BD14 private static CurveLoop GetRebarSweepProfile(Plane plane, List <Curve> centerLineCurves, double radius) { bool flag = centerLineCurves.none <Curve>(); CurveLoop result; if (flag) { result = null; } else { XYZ xvec = plane.XVec; XYZ yvec = plane.YVec; XYZ endPoint = centerLineCurves[0].GetEndPoint(0); Arc item = Arc.Create(endPoint, radius, 0.0, 3.1415926535897931, xvec, yvec); Arc item2 = Arc.Create(endPoint, radius, 3.1415926535897931, 6.2831853071795862, xvec, yvec); CurveLoop curveLoop = CurveLoop.Create(new List <Curve> { item, item2 }); result = curveLoop; } return(result); }
/// <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(); } } }
static public Curve Flatten(this Curve curve, double height = 0) { XYZ firstPoint = curve.GetEndPoint(0); firstPoint = new XYZ(firstPoint.X, firstPoint.Y, height); XYZ secondPoint = curve.GetEndPoint(1); secondPoint = new XYZ(secondPoint.X, secondPoint.Y, height); if (firstPoint.IsAlmostEqualTo(secondPoint)) { return(null); } if (curve is Line) { return(Line.CreateBound(firstPoint, secondPoint)); } if (curve is Arc) { XYZ centerPoint = curve.Evaluate(0.5, true); centerPoint = new XYZ(centerPoint.X, centerPoint.Y, height); return(Arc.Create(firstPoint, secondPoint, centerPoint)); } throw new Exception("THIAGO -> Curve can't be flatten because it is not a line or arc"); }
/// <summary> /// Create a new curve with the same /// geometry in the reverse direction. /// </summary> /// <param name="original">The original curve.</param> /// <returns>The reversed curve.</returns> /// <throws cref="NotImplementedException">If the /// curve type is not supported by this utility.</throws> static Curve CreateReversedCurve(Curve original) { // Check if the curve is supported. if (!IsSupported(original)) { throw new NotImplementedException( "CreateReversedCurve for type " + original.GetType().Name); } // The curve is a line => Create a reversed line. if (original is Line) { return(Line.CreateBound( original.GetEndPoint(1), original.GetEndPoint(0))); } // The curve is arc => Create a reverses arc. else if (original is Arc) { return(Arc.Create(original.GetEndPoint(1), original.GetEndPoint(0), original.Evaluate(0.5, true))); } // Something else! => There is an error! else { throw new Exception( "CreateReversedCurve - Unreachable"); } }
/// <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> /// Offsets an arc along the offset direction from the point on the arc. /// </summary> /// <param name="arc">The arc.</param> /// <param name="offsetPntOnArc">The point on the arc.</param> /// <param name="offset">The offset vector.</param> /// <returns>The offset Arc.</returns> private static Arc OffsetArc(Arc arc, XYZ offsetPntOnArc, XYZ offset) { if (arc == null || offset == null) { throw new ArgumentNullException(); } if (offset.IsZeroLength()) { return(arc); } XYZ axis = arc.Normal.Normalize(); XYZ offsetAlongAxis = axis.Multiply(offset.DotProduct(axis)); XYZ offsetOrthAxis = offset - offsetAlongAxis; XYZ offsetPntToCenter = (arc.Center - offsetPntOnArc).Normalize(); double signedOffsetLengthTowardCenter = offsetOrthAxis.DotProduct(offsetPntToCenter); double newRadius = arc.Radius - signedOffsetLengthTowardCenter; // signedOffsetLengthTowardCenter > 0, minus, < 0, add Arc offsetArc = Arc.Create(arc.Center, newRadius, arc.GetEndParameter(0), arc.GetEndParameter(1), arc.XDirection, arc.YDirection); offsetArc = GeometryUtil.MoveCurve(offsetArc, offsetAlongAxis) as Arc; return(offsetArc); }
private static Curve CreateReversed(Curve curve) { Autodesk.Revit.DB.Curve orig = curve.ToRevitType(); var app = DocumentManager.Instance.CurrentUIApplication; if (orig is Line) { var line = Line.CreateBound( orig.GetEndPoint(1), orig.GetEndPoint(0)); return(line.ToProtoType()); } else if (orig is Arc) { var arc = Arc.Create(orig.GetEndPoint(1), orig.GetEndPoint(0), orig.Evaluate(0.5, true)); return(arc.ToProtoType()); } else { throw new Exception( "CreateReversedCurve - Unreachable"); } }
// 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(); } } }
/// <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 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 Curve ToRevit(this oM.Geometry.Circle curve) { double radius = curve.Radius.FromSI(UnitType.UT_Length); Plane plane = Plane.CreateByNormalAndOrigin(curve.Normal.ToRevit().Normalize(), curve.Centre.ToRevit()); return(Arc.Create(plane, radius, 0, Math.PI * 2)); }
/// <summary> /// create the extrusions of the air handler system /// </summary> private void CreateExtrusions() { Autodesk.Revit.Creation.Application app = m_application.Create; CurveArray curves = null; CurveArrArray profile = null; Plane plane = null; SketchPlane sketchPlane = null; #region Create the cuboid extrusions for (int i = 0; i <= 2; ++i) { // create the profile curves = app.NewCurveArray(); curves.Append(Line.CreateBound(profileData[i, 0], profileData[i, 1])); curves.Append(Line.CreateBound(profileData[i, 1], profileData[i, 2])); curves.Append(Line.CreateBound(profileData[i, 2], profileData[i, 3])); curves.Append(Line.CreateBound(profileData[i, 3], profileData[i, 0])); profile = app.NewCurveArrArray(); profile.Append(curves); // create the sketch plane plane = Plane.CreateByNormalAndOrigin(sketchPlaneData[i, 0], sketchPlaneData[i, 1]); sketchPlane = SketchPlane.Create(m_document, plane); // create the extrusion extrusions[i] = f.NewExtrusion(isSolid[i], profile, sketchPlane, extrusionOffsets[i, 1]); extrusions[i].StartOffset = extrusionOffsets[i, 0]; m_combineElements.Append(extrusions[i]); } #endregion #region Create the round extrusions for (int i = 3; i <= 4; ++i) { // create the profile profile = app.NewCurveArrArray(); curves = app.NewCurveArray(); plane = Plane.CreateByNormalAndOrigin(profileData[i, 0], profileData[i, 1]); curves.Append(Arc.Create(plane, arcRadius, 0, Math.PI * 2)); profile.Append(curves); // create the sketch plane plane = Plane.CreateByNormalAndOrigin(sketchPlaneData[i, 0], sketchPlaneData[i, 1]); sketchPlane = SketchPlane.Create(m_document, plane); // create the extrusion extrusions[i] = f.NewExtrusion(isSolid[i], profile, sketchPlane, extrusionOffsets[i, 1]); extrusions[i].StartOffset = extrusionOffsets[i, 0]; m_combineElements.Append(extrusions[i]); } #endregion }
/// <summary> /// Draw an O at the given position. /// </summary> public static void DrawMarkerO(XYZ p, double radius, SketchPlane sketchPlane) { Document doc = sketchPlane.Document; XYZ xAxis = new XYZ(1, 0, 0); XYZ yAxis = new XYZ(0, 1, 0); doc.Create.NewModelCurve(Arc.Create(p, radius, 0, 2 * Math.PI, xAxis, yAxis), sketchPlane); }
/// <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(); } } }
/// <summary> /// Draw point marker with detail circles. /// Optional colors are "red" "blue" "orange" /// </summary> public static void DrawDetailMarkers(Document doc, List <XYZ> pts, int weight = 2, string color = "red", string pattern = "") { GetListOfLinestyles(doc); View view = doc.ActiveView; Color palette = new Color(0, 0, 0); switch (color) { case "red": palette = new Color(200, 50, 80); break; case "blue": palette = new Color(100, 149, 237); break; case "orange": palette = new Color(255, 140, 0); break; } FilteredElementCollector fec = new FilteredElementCollector(doc) .OfClass(typeof(LinePatternElement)); LinePatternElement linePatternElem = null; if (pattern != "") { try { linePatternElem = fec .Cast <LinePatternElement>() .First <LinePatternElement>(linePattern => linePattern.Name == pattern); } catch { Debug.Print("There's no matching pattern in the document"); } } XYZ xAxis = new XYZ(1, 0, 0); XYZ yAxis = new XYZ(0, 1, 0); using (Transaction tx = new Transaction(doc)) { tx.Start("Create Detail Markers"); foreach (XYZ pt in pts) { double radius = 0.3; Arc marker = Arc.Create(pt, radius, 0, 2 * Math.PI, xAxis, yAxis); DetailCurve detailCrv = doc.Create.NewDetailCurve(view, marker); GraphicsStyle gs = detailCrv.LineStyle as GraphicsStyle; gs.GraphicsStyleCategory.LineColor = palette; gs.GraphicsStyleCategory.SetLineWeight(weight, gs.GraphicsStyleType); if (linePatternElem != null) { gs.GraphicsStyleCategory.SetLinePatternId(linePatternElem.Id, GraphicsStyleType.Projection); } } tx.Commit(); } }