public void CreateAngleXLineCommand() { PromptPointOptions ppo = new PromptPointOptions("\nPick Point"); PromptPointResult ppr = GLOBAL.CurrentEditor.GetPoint(ppo); if (ppr.Status != PromptStatus.OK) { return; } PromptDoubleOptions pdo = new PromptDoubleOptions("\nEnter Grade (%)"); PromptDoubleResult pdr = GLOBAL.CurrentEditor.GetDouble(pdo); if (pdr.Status != PromptStatus.OK) { return; } // calculate second point Point3d secondPoint = Helper.Point3dHelper.Offset(ppr.Value, 100, pdr.Value, 0); Xline xline = new Xline() { BasePoint = ppr.Value, UnitDir = new Vector3d(secondPoint.X - ppr.Value.X, secondPoint.Y - ppr.Value.Y, secondPoint.Z - ppr.Value.Z) }; CompositeFigure cg = new CompositeFigure(); cg.Children.Add(xline); cg.Append(GLOBAL.CurrentDocument); }
public void Ali2pro() { Alignment selectedAli = GetAlignment(); if (selectedAli != null) { ObjectIdCollection prfIds = selectedAli.GetProfileViewIds(); try { Boolean loopControl = true; while (loopControl) { foreach (ObjectId item in prfIds) { using (Transaction ts = Application.DocumentManager.MdiActiveDocument.TransactionManager.StartTransaction()) { PromptPointOptions pntOpt = new PromptPointOptions("\nSelect a point"); pntOpt.AllowNone = true; pntOpt.Message = "dogruSec"; PromptPointResult pnt = Ed.GetPoint("\nSelect the point"); if (pnt.Status != PromptStatus.OK) { return; } ; Double km = 0; Double ofset = 0; double x = 0; double y = 0; selectedAli.StationOffset(pnt.Value.X, pnt.Value.Y, ref km, ref ofset); ProfileView pv = ts.GetObject(item, OpenMode.ForRead) as ProfileView; pv.FindXYAtStationAndElevation(km, pv.Location.Y, ref x, ref y); Point3d p1 = new Point3d(x, pv.Location.Y, 0); Point3d p2 = new Point3d(x, pv.Location.Y + pv.ElevationMax, 0); Xline xl = new Xline(); xl.BasePoint = p1; xl.SecondPoint = p2; BlockTable acBlkTbl; acBlkTbl = ts.GetObject(Db.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord acBlkTblRec; acBlkTblRec = ts.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; acBlkTblRec.AppendEntity(xl); ts.AddNewlyCreatedDBObject(xl, true); ts.Commit(); } } } } catch (System.Exception) { throw; } } }
public static bool Clear(this Xline obj) { if (Math.Abs(obj.BasePoint.Z) < TOLERANCE && Math.Abs(obj.SecondPoint.Z) < TOLERANCE) { return(false); } obj.BasePoint = obj.BasePoint.ClearZ(); obj.SecondPoint = obj.SecondPoint.ClearZ(); return(true); }
internal override bool Cross(Bounding selectBound, Entity entity) { Xline xline = entity as Xline; if (xline == null) { return(false); } return(XlineHitter.BoundingIntersectWithXline(selectBound, xline)); }
internal override bool Hit(PickupBox pkbox, Entity entity) { Xline xline = entity as Xline; if (xline == null) { return(false); } Bounding bounding = pkbox.reservedBounding; return(BoundingIntersectWithXline(bounding, xline)); }
private void OnPointInputReturn(DynInputCtrl sender, DynInputResult retult) { DynInputResult <LitMath.Vector2> xyRet = retult as DynInputResult <LitMath.Vector2>; if (xyRet != null && xyRet.status == DynInputStatus.OK) { switch (_step) { case Step.Step1_SpecifyBasePoint: { _currXline = new Xline(); _currXline.basePoint = xyRet.value; _currXline.layerId = this.document.currentLayerId; _currXline.color = this.document.currentColor; this.GotoStep(Step.Step2_SpecifyOtherPoint); } break; case Step.Step2_SpecifyOtherPoint: { LitMath.Vector2 dir = (xyRet.value - _currXline.basePoint).normalized; if (dir.x != 0 || dir.y != 0) { _currXline.direction = dir; _currXline.layerId = this.document.currentLayerId; _currXline.color = this.document.currentColor; _xlines.Add(_currXline); _currXline = _currXline.Clone() as Xline; } this.GotoStep(Step.Step2_SpecifyOtherPoint); } break; } } else { if (_xlines.Count > 0) { _mgr.FinishCurrentCommand(); } else { _mgr.CancelCurrentCommand(); } } }
XlineHardWired() { m_db = Utils.Db.GetCurDwg(); using (CompBldrCurSpace compBldr = new CompBldrCurSpace(m_db)) { compBldr.Start(); compBldr.PushXform(Utils.Db.GetUcsMatrix(m_db)); Xline xline = new Xline(); xline.UnitDir = new Vector3d(1.0, 1.0, 0.0); compBldr.AddToDb(xline); compBldr.Commit(); } }
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; } } } }
public static double CalculateBulge(Point3d ptStart, Point3d corner, Point3d ptEnd) { Line line = new Line(ptStart, ptEnd); Point3d center = new Point3d(); Circle cir = new Circle(); double p = (line.Length + ptStart.DistanceTo(corner) + ptEnd.DistanceTo(corner)) / 2; double S = Math.Sqrt((p - line.Length) * (p - ptStart.DistanceTo(corner)) * (p - ptEnd.DistanceTo(corner)) * p); cir.Radius = (line.Length * ptStart.DistanceTo(corner) * ptEnd.DistanceTo(corner)) / (4 * S); //Find Center // midle line Point3d mid = new Point3d((ptEnd.X + ptStart.X) / 2, (ptEnd.Y + ptStart.Y) / 2, (ptEnd.Z + ptStart.Z) / 2); Xline xline1 = new Xline(); xline1.BasePoint = mid; xline1.UnitDir = (ptStart - ptEnd).GetPerpendicularVector(); Point3d mid2 = new Point3d((ptEnd.X + corner.X) / 2, (ptEnd.Y + corner.Y) / 2, (ptEnd.Z + corner.Z) / 2); Xline xline2 = new Xline(); xline2.BasePoint = mid2; xline2.UnitDir = (corner - ptEnd).GetPerpendicularVector(); Point3dCollection pts = new Point3dCollection(); xline2.IntersectWith(xline1, Intersect.ExtendArgument, pts, IntPtr.Zero, IntPtr.Zero); if (pts.Count == 0) { return(0); } cir.Center = pts[0]; center = cir.Center; Vector3d v1 = ptStart - cir.Center; Vector3d v2 = corner - cir.Center; double angle = v1.GetAngleTo(v2); double bul = Math.Tan(angle / 4); if (Clockwise(ptStart, corner, ptEnd)) { bul = -1 * bul; } else { } return(bul); }
internal static bool BoundingIntersectWithXline(Bounding bounding, Xline xline) { LitMath.Vector2 pkPnt1 = new LitMath.Vector2(bounding.left, bounding.bottom); LitMath.Vector2 pkPnt2 = new LitMath.Vector2(bounding.left, bounding.top); LitMath.Vector2 pkPnt3 = new LitMath.Vector2(bounding.right, bounding.top); LitMath.Vector2 pkPnt4 = new LitMath.Vector2(bounding.right, bounding.bottom); double d1 = LitMath.Vector2.Cross(pkPnt1 - xline.basePoint, xline.direction); double d2 = LitMath.Vector2.Cross(pkPnt2 - xline.basePoint, xline.direction); double d3 = LitMath.Vector2.Cross(pkPnt3 - xline.basePoint, xline.direction); double d4 = LitMath.Vector2.Cross(pkPnt4 - xline.basePoint, xline.direction); if (d1 * d2 <= 0 || d1 * d3 <= 0 || d1 * d4 <= 0) { return(true); } else { return(false); } }
public static void Test() { ObjectId[] objectId = Interaction.GetSelection("\n选择多段线", "LWPOLYLINE");//选择多段线 if (objectId.Length == 0) { return; //一个都没选的情况下退出操作 } objectId.QForEach <Polyline>(polyline => { int length = (int)polyline.EndParam; for (int i = 0; i <= length; i++) { Line l1 = NoDraw.Line(polyline.GetPointAtParam(i), polyline.GetPreviousPointAtParam(i)); Line l2 = NoDraw.Line(polyline.GetPointAtParam(i), polyline.GetNextPointAtParam(i)); // Checks if lines intersect Plane plane; Line3d line1 = new Line3d(l1.StartPoint, l1.EndPoint); Line3d line2 = new Line3d(l2.StartPoint, l2.EndPoint); if (!line1.IsCoplanarWith(line2, out plane) || line1.IsParallelTo(line2)) { return; } // Calculates the bisector Point3d inters = line1.IntersectWith(line2)[0]; Vector3d vec1 = line1.Direction; Vector3d vec2 = line2.Direction; Vector3d bisectDir = ((vec1 + vec2) / 2.0).Negate(); var angle = bisectDir.GetAngleTo(Vector3d.XAxis); Xline xline = new Xline(); xline.UnitDir = bisectDir.GetNormal(); xline.BasePoint = inters; Draw.Text((i + 1).ToString(), 2, xline.GetPointAtDist(1)); Draw.Circle(polyline.GetPointAtParam(i), 0.5); } }); }
public override IEventResult OnMouseDown(IMouseButtonEventArgs e) { switch (_step) { case Step.Step1_SpecifyBasePoint: if (e.IsLeftPressed) { _currXline = presenter.AppendEntity(new Xline(), DBObjectState.Unconfirmed); _currXline.basePoint = this.Pointer.CurrentSnapPoint; _currXline.LayerId = this.document.currentLayerId; _currXline.Color = this.document.currentColor; this.GotoStep(Step.Step2_SpecifyOtherPoint); } break; case Step.Step2_SpecifyOtherPoint: if (e.IsLeftPressed) { CADVector dir = (this.Pointer.CurrentSnapPoint - _currXline.basePoint).normalized; if (dir.X != 0 || dir.Y != 0) { _currXline.direction = dir; _currXline.LayerId = this.document.currentLayerId; _currXline.Color = this.document.currentColor; _xlines.Add(_currXline); _currXline = Drawing.AppendEntity((Xline)_currXline.Clone(), DBObjectState.Unconfirmed); _currXline.Draw(); //_currXline = _currXline.Clone() as Xline; } } break; } return(EventResult.Handled); }
public override EventResult OnMouseDown(MouseEventArgs e) { switch (_step) { case Step.Step1_SpecifyBasePoint: if (e.Button == MouseButtons.Left) { _currXline = new Xline(); _currXline.basePoint = this.pointer.currentSnapPoint; _currXline.layerId = this.document.currentLayerId; _currXline.color = this.document.currentColor; this.GotoStep(Step.Step2_SpecifyOtherPoint); } break; case Step.Step2_SpecifyOtherPoint: if (e.Button == MouseButtons.Left) { LitMath.Vector2 dir = (this.pointer.currentSnapPoint - _currXline.basePoint).normalized; if (dir.x != 0 || dir.y != 0) { _currXline.direction = dir; _currXline.layerId = this.document.currentLayerId; _currXline.color = this.document.currentColor; _xlines.Add(_currXline); _currXline = _currXline.Clone() as Xline; } } break; } return(EventResult.Handled); }
static void TransformXline(Xline x, Matrix3d transform) { x.StartPoint = x.StartPoint.TransformBy(transform); x.SecondPoint = x.SecondPoint.TransformBy(transform); }
public static bool BuilPolyline(Point3d pt1, Point3d pt2, Point3d closerPoint, Point3d CloserPointOnLine, Point3d FurtherPoint, Point3d FurthurPointOnLine) { //Build Longer line Point3d pt7 = pt1 + (CloserPointOnLine - closerPoint).GetNormal() * 3; Point3d pt8 = pt2 + (CloserPointOnLine - closerPoint).GetNormal() * 3; Point3dCollection verx = new Point3dCollection(); verx.Add(pt7); verx.Add(pt1); verx.Add(pt2); verx.Add(pt8); Polyline3d longer = new Polyline3d(Poly3dType.SimplePoly, verx, false); //Build Shorter Line Xline xline = new Xline(); xline.BasePoint = closerPoint; xline.UnitDir = pt1 - pt2; Line l48 = new Line(FurthurPointOnLine, FurtherPoint); Point3dCollection intersec = new Point3dCollection(); xline.IntersectWith(l48, Intersect.OnBothOperands, intersec, IntPtr.Zero, IntPtr.Zero); if (intersec.Count < 1) { return(false); } Xline xl1 = new Xline(); if (pt1.DistanceTo(FurtherPoint) < pt2.DistanceTo(FurtherPoint)) { xl1.BasePoint = pt1; } else { xl1.BasePoint = pt2; } xl1.UnitDir = pt7 - pt1; Xline xl2 = new Xline(); xl2.BasePoint = FurtherPoint; xl2.UnitDir = pt2 - pt1; Point3dCollection intersec2 = new Point3dCollection(); xl1.IntersectWith(xl2, Intersect.OnBothOperands, intersec2, IntPtr.Zero, IntPtr.Zero); Point3dCollection verx2 = new Point3dCollection(); if (intersec2.Count < 1) { return(false); } ArxHelper.AppendEntity(longer); if (pt1.DistanceTo(FurtherPoint) < pt2.DistanceTo(FurtherPoint)) { verx2.Add(pt1); verx2.Add(intersec2[0]); verx2.Add(FurtherPoint); verx2.Add(intersec[0]); verx2.Add(closerPoint); verx2.Add(CloserPointOnLine); Polyline3d pl = new Polyline3d(Poly3dType.SimplePoly, verx2, false); ArxHelper.AppendEntity(pl); return(true); } else { verx2.Add(pt2); verx2.Add(intersec2[0]); verx2.Add(FurtherPoint); verx2.Add(intersec[0]); verx2.Add(closerPoint); verx2.Add(CloserPointOnLine); Polyline3d pl = new Polyline3d(Poly3dType.SimplePoly, verx2, false); ArxHelper.AppendEntity(pl); return(true); } }
public static void CreateStairFrom3Point(Point3d pt1, Point3d pt2, Point3d pt3, double stairWidth, string Layer) { Line l12 = new Line(pt1, pt2); Point3d ptonL12 = l12.GetClosestPointTo(pt3, false); Xline xl1 = new Xline(); xl1.BasePoint = pt1; xl1.UnitDir = pt3 - ptonL12; Xline xl3 = new Xline(); xl3.BasePoint = pt3; xl3.UnitDir = pt1 - pt2; Point3dCollection pts3 = new Point3dCollection(); Point3dCollection pts4 = new Point3dCollection(); xl1.IntersectWith(xl3, Intersect.OnBothOperands, pts3, IntPtr.Zero, IntPtr.Zero); Point3d p3 = new Point3d(); Point3d p4 = new Point3d(); if (pts3.Count > 0) { p3 = pts3[0]; } else { return; } Xline xl2 = new Xline(); xl2.BasePoint = pt2; xl2.UnitDir = pt3 - ptonL12; xl2.IntersectWith(xl3, Intersect.OnBothOperands, pts4, IntPtr.Zero, IntPtr.Zero); if (pts4.Count > 0) { p4 = pts4[0]; } else { return; } Point3dCollection verx = new Point3dCollection(); verx.Add(pt1); verx.Add(pt2); verx.Add(p4); verx.Add(p3); Polyline3d pl = new Polyline3d(Poly3dType.SimplePoly, verx, true); pl.Layer = Layer; ArxHelper.AppendEntity(pl); for (int i = 1; i < p4.DistanceTo(pt2) / stairWidth; i++) { Point3d p1 = pt1 + (p4 - pt2).GetNormal() * i * stairWidth; Point3d p2 = pt2 + (p4 - pt2).GetNormal() * i * stairWidth; Line line = new Line(p1, p2); line.Layer = Layer; ArxHelper.AppendEntity(line); } Point3d mid1 = new Point3d((pt1.X + pt2.X) / 2, (pt1.Y + pt2.Y) / 2, (pt1.Z + pt2.Z) / 2); Point3d mid2 = new Point3d((p3.X + p4.X) / 2, (p3.Y + p4.Y) / 2, (p3.Z + p4.Z) / 2); if (mid1.Z < mid2.Z) { drawArrow(mid1, mid2, pt1 - pt2, pt1.DistanceTo(pt2), stairWidth); } else { drawArrow(mid2, mid1, pt1 - pt2, pt1.DistanceTo(pt2), stairWidth); } }
public void LineSegs3d() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; using (Transaction trans = db.TransactionManager.StartTransaction())//开始事务处理 { //1.选择空间轴线的平面视图多段线 PromptEntityOptions plxyOpt = new PromptEntityOptions("\n选择空间轴线的平面视图多段线"); plxyOpt.SetRejectMessage("\n并非多段线!"); plxyOpt.AddAllowedClass(typeof(Polyline), true);//仅能选择多段线 PromptEntityResult plxyRes = ed.GetEntity(plxyOpt); if (plxyRes.Status != PromptStatus.OK) { return; } ObjectId plxyId = plxyRes.ObjectId; Polyline plxy = trans.GetObject(plxyId, OpenMode.ForWrite) as Polyline; //2.选择空间轴线的立面视图多段线 PromptEntityOptions plxzOpt = new PromptEntityOptions("\n选择空间轴线的立面视图多段线"); plxzOpt.SetRejectMessage("\n并非多段线!"); plxzOpt.AddAllowedClass(typeof(Polyline), true);//仅能选择多段线 PromptEntityResult plxzRes = ed.GetEntity(plxzOpt); if (plxzRes.Status != PromptStatus.OK) { return; } ObjectId plxzId = plxzRes.ObjectId; Polyline plxz = trans.GetObject(plxzId, OpenMode.ForWrite) as Polyline; //3.判断平面视图和立面视图中的长度是否一致 double lenXY = plxy.Length; double lenXZ = Math.Abs(plxz.StartPoint.X - plxz.EndPoint.X); if (Math.Abs(lenXY - lenXZ) > 10) { ed.WriteMessage("\n轴线平面长度与立面长度不一致,请检查!"); return; } double totalLen = lenXY;//记录轴线总长 //4.输入拟合直线段的长度 PromptDoubleOptions slOpt = new PromptDoubleOptions("\n输入拟合直线段的长度<1000>"); slOpt.AllowNegative = false; //不允许负值 slOpt.AllowZero = false; //不允许零值 slOpt.DefaultValue = 1000; //默认值为1000 PromptDoubleResult slRes = ed.GetDouble(slOpt); if (slRes.Status != PromptStatus.OK) { return; } double segLen = slRes.Value; //或得拟合线段长度 if (segLen > (totalLen - 10)) //节段过长(仅比总长小1cm或更长) { ed.WriteMessage("\n节段长度过长!"); return; } //5.获取每个节段点的坐标 //节段需要包括所有平面曲线节点、立面曲线节点和节段长度端点 List <Point3d> verts = new List <Point3d>();//初始化节段点List //5.1 添加平面曲线节点 for (int i = 0; i < plxy.NumberOfVertices; i++) { Point3d vertInPlxy = plxy.GetPoint3dAt(i); //平面图节点 double prmt = plxy.GetParameterAtPoint(vertInPlxy); //该节点参数 double distance = plxy.GetDistanceAtParameter(prmt); //该节点到起点距离,即为立面图上到起点的横坐标差 Point3d xlBase = plxz.StartPoint + new Vector3d(distance, 0, 0); //立面图起点偏移distance后,作为Xline基点 Xline xl = new Xline(); //新建xline xl.BasePoint = xlBase; //基点如前所述 xl.UnitDir = new Vector3d(0, 1, 0); //竖直方向 Point3dCollection ptIntersects = new Point3dCollection(); //建立交点组 plxz.IntersectWith(xl, Intersect.OnBothOperands, ptIntersects, IntPtr.Zero, IntPtr.Zero); //与立面轴线相交 Point3d vertInPlxz = ptIntersects[0]; //获得交点 //将节点添加至节点列表,X,Y坐标由平面图确定,Z坐标由立面图确定 Point3d vert = new Point3d(vertInPlxy.X, vertInPlxy.Y, vertInPlxz.Y - plxz.StartPoint.Y); verts.Add(vert); xl.Dispose(); } //5.2 添加立面曲线节点 for (int i = 1; i < plxz.NumberOfVertices - 1; i++) { Point3d vertInPlxz = plxz.GetPoint3dAt(i); //立面图节点 double distance = vertInPlxz.X - plxz.StartPoint.X; //该节点到起点距离,即为立面图上到起点的横坐标差 Point3d vertInPlxy = plxy.GetPointAtDist(distance); //获取该点在平面图上的对应点 //将节点添加至节点列表,X,Y坐标由平面图确定,Z坐标由立面图确定 Point3d vert = new Point3d(vertInPlxy.X, vertInPlxy.Y, vertInPlxz.Y - plxz.StartPoint.Y); if (!IsPtInList(vert, verts, 10))//如果该点尚不在点群中 { verts.Add(vert); } } //5.3 节段端点 double dist = segLen; do { Point3d vertInPlxy = plxy.GetPointAtDist(dist); //平面图节点 //立面图节点 Point3d xlBase = plxz.StartPoint + new Vector3d(dist, 0, 0); //立面图起点偏移dist后,作为Xline基点 Xline xl = new Xline(); //新建xline xl.BasePoint = xlBase; //基点如前所述 xl.UnitDir = new Vector3d(0, 1, 0); //竖直方向 Point3dCollection ptIntersects = new Point3dCollection(); //建立交点组 plxz.IntersectWith(xl, Intersect.OnBothOperands, ptIntersects, IntPtr.Zero, IntPtr.Zero); //与立面轴线相交 Point3d vertInPlxz = ptIntersects[0]; //获得交点 //将节点添加至节点列表,X,Y坐标由平面图确定,Z坐标由立面图确定 Point3d vert = new Point3d(vertInPlxy.X, vertInPlxy.Y, vertInPlxz.Y - plxz.StartPoint.Y); if (!IsPtInList(vert, verts, 10))//如果该点尚不在点群中 { verts.Add(vert); } dist += segLen; }while (dist < totalLen - 10);//前进长度小于总长度 //6.对所有节点进行排序 var sortedPts = (from pt in verts let p = plxy.GetParameterAtPoint(pt) let d = plxy.GetDistanceAtParameter(p) orderby d select pt).ToList(); //7.指定插入点 Point3d insertPt = new Point3d(); for (;;) { PromptPointOptions ptOpt = new PromptPointOptions("\n指定空间拟合段插入点"); PromptPointResult ptRes = ed.GetPoint(ptOpt); if (ptRes.Status == PromptStatus.OK) { insertPt = ptRes.Value; break; } } Vector3d vect = insertPt - plxy.StartPoint; //建立平移向量,从曲线平面图起点至选择的插入点 Matrix3d mt = Matrix3d.Displacement(vect); //建立对应的变换矩阵 //7.依次建立线段 for (int i = 0; i < sortedPts.Count - 1; i++) { Line line = new Line(sortedPts[i], sortedPts[i + 1]); line.TransformBy(mt); //平移到位 db.AddToModelSpace(line); //添加至模型空间 } trans.Commit();//执行事务处理 } }
private Autodesk.AutoCAD.Geometry.Point3d mSecondPoint; // Jig Factor #2 public XlineJig(Xline ent) : base(ent) { // Initialize and transform the Entity. Entity.SetDatabaseDefaults(); Entity.TransformBy(UCS); }
Entity[] MakeGouJian(Param param) { Point2d[] p2ds = new Point2d[] { Point2d.Origin, Point2d.Origin + Vector2d.YAxis * param.A, Point2d.Origin + Vector2d.YAxis * param.A - Vector2d.XAxis * param.D, Point2d.Origin + Vector2d.YAxis * param.B - Vector2d.XAxis * (param.C - param.E), Point2d.Origin + Vector2d.YAxis * param.B - Vector2d.XAxis * param.C, Point2d.Origin - Vector2d.XAxis * param.C }; Vector2d vec1 = p2ds[1] - p2ds[2]; Vector2d vec2 = p2ds[3] - p2ds[2]; //倒角 Point2d[] AnglePoint = GetAnglePoint(p2ds[2], vec1, vec2, 0.1); Vector2d vec3 = p2ds[0] - p2ds[1]; Vector2d vec4 = p2ds[2] - p2ds[1]; Point2d[] AnglePoint0 = GetAnglePoint(p2ds[1], vec3, vec4, 0.1); Polyline pline0 = EntityHelper.CreatePolygon( new double[] { p2ds[0].X, p2ds[0].Y, AnglePoint0[1].X, AnglePoint0[1].Y, AnglePoint0[0].X, AnglePoint0[0].Y, p2ds[1].X - param.D * 0.5, p2ds[1].Y, AnglePoint[1].X, AnglePoint[1].Y, AnglePoint[0].X, AnglePoint[0].Y, p2ds[3].X, p2ds[3].Y, p2ds[4].X, p2ds[4].Y, p2ds[5].X, p2ds[5].Y, }, new Tuple <int, double>[] { Tuple.Create(4, Math.Tan((Math.PI - vec2.GetAngleTo(vec1)) / 4)), Tuple.Create(1, Math.Tan((Math.PI - vec4.GetAngleTo(vec3)) / 4)) }, null, null ); AlignedDimension alignDim1 = new AlignedDimension(Point3d.Origin, Point3d.Origin + Vector3d.YAxis * param.A, Point3d.Origin + Vector3d.XAxis * 0.5, null, ObjectId.Null); AlignedDimension alignDim2 = new AlignedDimension(Point3d.Origin + Vector3d.YAxis * param.A, Point3d.Origin + Vector3d.YAxis * param.A - Vector3d.XAxis * param.D, Point3d.Origin + Vector3d.YAxis * 3.5, null, ObjectId.Null); AlignedDimension alignDim3 = new AlignedDimension(Point3d.Origin + Vector3d.YAxis * param.B - Vector3d.XAxis * (param.C - param.E), Point3d.Origin + Vector3d.YAxis * param.B - Vector3d.XAxis * param.C, Point3d.Origin + Vector3d.YAxis * (param.B + 0.5), null, ObjectId.Null); AlignedDimension alignDim4 = new AlignedDimension(Point3d.Origin + Vector3d.YAxis * param.B - Vector3d.XAxis * param.C, Point3d.Origin - Vector3d.XAxis * param.C, Point3d.Origin - Vector3d.XAxis * (param.C + 0.5), null, ObjectId.Null); AlignedDimension alignDim5 = new AlignedDimension(Point3d.Origin - Vector3d.XAxis * param.C, Point3d.Origin, Point3d.Origin - Vector3d.YAxis * 0.5, null, ObjectId.Null); LineAngularDimension2 langularDim = new LineAngularDimension2(new Point3d(p2ds[3].X, p2ds[3].Y, 0), new Point3d(p2ds[2].X, p2ds[2].Y, 0), new Point3d(p2ds[3].X, p2ds[3].Y, 0), new Point3d(p2ds[4].X, p2ds[4].Y, 0), new Point3d(p2ds[3].X - 0.8, p2ds[3].Y + 0.8, 0), null, ObjectId.Null ); Xline xline = new Xline() { BasePoint = new Point3d(0, param.A * 0.5, 0), UnitDir = Vector3d.XAxis }; DBText d1 = new DBText() { TextString = "A", Position = new Point3d(-0.15, param.A * 0.5, 0) }; HatchLoop hLoop = new HatchLoop(HatchLoopTypes.Polyline); foreach (var i in Enumerable.Range(0, pline0.NumberOfVertices)) { hLoop.Polyline.Add(new BulgeVertex(pline0.GetPoint2dAt(i), pline0.GetBulgeAt(i))); } Hatch hatch = new Hatch(); hatch.SetHatchPattern(HatchPatternType.PreDefined, "BOX"); hatch.AppendLoop(hLoop); return(new Entity[] { pline0, alignDim1, alignDim2, alignDim3, alignDim4, alignDim5, d1, hatch, langularDim, xline }); }
public void Bisector() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; PromptEntityOptions peo = new PromptEntityOptions("\nSelect the first line: "); peo.SetRejectMessage("Selected object is not a line !"); peo.AddAllowedClass(typeof(Line), true); PromptEntityResult per = ed.GetEntity(peo); if (per.Status != PromptStatus.OK) { return; } Point3d p1 = per.PickedPoint.TransformBy(ed.CurrentUserCoordinateSystem); ObjectId id1 = per.ObjectId; peo.Message = "\nSelect the second line: "; per = ed.GetEntity(peo); if (per.Status != PromptStatus.OK) { return; } Point3d p2 = per.PickedPoint.TransformBy(ed.CurrentUserCoordinateSystem); ObjectId id2 = per.ObjectId; using (Transaction tr = db.TransactionManager.StartTransaction()) { Line l1 = (Line)tr.GetObject(id1, OpenMode.ForRead); Line l2 = (Line)tr.GetObject(id2, OpenMode.ForRead); // Checks if lines intersect Plane plane; Line3d line1 = new Line3d(l1.StartPoint, l1.EndPoint); Line3d line2 = new Line3d(l2.StartPoint, l2.EndPoint); if (!line1.IsCoplanarWith(line2, out plane) || line1.IsParallelTo(line2)) { return; } // Calculates the bisector Point3d inters = line1.IntersectWith(line2)[0]; Vector3d vec1 = line1.Direction; Vector3d vec2 = line2.Direction; // Corrects the vectors direction according to picked points if (vec1.DotProduct(inters.GetVectorTo(p1)) < 0) { vec1 = vec1.Negate(); } if (vec2.DotProduct(inters.GetVectorTo(p2)) < 0) { vec2 = vec2.Negate(); } Vector3d bisectDir = (vec1 + vec2) / 2.0; // Draws the bisector (XLine) Xline xline = new Xline(); xline.UnitDir = bisectDir.GetNormal(); xline.BasePoint = inters; BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite); btr.AppendEntity(xline); tr.AddNewlyCreatedDBObject(xline, true); tr.Commit(); } }
private void CreateHelpLine(string lineType) { Xline helpLine = new Xline(); Xline helpLineCross = new Xline(); if (string.IsNullOrEmpty(lineType) || string.IsNullOrWhiteSpace(lineType)) { return; } ObjectId layerHelp = _drawingHelper.LayerManipulator.CreateLayer("HELP", System.Drawing.Color.Gray); var basePointResult = _editorHelper.PromptForPoint("Pick insertion point :"); if (basePointResult.Status != PromptStatus.OK) { return; } helpLine.BasePoint = basePointResult.Value; // detect the selected line type switch (lineType) { case "Horizontal": helpLine.UnitDir = Vector3d.XAxis; break; case "Vertical": helpLine.UnitDir = Vector3d.YAxis; break; case "Crossed": helpLine.UnitDir = Vector3d.YAxis; helpLineCross.BasePoint = helpLine.BasePoint; helpLineCross.UnitDir = Vector3d.XAxis; break; case "Angular": var directinPointResult = _editorHelper.PromptForPoint("Pick direction point :"); if (directinPointResult.Status != PromptStatus.OK) { return; } helpLine.UnitDir = new Vector3d(helpLine.BasePoint.X - directinPointResult.Value.X, helpLine.BasePoint.Y - directinPointResult.Value.Y, helpLine.BasePoint.Z - directinPointResult.Value.Z); break; case "Deg45": Vector3d Vector45 = new Vector3d(5, 5, 0); helpLine.UnitDir = Vector45; break; } try { using (Transaction transaction = _doc.Database.TransactionManager.StartTransaction()) { // open current space (model space in our case) for write BlockTableRecord btr = (BlockTableRecord)transaction.GetObject(_doc.Database.CurrentSpaceId, OpenMode.ForWrite); // set Xline Layer helpLine.SetLayerId(layerHelp, false); Matrix3d mat = _editorHelper.CurrentUcs; helpLine.TransformBy(mat); btr.AppendEntity(helpLine); // add the Xline to the transaction transaction.AddNewlyCreatedDBObject(helpLine, true); if ((lineType == "Crossed")) { // set Xline Layer helpLineCross.TransformBy(mat); helpLineCross.SetLayerId(layerHelp, false); btr.AppendEntity(helpLineCross); // add the Xline to the transaction transaction.AddNewlyCreatedDBObject(helpLineCross, true); } transaction.Commit(); } } catch (Exception exception) { _logger.Error("Help Line error", exception); } }