-
- ///
- /// 获取线对象上的坐标集和突度集
- ///
- /// Curve对象
- /// 坐标集
- /// 突度集
- 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
- /// 返回CAD对象类型
- ///
- /// 对象名称
- ///
- public static string GetEntityType(this Entity ent)
- {
- try
- {
- return ent.GetType().ToString().Replace("Autodesk..DatabaseServices.", "");
- }
- catch
- {
- return "";
- }
- } ///
- /// 获取ObjectId的Entity
- ///
- /// 对象ID
- /// 事务处理对象
- /// 读取模式
- ///
- 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 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;
- }
扩展方法需要放在静态类里面
|