/// <summary> /// 通过限定分段长度来对多段线变稀或者变密(保留首尾两个点) /// </summary> /// <param name="cs"></param> /// <param name="segLength">每一分段的长度</param> /// <returns></returns> public static CompositeCurve3d GetThinedPolyline(Curve3d cs, double segLength) { var startPara = cs.GetParameterOf(cs.StartPoint); var endPara = cs.GetParameterOf(cs.EndPoint); var startPt = cs.StartPoint; var endPt = startPt; var para = startPara; // var segCount = (int)Math.Ceiling((endPara - startPara) / segLength); var lines = new Curve3d[segCount]; // 最后一段的间距不由 segLength 控制 for (int i = 0; i < segCount - 1; i++) { para += segLength; endPt = cs.EvaluatePoint(para); // lines[i] = new LineSegment3d(startPt, endPt); // startPt = endPt; } // 处理最后一段曲线 lines[segCount - 1] = new LineSegment3d(startPt, cs.EndPoint); // return(new CompositeCurve3d(lines)); }
static ObjectId GetCurveObjectId(Curve3d geCurve3d) { Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; Database db = doc.Database; ObjectId oid = ObjectId.Null; try { Curve dbCurve = Curve.CreateFromGeCurve(geCurve3d); if (dbCurve != null) { using (Transaction tr = db.TransactionManager.StartTransaction()) { BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable; BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord; btr.AppendEntity(dbCurve); tr.AddNewlyCreatedDBObject(dbCurve, true); tr.Commit(); } } } catch (System.Exception ex) { ed.WriteMessage(ex.Message); } return(oid); }
public static bool IsPointOnPolyline([NotNull] this Polyline pl, Point3d pt) { var isOn = false; var ptZeroZ = new Point3d(pt.X, pt.Y, pl.Elevation); for (var i = 0; i < pl.NumberOfVertices; i++) { Curve3d seg = null; var segType = pl.GetSegmentType(i); if (segType == SegmentType.Arc) { seg = pl.GetArcSegmentAt(i); } else if (segType == SegmentType.Line) { seg = pl.GetLineSegmentAt(i); } if (seg != null) { isOn = seg.IsOn(ptZeroZ); if (isOn) { break; } } } return(isOn); }
//расчитать расстояние до коробки от полилинии с помощью API AutoCAD private double DistanceFromPolyToTxtBox(Polyline poly, TextPosition txtPos) { Point2d maxPt = new Point2d(txtPos.Envelope.MaxX, txtPos.Envelope.MaxY); Point2d minPt = new Point2d(txtPos.Envelope.MinX, txtPos.Envelope.MinY); //хотябы одна точка полилинии находится внутри коробки? (возможен случай когда вся полилиния внутри коробки) for (int i = 0; i < poly.NumberOfVertices; i++) { if (Utils.PointInsideBoundingBox(maxPt, minPt, poly.GetPoint2dAt(i))) { return(0); } } Curve3d polyGeCurve = poly.GetGeCurve(); //полилиния пересекает коробку? ЭТО ИЗЛИШНЕ //CurveCurveIntersector3d intersector = new CurveCurveIntersector3d(polyGeCurve, txtPos.BoxCurve, Vector3d.ZAxis); //if (intersector.NumberOfIntersectionPoints>0) //{ // return 0; //} //тогда найти расстояние между кривыми return(polyGeCurve.GetDistanceTo(txtPos.BoxCurve)); }
/// <summary> /// TODO /// </summary> /// <param name="nat"></param> /// <param name="axis"></param> /// <returns></returns> private Vector3d GetTangent(Curve3d nat, Axis axis) { var vec = new Vector3d(); try { if (nat is LinearEntity3d || nat.IsClosed()) { vec = axis.ToVector(); } else if (nat.StartPoint == axis.Start || nat.EndPoint == axis.Start) { using (var curved = nat.GetClosestPointTo(axis.Start)) { vec = curved.GetDerivative(1).GetNormal() * axis.Length; } using (var curved2 = nat.GetClosestPointTo(axis.Start + vec)) { if (curved2.Point.IsEqualTo(axis.Start)) { vec = vec.Negate(); } } } } catch (Exception e) { Console.WriteLine(e); MailAgent.Report(e.Message); } return(vec); }
static private Curve GenCurve(Curve3d crv3d) { Tolerance tol = new Tolerance(); ExternalCurve3d extCrv = crv3d as ExternalCurve3d; Line3d ln3d; if (extCrv.IsLinear(out ln3d)) { Line ln = new Line(crv3d.StartPoint, crv3d.EndPoint); return(ln); } else { Double per; KnotCollection kc; NurbCurve3d nc3d = extCrv.NativeCurve as NurbCurve3d; kc = nc3d.Knots; Double[] dblKnots = new Double[kc.Count]; kc.CopyTo(dblKnots, 0); DoubleCollection dc = new DoubleCollection(dblKnots); NurbCurve3dData nc3dData = nc3d.DefinitionData; return(new Spline(nc3d.Degree, nc3d.IsRational, nc3d.IsClosed(), nc3d.IsPeriodic(out per), nc3dData.ControlPoints, dc, nc3dData.Weights, tol.EqualPoint, tol.EqualVector)); } }
public Curve3d GetGeCurve(Tolerance tolerance) { createInstance(); Curve3d GetGeCur = BaseCurve.GetGeCurve(tolerance); tr.Dispose(); return GetGeCur; }
public static bool IsPointOnPolyline(Polyline pl, Point3d pt) { bool isOn = false; for (int i = 0; i < pl.NumberOfVertices; i++) { Curve3d seg = null; SegmentType segType = pl.GetSegmentType(i); if (segType == SegmentType.Arc) { seg = pl.GetArcSegmentAt(i); } else if (segType == SegmentType.Line) { seg = pl.GetLineSegmentAt(i); } if (seg != null) { isOn = seg.IsOn(pt); if (isOn) { break; } } } return(isOn); }
public Curve3d GetGeCurve() { createInstance(); Curve3d GetGeCur = BaseCurve.GetGeCurve(); tr.Dispose(); return(GetGeCur); }
public static IEnumerable <DistanceBetween2PolylinesSectionResult> CalculateDistanceBetween3dPolylines(Database database, ObjectId pl1Id, ObjectId pl2Id) { Curve3d curve1, curve2 = null; int polyline1EndParam; Point3d[] parameterListPoints = null; double[] parameterListLength = null; using (Transaction transAction = database.TransactionManager.StartTransaction()) { object objectX1 = transAction.GetObject(pl1Id, OpenMode.ForRead); object objectX2 = transAction.GetObject(pl2Id, OpenMode.ForRead); //Get a list of 3D points in parameter order using (Polyline3d pl1 = (Polyline3d)objectX1) using (Polyline3d pl2 = (Polyline3d)objectX2) { // We get curve here, its faster to get the parameters and // point on a non database object curve1 = pl1.GetGeCurve(new Tolerance(1e-10, 1e-10)); curve2 = pl2.GetGeCurve(new Tolerance(1e-10, 1e-10)); polyline1EndParam = (int)pl1.EndParam; parameterListPoints = new Point3d[polyline1EndParam + 1]; parameterListLength = new double[polyline1EndParam + 1]; for (int y = 0; y <= polyline1EndParam; y++) { parameterListPoints[y] = pl1.GetPointAtParameter(y); parameterListLength[y] = pl1.GetDistanceAtParameter(y); } } // Initialize list with dimensions specified (speed) DistanceBetween2PolylinesSectionResult[] arrRes = new DistanceBetween2PolylinesSectionResult[polyline1EndParam + 1]; //for (int i = 0; i <= polyline1EndParam; i++) Parallel.For(0, polyline1EndParam + 1, (i) => { Point3d pointOnCurve1, pointOnCurve2; lock (_curveLock) { pointOnCurve1 = parameterListPoints[i]; pointOnCurve2 = curve2.GetClosestPointTo(pointOnCurve1).Point; } // Add result to array lock (_arrayLock) arrRes[i] = new DistanceBetween2PolylinesSectionResult( parameterListLength[i], pointOnCurve1.Z - pointOnCurve2.Z, pointOnCurve1.T2d().GetDistanceTo(pointOnCurve2.T2d()), pointOnCurve1.DistanceTo(pointOnCurve2), pointOnCurve1, pointOnCurve2); }); transAction.Commit(); return(arrRes); } }
private Drawable GetDrawable(Curve3d curve) { // We could support multiple curve types here, but for // now let's just return a line approximating it Line ln = new Line(curve.StartPoint, curve.EndPoint); ln.ColorIndex = 1; return(ln); }
public override IEnumerable <Autodesk.DesignScript.Interfaces.IGraphicItem> GetDynGeometry() { IList <Autodesk.DesignScript.Interfaces.IGraphicItem> ret = new List <Autodesk.DesignScript.Interfaces.IGraphicItem>(); lock (access_obj) { using (var ctx = new SteelServices.DocContext()) { var myGrid = Utils.GetObject(Handle) as Autodesk.AdvanceSteel.Modelling.Grid; Matrix3d gridCS = myGrid.CS; Vector3d xVect = null; Vector3d yVect = null; Vector3d ZVect = null; Point3d origin = null; gridCS.GetCoordSystem(out origin, out xVect, out yVect, out ZVect); Autodesk.AdvanceSteel.Modelling.GridElement[] gridEles = null; myGrid.GetAllElements(out gridEles); foreach (var item in gridEles) { Curve3d curve = null; item.GetCurve(ref curve, gridCS); if (curve != null) { Point3d sp = null; Point3d ep = null; if (curve.HasStartPoint(out sp)) { if (curve.HasEndPoint(out ep)) { var line1 = Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(Utils.ToDynPoint(sp, true), Utils.ToDynPoint(ep, true)); ret.Add(line1); } } } } } } return(ret); }
private double DistanceFromPolyToTxtBox(Polyline poly, TextPosition txtPos) { Point2d maxPt = new Point2d(txtPos.Envelope.MaxX, txtPos.Envelope.MaxY); Point2d minPt = new Point2d(txtPos.Envelope.MinX, txtPos.Envelope.MinY); //хотябы одна точка полилинии находится внутри коробки? (возможен случай когда вся полилиния внутри коробки) for (int i = 0; i < poly.NumberOfVertices; i++) { if (Utils.PointInsideBoundingBox(maxPt, minPt, poly.GetPoint2dAt(i))) { return(0); } } Curve3d polyGeCurve = poly.GetGeCurve(); //тогда найти расстояние между кривыми return(polyGeCurve.GetDistanceTo(txtPos.BoxCurve)); }
public ICurve CurveToSpeckle(Curve3d curve) { if (curve.IsPlanar(out AC.Plane pln)) { if (curve.IsPeriodic(out double period) && curve.IsClosed()) { } if (curve.IsLinear(out Line3d line)) // defaults to polyline { if (null != line) { return(LineToSpeckle(line)); } } } return(NurbsToSpeckle(curve as NurbCurve3d)); }
public ICurve CurveToSpeckle(Curve3d curve, string units = null) { var u = units ?? ModelUnits; // note: some curve3ds may not have endpoints! Not sure what contexts this may occur in, might cause issues later. switch (curve) { case Line3d line: return(LineToSpeckle(line)); case LineSegment3d line: return(LineToSpeckle(line)); case CircularArc3d arc: return(ArcToSpeckle(arc)); default: return(NurbsToSpeckle(curve as NurbCurve3d)); } }
public override Vector3 InterpolatedPoint(float t) { var point = (points.Count - 1) * t; var intPoint = Mathf.Floor(point); var weight = point - intPoint; var c0 = intPoint == 0 ? intPoint : intPoint - 1; var c1 = intPoint; var c2 = intPoint > points.Count - 2 ? points.Count - 1 : intPoint + 1; var c3 = intPoint > points.Count - 3 ? points.Count - 1 : intPoint + 2; var pt0 = points[c0]; var pt1 = points[c1]; var pt2 = points[c2]; var pt3 = points[c3]; var x = Curve3d.InterpolateCatmullRom(pt0.x, pt1.x, pt2.x, pt3.x, weight); var y = Curve3d.InterpolateCatmullRom(pt0.y, pt1.y, pt2.y, pt3.y, weight); var z = Curve3d.InterpolateCatmullRom(pt0.z, pt1.z, pt2.z, pt3.z, weight); return(new Vector3(x, y, z)); }
public override Vector3 InterpolatedPoint(float t) { var point = (points.Count - 0) * t; // This needs to be from 0-length +1 var intPoint = Mathf.Floor(point); var weight = point - intPoint; intPoint += intPoint > 0 ? 0 : (Mathf.Floor(Mathf.Abs(intPoint) / points.Count) + 1) * points.Count; var c0 = points[(intPoint - 1) % points.Count]; var c1 = points[(intPoint) % points.Count]; var c2 = points[(intPoint + 1) % points.Count]; var c3 = points[(intPoint + 2) % points.Count]; var x = Curve3d.InterpolateCatmullRom(c0.x, c1.x, c2.x, c3.x, weight); var y = Curve3d.InterpolateCatmullRom(c0.y, c1.y, c2.y, c3.y, weight); var z = Curve3d.InterpolateCatmullRom(c0.z, c1.z, c2.z, c3.z, weight); return(new Vector3(x, y, z)); }
public static DBObjectCollection IntersectSurf(Autodesk.AutoCAD.DatabaseServices.Surface surf1, Autodesk.AutoCAD.DatabaseServices.Surface surf2) { Brep surfBrep1 = new Brep(surf1); Brep surfBrep2 = new Brep(surf2); SurfaceSurfaceIntersector ssi = new SurfaceSurfaceIntersector(); DBObjectCollection dboCol = new DBObjectCollection(); foreach (Autodesk.AutoCAD.BoundaryRepresentation.Face fc1 in surfBrep1.Faces) { ExternalBoundedSurface[] ebSurfs1 = fc1.GetSurfaceAsTrimmedNurbs(); Autodesk.AutoCAD.Geometry.Surface sur1 = ebSurfs1[0]; foreach (Autodesk.AutoCAD.BoundaryRepresentation.Face fc2 in surfBrep2.Faces) { ExternalBoundedSurface[] ebSurfs2 = fc2.GetSurfaceAsTrimmedNurbs(); Autodesk.AutoCAD.Geometry.Surface sur2 = ebSurfs2[0]; ssi.Set(sur1, sur2); if (ssi.NumResults < 1) { break; } for (int i = 0; i < ssi.NumResults; i++) { Curve3d c3d = ssi.IntersectCurve(i, true); Curve crv = GenCurve(c3d); crv.SetDatabaseDefaults(); crv.Color = Color.FromRgb(255, 255, 255); dboCol.Add(crv); ////adding for now need instead to conver to single Spline //BlockTableRecord btr = (BlockTableRecord)(trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)); //btr.AppendEntity(crv); //trans.AddNewlyCreatedDBObject(crv, true); } } } return(dboCol); }
/// <summary> /// Полилиния пересекает сама себя /// </summary> /// <param name="poly"></param> /// <returns></returns> public static bool PolylineIsSelfIntersecting(Polyline poly) { Curve3d curve3D = poly.GetGeCurve(); CurveCurveIntersector3d intersector = new CurveCurveIntersector3d(curve3D, curve3D, Vector3d.ZAxis); return(intersector.NumberOfIntersectionPoints > 0); /* * Dictionary<Point3d, int?> polyPts = new Dictionary<Point3d, int?>(); * int vertCount = poly.NumberOfVertices; * for (int i = 0; i < vertCount; i++) * { * Point3d pt3d = poly.GetPoint3dAt(i); * //Если точки повторяются, то есть самопересечение * //Но допускается повторение первой и последней точек * int? existPtNum = null; * polyPts.TryGetValue(pt3d, out existPtNum); * if (existPtNum == null//Такой точки не было || (i == vertCount - 1 && existPtNum == 0))//Такая тока была, но это замыкание, а не самопересечение || { || polyPts[pt3d] = i; || } || else || return true; ||} ||//Использование метода IntersectWith ||Point3dCollection intersectionPts = new Point3dCollection(); ||poly.IntersectWith(poly, Intersect.OnBothOperands, intersectionPts, IntPtr.Zero, IntPtr.Zero); || ||foreach (Point3d intersectionPt in intersectionPts) ||{ || if (!polyPts.ContainsKey(intersectionPt)) || { || return true; || } ||} || ||return false; */ }
public static Vector3d GetNormal(this Curve3d curve) { if (curve is ExternalCurve3d) { using (var extCurve = curve as ExternalCurve3d) { using (var natCurve = extCurve.NativeCurve) { return(natCurve.GetNormal()); } } } if (curve is LinearEntity3d) { return(new Vector3d()); } if (curve is CircularArc3d) { return(((CircularArc3d)curve).Normal); } if (curve is EllipticalArc3d) { return(((EllipticalArc3d)curve).Normal); } var samplePoints = curve.GetSamplePoints(4); var vectorTo = samplePoints[1].Point.GetVectorTo(samplePoints[0].Point); var v = samplePoints[1].Point.GetVectorTo(samplePoints[2].Point); if (!vectorTo.IsLessThanTol() && !v.IsLessThanTol() && !vectorTo.IsParallelTo(v, CalcTol.CadTolerance)) { return(vectorTo.CrossProduct(v)); } return(new Vector3d()); }
public void SetFromGeCurve(Curve3d geCurve, Vector3d __unnamed001, Tolerance tolerance) { createInstance(); BaseCurve.SetFromGeCurve(geCurve, __unnamed001, tolerance); tr.Dispose(); }
/// <summary> 将给定的线性多段线的段数变稀 </summary> /// <param name="cs">用来变稀的那条比较密的多段线几何,集合中的曲线必须首尾相连</param> /// <param name="segPoints">每隔多少个点取用一个,比如2表示只取源多段线中的第1、3、5、7 ... 个点</param> /// <param name="includeAllNonlinear"> true 表示保留所有的曲线段,只将直线段的顶点变疏;false 表示不管是曲线段还是直线段,最终都按顶点坐标转换为直线段 </param> /// <returns></returns> public static CompositeCurve3d GetThinedPolyline(Curve3d[] cs, int segPoints, bool includeAllNonlinear) { Point3d startPt = cs[0].StartPoint; Point3d endPt; var curves = new List <Curve3d>(); Curve3d c = null; var n = cs.Length; var id = 1; if (includeAllNonlinear) { // 保留所有的曲线段,只将直线段的顶点变疏 for (var i = 0; i < n; i++) { c = cs[i]; if (c is LineSegment3d) { if (id % segPoints == 0) { // 说明到了关键点 endPt = c.EndPoint; curves.Add(new LineSegment3d(startPt, endPt)); startPt = endPt; } id += 1; } else { if (id > 1) { // 说明中间有直线段 endPt = c.StartPoint; curves.Add(new LineSegment3d(startPt, endPt)); } else { // 说明前一段也是曲线 } // 强制性添加上这一段曲线 curves.Add(c); startPt = c.EndPoint; id = 1; } } } else { // 不管是曲线段还是直线段,最终都按顶点坐标转换为直线段 for (var i = 0; i < n; i++) { c = cs[i]; if (id % segPoints == 0) { // 说明到了关键点 endPt = c.EndPoint; curves.Add(new LineSegment3d(startPt, endPt)); startPt = endPt; } id += 1; } } // 强制补上最后一个可能漏掉的直线段 if (c != null && startPt != c.EndPoint) { curves.Add(new LineSegment3d(startPt, c.EndPoint)); } return(new CompositeCurve3d(curves.ToArray())); }
public void fitPolyline(double tolerance, bool delSoursePL) { List <Point3d> Vert = new List <Point3d>(); List <Point3d> delVert = new List <Point3d>(); Vert = this.listVertecs(plineGetFromUser); if (this.closeAndDuplicateVertex == false && plineGetFromUser.Polyline.ClosedLogically == true) { for (uint i = 0; i < plineGetFromUser.Polyline.Segments.Count; i++) { Curve3d oneSegment = plineGetFromUser.Polyline.Segments.GetSegAt(i, true); int j = Convert.ToInt32(i); if (j == plineGetFromUser.Polyline.Segments.Count - 1 && oneSegment.Length(0, 1) < tolerance) // дописать логику. что делать если последний сегмент замкнутой поллинии короткий? { } else if (oneSegment.Length(0, 1) < tolerance) { delVert.Add(Vert[j + 1]); } } } else { for (uint i = 0; i < plineGetFromUser.Polyline.Segments.Count; i++) { Curve3d oneSegment = plineGetFromUser.Polyline.Segments.GetSegAt(i, true); int j = Convert.ToInt32(i); if (oneSegment.Length(0, 1) < tolerance) { delVert.Add(Vert[j + 1]); } } } List <Point3d> resultVertex = new List <Point3d>(); if (delVert.Count == 0) { MessageBox.Show("Коротких сегментов не найдено"); return; } else if (delVert.Count == Vert.Count - 1)// в случае если все сегменты меньше заданного значения -соединяем первую и последнюю точку { resultVertex.Add(plineGetFromUser.Polyline.Points.FirstPoint); resultVertex.Add(plineGetFromUser.Polyline.Points.LastPoint); } else { var result = Vert.Except(delVert);// на LINQ с помощью метода Except можно получить разность двух множеств foreach (var item in result) { Point3d PointForList = new Point3d(item.X, item.Y, item.Z); resultVertex.Add(PointForList); } } Polyline3d PL3dFited = new Polyline3d(resultVertex); if (plineGetFromUser.Polyline.ClosedLogically == true) { PL3dFited.SetClosed(true); } if (delSoursePL == true)// проверка удалять ли исходную Pl - чекбокс в форме { plineGetFromUser.DbEntity.Erase(); } plineGetFromUser = PL3dFited; plineGetFromUser.DbEntity.AddToCurrentDocument(); }
public void SurfInt() { Database db = HostApplicationServices.WorkingDatabase; Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; ObjectId ObjID; using (Transaction trans = db.TransactionManager.StartTransaction()) { try { Autodesk.AutoCAD.DatabaseServices.Surface surf1; Autodesk.AutoCAD.DatabaseServices.Surface surf2; SurfGeomConstruct sgc1; SurfGeomConstruct sgc2; PromptEntityOptions peo = new PromptEntityOptions("Select first surface for intersection: "); peo.SetRejectMessage("\nPlease select only a Surface"); peo.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Surface), false); PromptEntityResult per = ed.GetEntity(peo); if (per.Status != PromptStatus.OK) { return; } ObjID = per.ObjectId; surf1 = (Autodesk.AutoCAD.DatabaseServices.Surface)trans.GetObject(ObjID, OpenMode.ForRead, false); surf1.Highlight(); peo.Message = "Select intersecting surface: "; per = ed.GetEntity(peo); if (per.Status != PromptStatus.OK) { return; } surf1.Unhighlight(); sgc1 = new SurfGeomConstruct(surf1); ObjID = per.ObjectId; surf2 = (Autodesk.AutoCAD.DatabaseServices.Surface)trans.GetObject(ObjID, OpenMode.ForRead, false); sgc2 = new SurfGeomConstruct(surf2); SurfaceSurfaceIntersector ssi = new SurfaceSurfaceIntersector(); //ssi.Set(sgc1.GeomSurf, sgc2.GeomSurf); //int count = ssi.NumResults; //if (count < 1) return; BlockTableRecord btr = (BlockTableRecord)(trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite)); //for (int i = 0; i < count; i++) //{ // Curve3d c3d = ssi.IntersectCurve(i, true); // Curve crv = GenCurve(c3d); // crv.SetDatabaseDefaults(); // btr.AppendEntity(crv); // trans.AddNewlyCreatedDBObject(crv, true); //} Brep surfBrep1 = new Brep(surf1); Brep surfBrep2 = new Brep(surf2); foreach (Autodesk.AutoCAD.BoundaryRepresentation.Face fc1 in surfBrep1.Faces) { ExternalBoundedSurface[] ebSurfs1 = fc1.GetSurfaceAsTrimmedNurbs(); Autodesk.AutoCAD.Geometry.Surface sur1 = ebSurfs1[0]; foreach (Autodesk.AutoCAD.BoundaryRepresentation.Face fc2 in surfBrep2.Faces) { ExternalBoundedSurface[] ebSurfs2 = fc2.GetSurfaceAsTrimmedNurbs(); Autodesk.AutoCAD.Geometry.Surface sur2 = ebSurfs2[0]; ssi.Set(sur1, sur2); if (ssi.NumResults < 1) { break; } for (int i = 0; i < ssi.NumResults; i++) { Curve3d c3d = ssi.IntersectCurve(i, true); Curve crv = GenCurve(c3d); crv.SetDatabaseDefaults(); btr.AppendEntity(crv); trans.AddNewlyCreatedDBObject(crv, true); } } } if (ssi != null) { ssi.Dispose(); } if (sgc1.GeomSurf != null) { sgc1.GeomSurf.Dispose(); } if (sgc2.GeomSurf != null) { sgc2.GeomSurf.Dispose(); } } catch (System.Exception ex) { ed.WriteMessage("Error: " + ex.Message); } finally { trans.Commit(); } } }
public void SetFromGeCurve(Curve3d geCurve, Tolerance tolerance) { createInstance(); BaseCurve.SetFromGeCurve(geCurve, tolerance); tr.Dispose(); }
/// <summary> /// 중심점 구하기 /// </summary> /// <param name="C"></param> /// <returns></returns> public static Point3d GetCenterP(Curve3d C) { return(GetCenterP(C.StartPoint, C.EndPoint)); }
public static Line GetOrthoNormalLine(this Polyline pline, Point3d point, Plane plane = null, bool nullForOutOfRange = true) { point = point.OrthoProject(pline.GetPlane()); Point3d?normalPoint = pline.GetOrthoNormalPoint(point, null, nullForOutOfRange); if (!normalPoint.HasValue) { return(null); } else if (nullForOutOfRange) { return(new Line(normalPoint.Value, point)); } int param = 0; try { if (normalPoint.Value.IsEqualTo(pline.EndPoint, Tolerance.Global)) { param = (int)pline.EndParam; } else if (normalPoint.Value.IsEqualTo(pline.StartPoint, Tolerance.Global)) { param = (int)pline.StartParam; } else { param = (int)pline.GetParameterAtPoint(normalPoint.Value); } } catch { return(new Line(normalPoint.Value, point)); } var sType = pline.GetSegmentType(param); while (sType != SegmentType.Line && sType != SegmentType.Arc) { if (--param < pline.StartParam) { throw new ArgumentException(); } sType = pline.GetSegmentType(param); } Curve3d segment = sType == SegmentType.Line ? (Curve3d)pline.GetLineSegmentAt(param) : (Curve3d)pline.GetArcSegmentAt(param); if (segment is LineSegment3d) { return(((LineSegment3d)segment).ConvertToLine().GetOrthoNormalLine(point, plane, false)); } else if (segment is CircularArc3d) { return(((CircularArc3d)segment).ConvertToArc().GetOrthoNormalLine(point, false)); } else { throw new ArgumentException(); } }
makePipeNetwork(ObjectId idAlign, string nameNetwork, string pipeType) { string pntDesc = fMNP.pntDesc; Point3d pnt3dPick = Pub.pnt3dO; if (idAlign == ObjectId.Null) { Autodesk.AutoCAD.DatabaseServices.Entity ent = Select.selectEntity(typeof(Alignment), "Select Alignment: ", "Selected object was not an alignment. Try again: ", out pnt3dPick); idAlign = ent.ObjectId; } Network net = null; ObjectIdCollection ids = CivilApplication.ActiveDocument.GetPipeNetworkIds(); ObjectId idNet = ObjectId.Null; if (ids.Count == 0) { idNet = Network.Create(CivilApplication.ActiveDocument, ref nameNetwork); } else { for (int i = 0; i < ids.Count; i++) { net = (Network)ids[i].getEnt(); //if (net.Name == nameNetwork){ // string index = Align.getAlignIndex(nameNetwork); // nameNetwork = string.Format("{0}-{1}", nameNetwork, index); // break; //} } idNet = Network.Create(CivilApplication.ActiveDocument, ref nameNetwork); } bool exists = false; Alignment align = (Alignment)idAlign.getEnt(); AlignmentEntityCollection ents = align.Entities; TinSurface tinSurfDE = Surf.getTinSurface("CPNT-ON", out exists); List <AlgnEntData> algnData = MNP_Align.sortAlignEnts(align); List <string> hPipe = new List <string>(); List <ObjectId> idsCgPnt = new List <ObjectId>(); ObjectId idPipe, idPipeSize, idStruct, idStructSize; using (Transaction tr = BaseObjs.startTransactionDb()) { net = (Network)tr.GetObject(idNet, OpenMode.ForWrite); net.ReferenceAlignmentId = idAlign; net.ReferenceSurfaceId = Surf.getTinSurface("CPNT-ON", out exists).ObjectId; ObjectId idPartsList = CivilApplication.ActiveDocument.Styles.PartsListSet["Standard"]; PartsList partsList = (PartsList)tr.GetObject(idPartsList, OpenMode.ForRead); idPipe = partsList["Concrete Pipe"]; PartFamily partFamily = (PartFamily)tr.GetObject(idPipe, OpenMode.ForWrite); idPipeSize = partFamily[0]; PartSize partSize = (PartSize)tr.GetObject(idPipeSize, OpenMode.ForRead); PartDataRecord pdr = partSize.SizeDataRecord; PartDataField[] pdf = pdr.GetAllDataFields(); for (int i = 0; i < pdf.Length; i++) { System.Diagnostics.Debug.Print(string.Format("{0}: {1}", pdf[i].Description, pdf[i].Value.ToString())); } idStruct = partsList["Rectangular Structure Slab Top Rectangular Frame"]; partFamily = (PartFamily)tr.GetObject(idStruct, OpenMode.ForWrite); idStructSize = partFamily[0]; double depth = -6, slope = 0, dZ = 0, top = 0; double diam = double.Parse(pdf[0].Value.ToString()) / 12; ObjectId idPipeNew = ObjectId.Null; AlignmentEntity ent = null; Structure sPrev = null; uint pntNum = 0; ObjectId idCgPntBeg, idCgPntEnd, idCgPntPrev = ObjectId.Null; TypedValue[] tvs; for (int i = 0; i < algnData.Count; i++) { if (algnData.Count == 1) { ent = ents[0]; } else { ent = ents.EntityAtId(algnData[i].ID); } ObjectId idStructNew = ObjectId.Null; Structure s = null; Pipe p = null; if (ent.EntityType == AlignmentEntityType.Line) { AlignmentLine line = (AlignmentLine)ent; Point2d pnt2dBeg = line.StartPoint; Point2d pnt2dEnd = line.EndPoint; try { top = tinSurfDE.FindElevationAtXY(pnt2dBeg.X, pnt2dBeg.Y) + depth; } catch (System.Exception) { Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Pipe endpoint is beyond limit of design surface"); return; } Point3d pnt3dBeg = new Point3d(pnt2dBeg.X, pnt2dBeg.Y, top); try { top = tinSurfDE.FindElevationAtXY(pnt2dEnd.X, pnt2dEnd.Y) + depth; } catch (System.Exception) { Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Pipe endpoint is beyond limit of design surface"); return; } Point3d pnt3dEnd = new Point3d(pnt2dEnd.X, pnt2dEnd.Y, top); LineSegment3d seg3d = new LineSegment3d(pnt3dBeg, pnt3dEnd); net.AddLinePipe(idPipe, idPipeSize, seg3d, ref idPipeNew, true); p = (Pipe)idPipeNew.getEnt(); p.AddToProfileView(fMNP.idProfileView); ObjectId idPart = getProfileViewPart(); slope = pnt3dBeg.getSlope(pnt3dEnd); dZ = diam / (2 * (System.Math.Cos(System.Math.Atan(System.Math.Abs(slope))))); if (i == 0) { pnt3dBeg = new Point3d(pnt3dBeg.X, pnt3dBeg.Y, pnt3dBeg.Z - dZ); pnt3dEnd = new Point3d(pnt3dEnd.X, pnt3dEnd.Y, pnt3dEnd.Z - dZ); idCgPntBeg = pnt3dBeg.setPoint(out pntNum, pntDesc); idsCgPnt.Add(idCgPntBeg); idCgPntEnd = pnt3dEnd.setPoint(out pntNum, pntDesc); idsCgPnt.Add(idCgPntEnd); idCgPntPrev = idCgPntEnd; tvs = new TypedValue[3]; tvs.SetValue(new TypedValue(1001, apps.lnkMNP), 0); tvs.SetValue(new TypedValue(1005, idCgPntBeg.getHandle().ToString()), 1); tvs.SetValue(new TypedValue(1005, idCgPntEnd.getHandle().ToString()), 2); //idPart.setXData(rb, apps.lnkMNP); idPipeNew.setXData(tvs, apps.lnkMNP); net.AddStructure(idStruct, idStructSize, pnt3dBeg, 0, ref idStructNew, true); s = (Structure)idStructNew.getEnt(); s.AddToProfileView(fMNP.idProfileView); s.ConnectToPipe(idPipeNew, ConnectorPositionType.Start); net.AddStructure(idStruct, idStructSize, pnt3dEnd, 0, ref idStructNew, true); s = (Structure)idStructNew.getEnt(); s.AddToProfileView(fMNP.idProfileView); s.ConnectToPipe(idPipeNew, ConnectorPositionType.End); sPrev = s; hPipe.Add(idPipeNew.getHandle().ToString()); } else { pnt3dEnd = new Point3d(pnt3dEnd.X, pnt3dEnd.Y, pnt3dEnd.Z - dZ); idCgPntEnd = pnt3dEnd.setPoint(out pntNum, pntDesc); idsCgPnt.Add(idCgPntEnd); tvs = new TypedValue[3]; tvs.SetValue(new TypedValue(1001, apps.lnkMNP), 0); tvs.SetValue(new TypedValue(1005, idCgPntPrev.getHandle().ToString()), 1); tvs.SetValue(new TypedValue(1005, idCgPntEnd.getHandle().ToString()), 2); //idPart.setXData(rb, apps.lnkMNP); idPipeNew.setXData(tvs, apps.lnkMNP); idCgPntPrev = idCgPntEnd; net.AddStructure(idStruct, idStructSize, pnt3dEnd, 0, ref idStructNew, true); s = (Structure)idStructNew.getEnt(); s.AddToProfileView(fMNP.idProfileView); sPrev.ConnectToPipe(idPipeNew, ConnectorPositionType.Start); s.ConnectToPipe(idPipeNew, ConnectorPositionType.End); sPrev = s; hPipe.Add(idPipeNew.getHandle().ToString()); } } else if (ent.EntityType == AlignmentEntityType.Arc) { AlignmentArc arc = (AlignmentArc)ent; double radius = arc.Radius; Point2d pnt2dBeg = arc.StartPoint; Point2d pnt2dEnd = arc.EndPoint; try { top = tinSurfDE.FindElevationAtXY(pnt2dBeg.X, pnt2dBeg.Y) + depth; } catch (System.Exception) { Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Pipe endpoint is beyond limit of design surface"); return; } Point3d pnt3dBeg = new Point3d(pnt2dBeg.X, pnt2dBeg.Y, top); try { top = tinSurfDE.FindElevationAtXY(pnt2dEnd.X, pnt2dEnd.Y) + depth; } catch (System.Exception) { Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Pipe endpoint is beyond limit of design surface"); return; } IntPtr iptr = (IntPtr)0; Point3d pnt3dEnd = new Point3d(pnt2dEnd.X, pnt2dEnd.Y, top); Arc a = new Arc(); a.Radius = arc.Radius; a.StartPoint = new Point3d(pnt2dBeg.X, pnt2dBeg.Y, 0); a.EndPoint = new Point3d(pnt2dEnd.X, pnt2dEnd.Y, 0); a.Center = new Point3d(arc.CenterPoint.X, arc.CenterPoint.Y, 0); Curve3d c = (Curve3d)a.GetGeCurve(); net.AddCurvePipe(idPipe, idPipeSize, c, arc.Clockwise, ref idPipeNew, true); p = (Pipe)idPipeNew.getEnt(); p.AddToProfileView(fMNP.idProfileView); ObjectId idPart = getProfileViewPart(); slope = (pnt3dEnd.Z - pnt3dBeg.Z) / arc.Length; dZ = diam / (2 * (System.Math.Cos(System.Math.Atan(System.Math.Abs(slope))))); if (i == 0) { pnt3dBeg = new Point3d(pnt3dBeg.X, pnt3dBeg.Y, pnt3dBeg.Z - dZ); pnt3dEnd = new Point3d(pnt3dEnd.X, pnt3dEnd.Y, pnt3dEnd.Z - dZ); idCgPntBeg = pnt3dBeg.setPoint(out pntNum, pntDesc); idsCgPnt.Add(idCgPntBeg); idCgPntEnd = pnt3dEnd.setPoint(out pntNum, pntDesc); idsCgPnt.Add(idCgPntEnd); tvs = new TypedValue[3]; tvs.SetValue(new TypedValue(1001, apps.lnkMNP), 0); tvs.SetValue(new TypedValue(1005, idCgPntBeg.getHandle().ToString()), 1); tvs.SetValue(new TypedValue(1005, idCgPntEnd.getHandle().ToString()), 2); //idPart.setXData(rb, apps.lnkMNP); idPipeNew.setXData(tvs, apps.lnkMNP); net.AddStructure(idStruct, idStructSize, pnt3dBeg, 0, ref idStructNew, true); s = (Structure)tr.GetObject(idStructNew, OpenMode.ForWrite); s.AddToProfileView(fMNP.idProfileView); s.ConnectToPipe(idPipeNew, ConnectorPositionType.Start); net.AddStructure(idStruct, idStructSize, pnt3dBeg, 0, ref idStructNew, true); s = (Structure)tr.GetObject(idStructNew, OpenMode.ForWrite); s.AddToProfileView(fMNP.idProfileView); s.ConnectToPipe(idPipeNew, ConnectorPositionType.End); sPrev = s; hPipe.Add(idPipeNew.getHandle().ToString()); } else { pnt3dEnd = new Point3d(pnt3dEnd.X, pnt3dEnd.Y, pnt3dEnd.Z - dZ); idCgPntEnd = pnt3dEnd.setPoint(out pntNum, pntDesc); idsCgPnt.Add(idCgPntEnd); tvs = new TypedValue[3]; tvs.SetValue(new TypedValue(1001, apps.lnkMNP), 0); tvs.SetValue(new TypedValue(1005, idCgPntPrev.getHandle().ToString()), 1); tvs.SetValue(new TypedValue(1005, idCgPntEnd.getHandle().ToString()), 2); //idPart.setXData(rb, apps.lnkMNP); idPipeNew.setXData(tvs, apps.lnkMNP); idCgPntPrev = idCgPntEnd; net.AddStructure(idStruct, idStructSize, pnt3dBeg, 0, ref idStructNew, true); s = (Structure)tr.GetObject(idStructNew, OpenMode.ForWrite); s.AddToProfileView(fMNP.idProfileView); sPrev.ConnectToPipe(idPipeNew, ConnectorPositionType.Start); s.ConnectToPipe(idPipeNew, ConnectorPositionType.End); sPrev = s; hPipe.Add(idPipeNew.getHandle().ToString()); } } } tr.Commit(); } hPipe.Insert(0, "-1"); hPipe.Add("-1"); for (int i = 0; i < idsCgPnt.Count; i++) { TypedValue[] tvs = new TypedValue[3]; tvs.SetValue(new TypedValue(1001, apps.lnkMNP), 0); tvs.SetValue(new TypedValue(1005, hPipe[i]), 1); tvs.SetValue(new TypedValue(1005, hPipe[i + 1]), 2); idsCgPnt[i].setXData(tvs, apps.lnkMNP); } }