- 积分
- 1491
- 明经币
- 个
- 注册时间
- 2004-5-8
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
- /// <summary>
- /// 获取线对象上的坐标集和突度集
- /// </summary>
- /// <param name="curve">Curve对象</param>
- /// <param name="Point3dColl">坐标集</param>
- /// <param name="Bulges">突度集</param>
- public static void GetPolylinePoint3dsAndBulge(this Curve curve,ref Point3dCollection Point3dColl,ref DoubleCollection Bulges)
- {
- try
- {
-
- Point3dColl.Clear();
- Bulges.Clear();
- switch (curve.GetEntityType())
- {
- case "Polyline":
- Polyline polylineObject = (Polyline)curve;
- int NumberOfVertices = polylineObject.NumberOfVertices;
- for (int i = 0; i < NumberOfVertices; i++)
- {
- Point3dColl.Add(polylineObject.GetPoint3dAt(i));
- Bulges.Add(polylineObject.GetBulgeAt(i));
- }
- break;
- case "Line":
- Point3dColl.Add(curve.StartPoint);
- Point3dColl.Add(curve.EndPoint);
- Bulges.Add(0);
- Bulges.Add(0);
- break;
- case "Arc":
- Point3dColl.Add(curve.StartPoint);
- Point3dColl.Add(curve.EndPoint);
- Bulges.Add(((Arc)curve).GetBulge(true));
- Bulges.Add(0);
- break;
- case "Polyline2d":
- Polyline2d polyline2dObject = (Polyline2d)curve;
- using (Transaction trans = AcadPropers.Tm.StartTransaction())
- {
- foreach (ObjectId objId in polyline2dObject)
- {
- Vertex2d v2d = (Vertex2d)objId.GetEntity(trans, OpenMode.ForRead, false, false);
- Point3dColl.Add(v2d.Position);
- Bulges.Add(v2d.Bulge);
- }
- trans.Commit();
- }
- break;
- }
- }
- catch
- {
- Point3dColl.Clear();
- Bulges.Clear();
- }
- }
- public static Point3dCollection GetPolylinePoint3ds(this Curve curve)
- {
- try
- {
- Point3dCollection Point3dColl = new Point3dCollection();
- switch (curve.GetEntityType())
- {
- case "Polyline":
- Polyline polylineObject = (Polyline)curve;
- int NumberOfVertices = polylineObject.NumberOfVertices;
- for (int i = 0; i < NumberOfVertices; i++)
- {
- Point3dColl.Add(polylineObject.GetPoint3dAt(i));
- }
- break;
- case "Line":
- Point3dColl.Add(curve.StartPoint);
- Point3dColl.Add(curve.EndPoint);
- break;
- case "Arc":
- Point3dColl.Add(curve.StartPoint);
- Point3dColl.Add(curve.EndPoint);
- break;
- case "Polyline2d":
- Polyline2d polyline2dObject = (Polyline2d)curve;
- using (Transaction trans = AcadPropers.Tm.StartTransaction())
- {
- foreach (ObjectId objId in polyline2dObject)
- {
- Vertex2d v2d = (Vertex2d)objId.GetEntity(trans, OpenMode.ForRead, false, false);
- Point3dColl.Add(v2d.Position);
- }
- trans.Commit();
- }
- break;
- }
- return Point3dColl;
- }
- catch
- {
- return null;
- }
- }
- /// <summary>
- /// 返回CAD对象类型
- /// </summary>
- /// <param name="ent">对象名称</param>
- /// <returns></returns>
- public static string GetEntityType(this Entity ent)
- {
- try
- {
- return ent.GetType().ToString().Replace("Autodesk.AutoCAD.DatabaseServices.", "");
- }
- catch
- {
- return "";
- }
- }
- /// <summary>
- /// 获取ObjectId的Entity
- /// </summary>
- /// <param name="ObjId">对象ID</param>
- /// <param name="trans">事务处理对象</param>
- /// <param name="openmode">读取模式</param>
- /// <returns></returns>
- public static DBObject GetEntity(this ObjectId ObjId, Transaction trans, OpenMode openmode, bool openErased, bool forceOpenOnLockeDLayer)
- {
- try
- {
- return (DBObject)trans.GetObject(ObjId, openmode, openErased, forceOpenOnLockeDLayer);
- }
- catch (Exception)
- {
- return null;
- }
- }
- ///后面部分是抄的,原来自己写的方向有时候有问题
- ///忘记哪里了,急用没留地址,找不到了
- ///希望这位朋友不要介意啊,哈哈
- //计算凸起值
- public static double GetBulge(this Arc A, bool SEbo)
- {
- double Bulge = 0;
- double L1 = GetDistance(A.StartPoint, A.EndPoint);
- double Angle = A.EndAngle - A.StartAngle;
- if (Angle < 0)
- {
- Angle = Math.PI * 2 + Angle;
- //计算圆弧总角度
- }
- if (Angle > Math.PI)
- {
- //判断是否大于180度
- Bulge = A.Radius + Math.Sqrt(Math.Pow(A.Radius, 2) - Math.Pow((L1 / 2), 2));
- //计算凸起值
- }
- else
- {
- Bulge = A.Radius - Math.Sqrt(Math.Pow(A.Radius, 2) - Math.Pow((L1 / 2), 2));
- //计算凸起值
- }
- Point3d Pt2 = A.GetPointAtDist(A.GetDistanceAtParameter(A.EndParam) / 2);
- //取中点
- double TempDouble = 0;
- if (SEbo == true)
- {
- //判断方向
- TempDouble = PtSide(A.StartPoint, Pt2, A.EndPoint);
- }
- else
- {
- TempDouble = PtSide(A.EndPoint, Pt2, A.StartPoint);
- }
- if (TempDouble > 0)
- {
- //判断圆弧是凸向哪边
- return -Bulge / (L1 / 2);
- }
- else
- {
- return Bulge / (L1 / 2);
- }
- }
- //判断圆弧是凸向哪边
- private static double PtSide(Point3d pt1, Point3d pt2, Point3d pt3)
- {
- Vector3d vect1 = pt1.GetVectorTo(pt2);
- Vector3d vect2 = pt1.GetVectorTo(pt3);
- return vect2.X * vect1.Y - vect1.X * vect2.Y;
- }
扩展方法需要放在静态类里面
|
评分
-
查看全部评分
|