private IEnumerable <Entity> CreateSquareMark(Point3d position) { var markSize = ErrorMarkSettings.CurrentSettings.MarkerSize; var result = new List <Entity>(); // Create polyline var vector = new Vector3d(1, 0, 0); var radius = markSize / 2.0; var point1 = position + vector.RotateBy(PI / 4.0, Vector3d.ZAxis) * radius; var point2 = position + vector.RotateBy(PI * 3.0 / 4.0, Vector3d.ZAxis) * radius; var point3 = position + vector.RotateBy(PI * 5.0 / 4.0, Vector3d.ZAxis) * radius; var point4 = position + vector.RotateBy(PI * 7.0 / 4.0, Vector3d.ZAxis) * radius; var polyline = new Autodesk.AutoCAD.DatabaseServices.Polyline(); polyline.AddVertexAt(0, new Point2d(point1.X, point1.Y), 0, 0, 0); polyline.AddVertexAt(1, new Point2d(point2.X, point2.Y), 0, 0, 0); polyline.AddVertexAt(2, new Point2d(point3.X, point3.Y), 0, 0, 0); polyline.AddVertexAt(3, new Point2d(point4.X, point4.Y), 0, 0, 0); polyline.Closed = true; result.Add(polyline); // Create center point var ents = CreatePointMarker(position); result.AddRange(ents); return(result); }
public ElRecJig(Point3d pt) { ptStart = ptlast = new Point2d(pt.X, pt.Y); myline = new Line(); myline.StartPoint = pt; mypl = new Polyline(); }
private IEnumerable <Entity> CreateDiamondMark(Point3d position) { var markSize = ErrorMarkSettings.CurrentSettings.MarkerSize; var result = new List <Entity>(); // Create polyline var point1 = position + new Vector3d(1, 0, 0) * markSize / 2.0; var point2 = position + new Vector3d(0, 1, 0) * markSize / 4.0; var point3 = position + new Vector3d(-1, 0, 0) * markSize / 2.0; var point4 = position + new Vector3d(0, -1, 0) * markSize / 4.0; var polyline = new Autodesk.AutoCAD.DatabaseServices.Polyline(); polyline.AddVertexAt(0, new Point2d(point1.X, point1.Y), 0, 0, 0); polyline.AddVertexAt(1, new Point2d(point2.X, point2.Y), 0, 0, 0); polyline.AddVertexAt(2, new Point2d(point3.X, point3.Y), 0, 0, 0); polyline.AddVertexAt(3, new Point2d(point4.X, point4.Y), 0, 0, 0); polyline.Closed = true; result.Add(polyline); // Create center point var ents = CreatePointMarker(position); result.AddRange(ents); return(result); }
public static IList <Autodesk.DesignScript.Geometry.PolyCurve> GetPolyCurves(Parcel parcel) { IList <Autodesk.DesignScript.Geometry.PolyCurve> retPolys = new List <Autodesk.DesignScript.Geometry.PolyCurve>(); dynamic oParcel = parcel.AcadObject; dynamic loops = oParcel.ParcelLoops; foreach (dynamic loop in loops) { Autodesk.AutoCAD.DatabaseServices.Polyline poly = new Autodesk.AutoCAD.DatabaseServices.Polyline(); int count = loop.Count; for (int i = 0; i < count; i++) { dynamic segElement = loop.Item(i); double x = segElement.StartX; double y = segElement.StartY; double bulge = 0; try { bulge = (double)segElement.Bulge; } catch { } poly.AddVertexAt(i, new Point2d(x, y), bulge, 0, 0); } poly.Closed = true; retPolys.Add(ConvertPolylineToPolyCurve(poly)); } return(retPolys); }
public Drawable CreateVisual() { Autodesk.AutoCAD.DatabaseServices.Polyline pl = new Autodesk.AutoCAD.DatabaseServices.Polyline(); pl.AddVertexAt(0, new Point2d(Center.X - Size * 0.45, Center.Y - Size * 0.45), 0, 0, 0); pl.AddVertexAt(1, new Point2d(Center.X - Size * 0.45, Center.Y + Size * 0.45), 0, 0, 0); pl.AddVertexAt(2, new Point2d(Center.X + Size * 0.45, Center.Y + Size * 0.45), 0, 0, 0); pl.AddVertexAt(3, new Point2d(Center.X + Size * 0.45, Center.Y - Size * 0.45), 0, 0, 0); pl.Closed = true; pl.Color = GetInsColor(InsRate); return(pl); //Hatch h = new Hatch(); //h.SetHatchPattern(HatchPatternType.PreDefined, "SOLID"); //h.Color = Color; //// Set our transparency to 25% (=127) //// Alpha value is Truncate(255 * (100-n)/100) //h.Transparency = new Transparency(120); //Point2dCollection pts = new Point2dCollection(); //pts.Add(new Point2d(Center.X - Size * 0.45, Center.Y - Size * 0.45)); //pts.Add(new Point2d(Center.X - Size * 0.45, Center.Y + Size * 0.45)); //pts.Add(new Point2d(Center.X + Size * 0.45, Center.Y + Size * 0.45)); //pts.Add(new Point2d(Center.X + Size * 0.45, Center.Y - Size * 0.45)); //pts.Add(new Point2d(Center.X - Size * 0.45, Center.Y - Size * 0.45)); //DoubleCollection dps = new DoubleCollection(new double[] { 0, 0, 0, 0,0 }); //h.AppendLoop(HatchLoopTypes.Default, pts, dps); //h.EvaluateHatch(false); //return h; }
public static void darwBounds(Point2d left_down, Point2d right_up, Autodesk.AutoCAD.Colors.Color color, double start_width, double end_width) { Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; using (doc.LockDocument(DocumentLockMode.ProtectedAutoWrite, null, null, false)) { Database database = doc.Database; using (Transaction trans = database.TransactionManager.StartTransaction()) { BlockTable black_table = trans.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord blocktable_record = trans.GetObject(black_table[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; using (Autodesk.AutoCAD.DatabaseServices.Polyline poly = new Autodesk.AutoCAD.DatabaseServices.Polyline()) { poly.AddVertexAt(0, new Point2d(left_down.X, left_down.Y), 0, start_width, end_width); poly.AddVertexAt(1, new Point2d(right_up.X, left_down.Y), 0, start_width, end_width); poly.AddVertexAt(2, new Point2d(right_up.X, right_up.Y), 0, start_width, end_width); poly.AddVertexAt(3, new Point2d(left_down.X, right_up.Y), 0, start_width, end_width); poly.Closed = true; poly.Color = color; blocktable_record.AppendEntity(poly); trans.AddNewlyCreatedDBObject(poly, true); } trans.Commit(); } } }
public static void CreateTransientLines(Database database, List <Point3d> points) { var polyline = new Autodesk.AutoCAD.DatabaseServices.Polyline(); foreach (var point3D in points) { var pointNow = new Point2d(point3D.X, point3D.Y); polyline.AddVertexAt(polyline.NumberOfVertices, pointNow, 0, lineWidth, lineWidth); } polyline.ColorIndex = DefaultColorIndex; _drawables.Add(polyline); // ??? //polyline.Dispose(); // Draw each one initially foreach (Drawable d in _drawables) { TransientManager.CurrentTransientManager.AddTransient( d, TransientDrawingMode.DirectShortTerm, 128, new IntegerCollection() ); } }
public void autoca() { var doc = Application.DocumentManager.MdiActiveDocument; var db = HostApplicationServices.WorkingDatabase; var ed = doc.Editor; try { var per1 = ed.GetEntity("选择测试设备:\n"); if (per1.Status != PromptStatus.OK) { return; } using (var tr = doc.TransactionManager.StartTransaction()) { var bt = (BlockTable)(tr.GetObject(db.BlockTableId, OpenMode.ForRead)); var btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); var ent1 = tr.GetObject(per1.ObjectId, OpenMode.ForRead) as Entity; if (ent1 == null) { return; } if (ent1 is Polyline) { var pp = ent1 as Polyline; ed.WriteMessage(pp.Closed); ed.WriteMessage("\n"); } else if (ent1 is BlockReference) { var rr = ent1.Clone() as BlockReference; if (rr != null) { // 记录当前角度 var rolat = rr.Rotation; // 把角度设置为0 rr.Rotation = 0; // 得到角度为0的实体范围 var ext = rr.GeometricExtents; // 生成一个测试矩形,颜色为黄色 var pl = new Polyline(); pl.CreateRectangle(new Point2d(ext.MaxPoint.X, ext.MaxPoint.Y), new Point2d(ext.MinPoint.X, ext.MinPoint.Y)); pl.ColorIndex = 2; // 旋转实体范围 Matrix3d mt = Matrix3d.Rotation(rolat, Vector3d.ZAxis, GeTools.MidPoint(ext.MaxPoint, ext.MinPoint)); pl.TransformBy(mt); // 加入到模型空间 btr.AppendEntity(pl); tr.AddNewlyCreatedDBObject(pl, true); } } tr.Commit(); } } catch (Exception ex) { ed.WriteMessageWithReturn(ex); } }
private AcadPolyline CreatePolyline(KeyValuePair <Point2d, Point2d> segment) { var polyline = new AcadPolyline(); polyline.AddVertexAt(0, segment.Key, 0, 0, 0); polyline.AddVertexAt(1, segment.Value, 0, 0, 0); return(polyline); }
public PromptResult StartJig(Polyline pLine) { _pLine = pLine; _prevPoint = _pLine.GetPoint3dAt(0); _startPoint = _pLine.GetPoint3dAt(0); return(Application.DocumentManager.MdiActiveDocument.Editor.Drag(this)); }
public static Autodesk.DesignScript.Geometry.PolyCurve ConvertDynamoPolylineToPolyCurve(Autodesk.AutoCAD.DynamoNodes.Polyline dynamoPolyline) { Autodesk.AutoCAD.DatabaseServices.Polyline polyline = (Autodesk.AutoCAD.DatabaseServices.Polyline)dynamoPolyline.InternalDBObject; Autodesk.DesignScript.Geometry.PolyCurve retVal = null; if (polyline != null) { // extract each segment Autodesk.DesignScript.Geometry.Curve[] curves; // = new Autodesk.DesignScript.Geometry.Curve[polyline.NumberOfVertices]; if (polyline.Closed) { curves = new Autodesk.DesignScript.Geometry.Curve[polyline.NumberOfVertices]; } else { curves = new Autodesk.DesignScript.Geometry.Curve[polyline.NumberOfVertices - 1]; } // convert segment into Dynamo curve or line int curIndex = 0; while (curIndex <= polyline.NumberOfVertices) { if (polyline.GetSegmentType(curIndex) == SegmentType.Arc) { Autodesk.DesignScript.Geometry.Arc curCurve; Autodesk.DesignScript.Geometry.Point centerPt = Autodesk.DesignScript.Geometry.Point.ByCoordinates( polyline.GetArcSegment2dAt(curIndex).Center.X, polyline.GetArcSegment2dAt(curIndex).Center.Y, 0.0); Autodesk.DesignScript.Geometry.Point startPt = Autodesk.DesignScript.Geometry.Point.ByCoordinates( polyline.GetArcSegment2dAt(curIndex).StartPoint.X, polyline.GetArcSegment2dAt(curIndex).StartPoint.Y, 0.0); Autodesk.DesignScript.Geometry.Point endPt = Autodesk.DesignScript.Geometry.Point.ByCoordinates( polyline.GetArcSegment2dAt(curIndex).EndPoint.X, polyline.GetArcSegment2dAt(curIndex).EndPoint.Y, 0.0); curCurve = Autodesk.DesignScript.Geometry.Arc.ByCenterPointStartPointEndPoint(centerPt, endPt, startPt); curves.SetValue(curCurve, curIndex); } else if (polyline.GetSegmentType(curIndex) == SegmentType.Line) { Autodesk.DesignScript.Geometry.Line curLine; Autodesk.DesignScript.Geometry.Point startPt = Autodesk.DesignScript.Geometry.Point.ByCoordinates( polyline.GetLineSegment2dAt(curIndex).StartPoint.X, polyline.GetLineSegment2dAt(curIndex).StartPoint.Y, 0.0); Autodesk.DesignScript.Geometry.Point endPt = Autodesk.DesignScript.Geometry.Point.ByCoordinates( polyline.GetLineSegment2dAt(curIndex).EndPoint.X, polyline.GetLineSegment2dAt(curIndex).EndPoint.Y, 0.0); curLine = Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(startPt, endPt); curves.SetValue(curLine, curIndex); } curIndex = curIndex + 1; } retVal = Autodesk.DesignScript.Geometry.PolyCurve.ByJoinedCurves(curves); } return(retVal); }
private static void RemoveVertexFromCurrentWipeout(ObjectId wipeoutId) { var doc = Application.DocumentManager.MdiActiveDocument; var ed = doc.Editor; var loop = true; while (loop) { using (doc.LockDocument()) { using (var tr = doc.TransactionManager.StartTransaction()) { var wipeout = tr.GetObject(wipeoutId, OpenMode.ForWrite) as Wipeout; if (wipeout != null) { var points3D = wipeout.GetVertices(); if (points3D.Count > 3) { var polyline = new Polyline(); for (var i = 0; i < points3D.Count; i++) { polyline.AddVertexAt(i, new Point2d(points3D[i].X, points3D[i].Y), 0.0, 0.0, 0.0); } var pickedPt = ed.GetPoint($"\n{Language.GetItem(LangItem, "msg22")}:"); if (pickedPt.Status != PromptStatus.OK) { loop = false; } else { var pt = polyline.GetClosestPointTo(pickedPt.Value, false); var param = polyline.GetParameterAtPoint(pt); var vertex = Convert.ToInt32(Math.Truncate(param)); polyline.RemoveVertexAt(vertex); var new2DPoints = new Point2dCollection(); for (var i = 0; i < polyline.NumberOfVertices; i++) { new2DPoints.Add(polyline.GetPoint2dAt(i)); } wipeout.SetFrom(new2DPoints, polyline.Normal); } } else { // message loop = false; } } tr.Commit(); } } } }
private AcadPolyline CreatePolyline(IList <Point3d> points) { var polyline = new AcadPolyline(); foreach (var point3D in points) { polyline.AddVertexAt(polyline.NumberOfVertices, new Point2d(point3D.X, point3D.Y), 0, 0, 0); } return(polyline); }
/// <summary> /// Calcula el área de un polygono regular. /// </summary> /// <param name="pts">La geometría del polygono</param> /// <returns>El área del poligono</returns> public static double Area(this Point3dCollection pts) { var pl = new Autodesk.AutoCAD.DatabaseServices.Polyline(); for (int i = 0; i < pts.Count; i++) { pl.AddVertexAt(i, new Point2d(pts[i].X, pts[i].Y), 0, 0, 0); } return(pl.Area); }
public static Autodesk.DesignScript.Geometry.PolyCurve PolyCurveByParcel(Parcel parcel) { Autodesk.DesignScript.Geometry.PolyCurve retVal = null; if (parcel != null) { Autodesk.AutoCAD.DatabaseServices.Polyline poly = parcel.BaseCurve as Autodesk.AutoCAD.DatabaseServices.Polyline; retVal = ConvertPolylineToPolyCurve(poly); } return(retVal); }
/// <summary> /// 放大矩形 /// </summary> /// <param name="cutBox"></param> public static void ZoomRetangle(Polyline cutBox) { //获取最小与最大点 Point3d minPoint = cutBox.GeometricExtents.MinPoint; Point3d maxPoint = cutBox.GeometricExtents.MaxPoint; //设置缩放视口 CADTools.RunCommand(true, "Zoom", "e", new Point3d(minPoint.X - 10, minPoint.Y - 10, 0), new Point3d(maxPoint.X + 10, maxPoint.Y + 10, 0)); }
public PromptResult StartJig(Polyline polyline, Point3d fPt, int vx, string workType) { _prevPoint = fPt; _polyline = polyline; _startPoint = fPt; _vertex = vx; _startBulge = _polyline.GetBulgeAt(_vertex); _workType = workType; return(Application.DocumentManager.MdiActiveDocument.Editor.Drag(this)); }
public static void CreateHandleBlock() { Document doc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; using (Transaction tr = db.TransactionManager.StartTransaction()) { BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord btr = null; if (bt.Has("Handle")) { btr = tr.GetObject(bt["Handle"], OpenMode.ForWrite) as BlockTableRecord; } else { btr = new BlockTableRecord(); btr.Name = "Handle"; bt.UpgradeOpen(); bt.Add(btr); tr.AddNewlyCreatedDBObject(btr, true); } using (Autodesk.AutoCAD.DatabaseServices.Polyline outline = new Autodesk.AutoCAD.DatabaseServices.Polyline()) { outline.SetDatabaseDefaults(); outline.Normal = Vector3d.XAxis; outline.AddVertexAt(0, new Point2d(0.0, 0.0), 0, 0, 0); outline.AddVertexAt(1, new Point2d(0.0, 0.5 * t), 0, 0, 0); outline.AddVertexAt(2, new Point2d(-t, 0.5 * t), 0, 0, 0); outline.AddVertexAt(3, new Point2d(-t, 0.75 * t), 0, 0, 0); outline.AddVertexAt(4, new Point2d(-1.25 * t, t), 0, 0, 0); outline.AddVertexAt(5, new Point2d(-1.75 * t, t), 0, 0, 0); outline.AddVertexAt(6, new Point2d(-2.0 * t, 0.75 * t), 0, 0, 0); outline.AddVertexAt(7, new Point2d(-2.0 * t, 0.0), 0, 0, 0); outline.Closed = true; RevolveOptions opts = new RevolveOptions(); RevolveOptionsBuilder rob = new RevolveOptionsBuilder(opts); rob.CloseToAxis = true; rob.DraftAngle = 0; rob.TwistAngle = 0; Solid3d handle = new Solid3d();; handle.CreateRevolvedSolid(outline, new Point3d(0, 0, 0), Vector3d.YAxis, 2.0 * Math.PI, 0, rob.ToRevolveOptions()); handle.ColorIndex = 0; btr.AppendEntity(handle); tr.AddNewlyCreatedDBObject(handle, true); tr.Commit(); } } }
public PolygonHoleCheckResult(AcadPolyline hole) : base(ActionType.PolygonHole, new ObjectId[0]) { _polylines.Add(hole); _extents = GetExtents3d(); _position = _extents.Value.MinPoint + (_extents.Value.MaxPoint - _extents.Value.MinPoint) / 2; _baseSize = (_extents.Value.MaxPoint - _extents.Value.MinPoint).Length; HighlightEntity = false; }
private Polyline CreatePolygon(Point2d[] points) { var polyline = new Autodesk.AutoCAD.DatabaseServices.Polyline(); for (int i = 0; i < points.Length; i++) { polyline.AddVertexAt(i, points[i], 0, 0, 0); } polyline.Closed = true; return(polyline); }
public static void TestConvexHull() { var currentDoc = Application.DocumentManager.MdiActiveDocument; var editor = currentDoc.Editor; var database = currentDoc.Database; // Only select polyline and polyline 2d. ObjectId polylineId = ObjectId.Null; while (true) { var options = new PromptEntityOptions("\n选择一条曲线:"); var result = editor.GetEntity(options); if (result.Status == PromptStatus.OK) { polylineId = result.ObjectId; break; } if (result.Status == PromptStatus.Cancel) { break; } editor.WriteMessage("\n选择无效"); } if (polylineId.IsNull) { return; } using (var transaction = database.TransactionManager.StartTransaction()) { IEnumerable <Point3d> points = CurveUtils.GetDistinctVertices(polylineId, transaction); var convex = new ConvexHull <Point3d>(points, it => it.X, it => it.Y, (x, y) => new Point3d(x, y, 0), (a, b) => a == b); convex.CalcConvexHull(); var hullPoints = convex.GetResultsAsArrayOfPoint(); var polyline = new Autodesk.AutoCAD.DatabaseServices.Polyline(); for (int i = 0; i < hullPoints.Length; i++) { polyline.AddVertexAt(i, new Point2d(hullPoints[i].X, hullPoints[i].Y), 0, 1, 1); } polyline.ColorIndex = 2; var modelspaceId = SymbolUtilityServices.GetBlockModelSpaceId(database); var modelspace = transaction.GetObject(modelspaceId, OpenMode.ForWrite) as BlockTableRecord; modelspace.AppendEntity(polyline); transaction.AddNewlyCreatedDBObject(polyline, true); transaction.Commit(); } }
public static Autodesk.AutoCAD.DatabaseServices.Polyline CreatePolyline(List <Point2d> points, VisualOption opt) { Point2d[] pts = DistincPoints(points); var pl = new Autodesk.AutoCAD.DatabaseServices.Polyline(); for (int i = 0; i < pts.Length; i++) { pl.AddVertexAt(i, pts[i], 0, 0, 0); } pl.Closed = true; SetEntityOpt(pl, opt); return(pl); }
private static Entity DrawPolyline(Point[] points, bool closePart) { var polyline = new Autodesk.AutoCAD.DatabaseServices.Polyline(); int num = 0; for (int i = 0; i < points.Length; i++) { Point point = points[i]; PointN srcPt = (PointN)point; polyline.AddVertexAt(num++, GIS2CAD.ToCadPoint2d(srcPt), 0.0, 0.0, 0.0); } return(polyline); }
private AcadDB.Polyline GetPolylineFromBulgeVertexCollection(BulgeVertexCollection bulges) { var polyline = new AcadDB.Polyline(bulges.Count); double totalBulge = 0; for (int i = 0; i < bulges.Count; i++) { BulgeVertex bulgeVertex = bulges[i]; polyline.AddVertexAt(i, bulgeVertex.Vertex, bulgeVertex.Bulge, 1.0, 1.0); totalBulge += bulgeVertex.Bulge; } polyline.Closed = bulges[0].Vertex.IsEqualTo(bulges[bulges.Count - 1].Vertex) ? true : false; return(polyline); }
/// <summary> /// 剪切矩形区内的图形 /// </summary> /// <param name="cutBox"></param> public static void TrimMap(Polyline cutBox) { //关闭对象捕捉功能避免误删除 cadApplication.SetSystemVariable("SNAPMODE", 0); cadApplication.SetSystemVariable("MODEMACRO", "正在修剪"); ////获取最小与最大点 Point3d minPoint = cutBox.GeometricExtents.MinPoint; Point3d maxPoint = cutBox.GeometricExtents.MaxPoint; ////设置缩放视口 //设置缩放视口 //CADTools.RunCommand(true, "Zoom", "e", // new Point3d(minPoint.X - 10, minPoint.Y - 10, 0), new Point3d(maxPoint.X + 10, maxPoint.Y + 10, 0)); //CADTools.RunCommand(false, "Zoom", "W" // , new Point3d(minPoint.X - 10, minPoint.Y - 10, 0), new Point3d(maxPoint.X + 10, maxPoint.Y + 10, 0)); //裁剪精度 Polyline offsetBox = cutBox.GetOffsetCurves(0.2)[0] as Polyline; if (offsetBox.Area < cutBox.Area) { offsetBox = cutBox.GetOffsetCurves(-0.2)[0] as Polyline; } //裁剪 for (int i = 0; i < offsetBox.NumberOfVertices; i++) { Point3d p1 = offsetBox.GetPoint3dAt(i); Point3d p2 = new Point3d(); if (i == offsetBox.NumberOfVertices - 1) { p2 = offsetBox.GetPoint3dAt(0); } else { p2 = offsetBox.GetPoint3dAt(i + 1); } //调用Line命令,由用户结束 //CADTools.RunCommand(true, "_.line"); //调用Line命令并结束 // CADTools.RunCommand(false, "_.line", Point3d.Origin, new Point3d(10, 10, 0)); //CADTools.RunCommand(false,new ResultTree // CADTools.RunCommand(false, params new object[]{}); //CADTools.RunCommand(true, ".trim" // , cutBox.ObjectId, "", "F", p1, p2, "", ""); } offsetBox.Dispose(); cadApplication.SetSystemVariable("MODEMACRO", "修剪完成"); }
private ADS.DBObject CreateRectangle(Point3d first, Point3d second) { ADS.Polyline pl = new ADS.Polyline(4); pl.Color = this.graphicsColor; double firstX = first.X; double secondX = second.X; double firstY = first.Y; double secondY = second.Y; pl.AddVertexAt(0, new Point2d(firstX, firstY), 0, 0, 0); pl.AddVertexAt(1, new Point2d(firstX, secondY), 0, 0, 0); pl.AddVertexAt(2, new Point2d(secondX, secondY), 0, 0, 0); pl.AddVertexAt(3, new Point2d(secondX, firstY), 0, 0, 0); pl.Closed = true; return pl; }
public static void TileContour() { AcadLib.CommandStart.Start((doc) => { Database db = doc.Database; Editor ed = doc.Editor; // Jig отрисовки полилинии по задаваемым точкам. TileLineJig jigTest = new TileLineJig(); PromptResult jigRes; bool status = true; do { jigRes = ed.Drag(jigTest); if (jigRes.Status == PromptStatus.OK) { // Добавление указанной точки jigTest.AddNewPromptPoint(); } else if (jigRes.Status == PromptStatus.Cancel || jigRes.Status == PromptStatus.Error) { return; } else if (jigRes.Status == PromptStatus.Other) { status = false; } } while (status); // Добавление полилинии в чертеж. using (Transaction tr = db.TransactionManager.StartTransaction()) { BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); Autodesk.AutoCAD.DatabaseServices.Polyline pl = new Autodesk.AutoCAD.DatabaseServices.Polyline(); pl.SetDatabaseDefaults(); for (int i = 0; i < jigTest.AllVertex.Count; i++) { Point3d pt3d = jigTest.AllVertex[i]; Point2d pt2d = new Point2d(pt3d.X, pt3d.Y); pl.AddVertexAt(i, pt2d, 0, db.Plinewid, db.Plinewid); } pl.TransformBy(jigTest.UCS); btr.AppendEntity(pl); tr.AddNewlyCreatedDBObject(pl, true); tr.Commit(); } }); }
/// <summary> /// Метод сверления /// </summary> /// <param name="curve"></param> /// <returns></returns> public static string drillOperation(Db.Polyline curve) { string returnGCode = ""; //Итак нам понадобится // 1. Имя операции // 2. Диаметр инструмента (мм) // 3. Глубина на которую будем фрезеровать (мм) // 4. Расположение отверстия (в центре выбранной кривой / вдоль кривой) // 5. hole spacing (мм) // 6. Начальная рабочая плоскость (мм) // 7. Глубина сверления за один проход (мм) // 8. Скорость подачи при свердении (мм/мин) return(returnGCode); }
private ADS.DBObject CreateRectangle(Point3d first, Point3d second) { ADS.Polyline pl = new ADS.Polyline(4); pl.Color = this.graphicsColor; double firstX = first.X; double secondX = second.X; double firstY = first.Y; double secondY = second.Y; pl.AddVertexAt(0, new Point2d(firstX, firstY), 0, 0, 0); pl.AddVertexAt(1, new Point2d(firstX, secondY), 0, 0, 0); pl.AddVertexAt(2, new Point2d(secondX, secondY), 0, 0, 0); pl.AddVertexAt(3, new Point2d(secondX, firstY), 0, 0, 0); pl.Closed = true; return(pl); }
public void Point2Sec() { SampleLine smpLine = GetSampleLine(); SampleLineVertexCollection smpVertices = smpLine.Vertices; List <Point3d> pntList = new List <Point3d>(); Autodesk.AutoCAD.DatabaseServices.Polyline pl = new Autodesk.AutoCAD.DatabaseServices.Polyline(); foreach (SampleLineVertex item in smpVertices) { pntList.Add(item.Location); } Line l = new Line(pntList[0], pntList[2]); ObjectIdCollection sectionViewID = smpLine.GetSectionViewIds(); Boolean loopControl = true; while (loopControl) { using (Transaction ts = Dwg.TransactionManager.StartTransaction()) { try { PromptPointResult pnt = Ed.GetPoint("\nSelect the point"); if (pnt.Status == PromptStatus.Cancel) { return; } Point3d pntOnSampleLine = l.GetClosestPointTo(pnt.Value, false); Double dist = Math.Sqrt(Math.Pow((pntList[0].X - pntOnSampleLine.X), 2) + Math.Pow(pntList[0].Y - pntOnSampleLine.Y, 2)); SectionView sectionView = ts.GetObject(sectionViewID[0], OpenMode.ForRead) as SectionView; Point3d pntOnSec = sectionView.Location; Double left = sectionView.OffsetLeft; Point3d startPoint = new Point3d(sectionView.Location.X + left, sectionView.Location.Y, sectionView.Location.Z); Point3d targetPoint = new Point3d(startPoint.X + dist, startPoint.Y, startPoint.Z); Point3d targetPoint2 = new Point3d(targetPoint.X, targetPoint.Y - 5, targetPoint.Z); Xline xl = new Xline(); xl.BasePoint = targetPoint; xl.SecondPoint = targetPoint2; AppendEntity(Db.BlockTableId, xl); ts.Commit(); } catch (System.Exception) { throw; } } } }
/// <summary> /// 右侧张拉CheckBox点击事件 /// </summary> /// <param name="sender">右侧张拉对应CheckBox</param> /// <param name="e">右侧张拉对应CheckBox的事件参数</param> private void checkBoxRightDraw_Click(object sender, RoutedEventArgs e) { SyncData.SyncTdGenParasToDlg(this);//将tdGenParas对象与对话框数据同步 Database db = HostApplicationServices.WorkingDatabase; Editor ed = db.GetEditor(); int iRow = dataGridTdInfo.SelectedIndex; using (Transaction trans = db.TransactionManager.StartTransaction()) { //获得当前行 ObjectId tdId = tdIdsInTable[(dataGridTdInfo.Columns[10].GetCellContent(dataGridTdInfo.Items[iRow]) as TextBlock).Text]; //获取本行钢束线的ObjectId AcadPolyline td = tdId.GetObject(OpenMode.ForRead) as AcadPolyline; //获取本行钢束线 if ((sender as CheckBox).IsChecked == false) //如果右侧为不张拉状态,左侧必须张拉 { (dataGridTdInfo.GetControl(iRow, 4, "checkBoxLeftDraw") as CheckBox).IsChecked = true; //左侧则必须为张拉状态 //左侧引伸量 (dataGridTdInfo.Columns[6].GetCellContent(dataGridTdInfo.Items[iRow]) as TextBlock).Text = td.SingleDrawAmount( TendonGeneralParameters.CtrlStress, TendonGeneralParameters.Kii, TendonGeneralParameters.Miu, 1, TendonGeneralParameters.Ep).ToString("F0"); //右侧引伸量 (dataGridTdInfo.Columns[7].GetCellContent(dataGridTdInfo.Items[iRow]) as TextBlock).Text = "0"; } else if ((sender as CheckBox).IsChecked == true)//右侧目前为张拉状态 { //左侧引伸量 (dataGridTdInfo.Columns[6].GetCellContent(dataGridTdInfo.Items[iRow]) as TextBlock).Text = td.BothDrawAmount( TendonGeneralParameters.CtrlStress, TendonGeneralParameters.Kii, TendonGeneralParameters.Miu, TendonGeneralParameters.Ep)[0].ToString("F0"); //右侧引伸量 (dataGridTdInfo.Columns[7].GetCellContent(dataGridTdInfo.Items[iRow]) as TextBlock).Text = td.BothDrawAmount( TendonGeneralParameters.CtrlStress, TendonGeneralParameters.Kii, TendonGeneralParameters.Miu, TendonGeneralParameters.Ep)[1].ToString("F0"); } trans.Commit(); } }
public static ACADDB.Region AddRegion(ACADDB.ObjectId acadObjectId) { ACADDB.Region returnvalue = null; // Get the current document and database Document acDoc = Application.DocumentManager.MdiActiveDocument; ACADDB.Database acCurDb = acDoc.Database; // Start a transaction using (ACADDB.Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { // Open the Block table for read ACADDB.BlockTable acBlkTbl; acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, ACADDB.OpenMode.ForRead) as ACADDB.BlockTable; // Open the Block table record Model space for write ACADDB.BlockTableRecord acBlkTblRec; acBlkTblRec = acTrans.GetObject(acBlkTbl[ACADDB.BlockTableRecord.ModelSpace], ACADDB.OpenMode.ForWrite) as ACADDB.BlockTableRecord; ACADDB.Polyline polyline = acTrans.GetObject(acadObjectId, ACADDB.OpenMode.ForRead) as ACADDB.Polyline; if (polyline != null) { ACADDB.DBObjectCollection acDBObjColl = new ACADDB.DBObjectCollection(); acDBObjColl.Add((ACADDB.DBObject)polyline.AcadObject); // Calculate the regions based on each closed loop ACADDB.DBObjectCollection myRegionColl = new ACADDB.DBObjectCollection(); myRegionColl = ACADDB.Region.CreateFromCurves(acDBObjColl); ACADDB.Region acRegion = myRegionColl[0] as ACADDB.Region; returnvalue = acRegion; // Add the new object to the block table record and the transaction acBlkTblRec.AppendEntity(acRegion); acTrans.AddNewlyCreatedDBObject(acRegion, true); // Dispose } // Save the new object to the database acTrans.Commit(); } return(returnvalue); }
public static void CreateHandleBlock() { Document doc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; using (Transaction tr = db.TransactionManager.StartTransaction()) { BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord btr = null; if (bt.Has("Handle")) btr = tr.GetObject(bt["Handle"], OpenMode.ForWrite) as BlockTableRecord; else { btr = new BlockTableRecord(); btr.Name = "Handle"; bt.UpgradeOpen(); bt.Add(btr); tr.AddNewlyCreatedDBObject(btr, true); } using (Autodesk.AutoCAD.DatabaseServices.Polyline outline = new Autodesk.AutoCAD.DatabaseServices.Polyline()) { outline.SetDatabaseDefaults(); outline.Normal = Vector3d.XAxis; outline.AddVertexAt(0, new Point2d(0.0, 0.0), 0, 0, 0); outline.AddVertexAt(1, new Point2d(0.0, 0.5 * t), 0, 0, 0); outline.AddVertexAt(2, new Point2d(-t, 0.5 * t), 0, 0, 0); outline.AddVertexAt(3, new Point2d(-t, 0.75 * t), 0, 0, 0); outline.AddVertexAt(4, new Point2d(-1.25 * t, t), 0, 0, 0); outline.AddVertexAt(5, new Point2d(-1.75 * t, t), 0, 0, 0); outline.AddVertexAt(6, new Point2d(-2.0 * t, 0.75 * t), 0, 0, 0); outline.AddVertexAt(7, new Point2d(-2.0 * t, 0.0), 0, 0, 0); outline.Closed = true; RevolveOptions opts = new RevolveOptions(); RevolveOptionsBuilder rob = new RevolveOptionsBuilder(opts); rob.CloseToAxis = true; rob.DraftAngle = 0; rob.TwistAngle = 0; Solid3d handle = new Solid3d(); ; handle.CreateRevolvedSolid(outline, new Point3d(0, 0, 0), Vector3d.YAxis, 2.0 * Math.PI, 0, rob.ToRevolveOptions()); handle.ColorIndex = 0; btr.AppendEntity(handle); tr.AddNewlyCreatedDBObject(handle, true); tr.Commit(); } } }
public static ObjectId CreateExtrusion(Point2d[] pts, Point3d destPt, Vector3d normal, WoodGrainAlignment grain) { ObjectId entId = ObjectId.Null; Document activeDoc = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument; Database db = activeDoc.Database; using (Transaction tr = db.TransactionManager.StartTransaction()) { BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord btr = null; if (String.IsNullOrEmpty(blockName)) btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord; else { if (bt.Has(blockName)) btr = tr.GetObject(bt[blockName], OpenMode.ForWrite) as BlockTableRecord; else { btr = new BlockTableRecord(); btr.Name = blockName; bt.UpgradeOpen(); bt.Add(btr); tr.AddNewlyCreatedDBObject(btr, true); } } Solid3d extrudedSolid = new Solid3d(); using (Autodesk.AutoCAD.DatabaseServices.Polyline outline = new Autodesk.AutoCAD.DatabaseServices.Polyline()) { outline.SetDatabaseDefaults(); outline.Normal = normal; int cnt = 0; foreach (Point2d pt in pts) { outline.AddVertexAt(cnt, pt, 0, 0, 0); cnt++; } outline.Closed = true; Extents3d exts = outline.GeometricExtents; Point3d minPt = exts.MinPoint; Point3d maxPt = exts.MaxPoint; double p1 = maxPt.X - minPt.X; double p2 = maxPt.Y - minPt.Y; double p3 = maxPt.Z - minPt.Z; double pmin = 0.0; if (p1 == 0) { pmin = Math.Min(p2, p3); } if (p2 == 0) { pmin = Math.Min(p1, p3); } if (p3 == 0) { pmin = Math.Min(p1, p2); } double pmax = Math.Max(Math.Max(p1, p2), p3); extrudedSolid.RecordHistory = true; plyIndex++; Vector3d heightVector = outline.Normal * t; SweepOptions sweepOptions = new SweepOptions(); SweepOptionsBuilder builder = new SweepOptionsBuilder(sweepOptions); extrudedSolid.CreateExtrudedSolid(outline, heightVector, sweepOptions); } entId = btr.AppendEntity(extrudedSolid); tr.AddNewlyCreatedDBObject(extrudedSolid, true); extrudedSolid.TransformBy(Matrix3d.Displacement(destPt.GetAsVector())); tr.Commit(); } return entId; }