|
一直就不喜欢在程序里用命令,在.Net里还有AutoCAD命令与Editor及事务提交之间纠缠不清的关系,特别是三者的次序我实在搞不清楚,托管类里没有打断曲线的方法,AutoCAD的Break命令用起来不顺手,而且还担心不可靠.只好自己写一个打断曲线的方法,各位或许会用得上.花了一个很晚的晚上和一个很早的早上.可以打断直线,圆弧,圆,椭圆,椭圆弧,轻型多义线(封闭和开口的),Xline及射线.
///
/// curveid Object must have existed in Database
/// Can break Line | Arc | Circle | Ellipse | Polyline | Xline | Ray
///
/// 第一个打断点
/// 第二个打断点
/// 要打断曲线的ObjectId
///
public static bool BreakCurve(Point3d p1, Point3d p2, ObjectId curveid)
{
//pcm.WriteLine("BreakCurve start", 0);
try
{
Database cdb = curveid.Database;
using (Transaction ctrans = cdb.TransactionManager.StartTransaction())
{
Curve cur = (Curve)ctrans.GetObject(curveid, OpenMode.ForWrite);
Point3d p11 = cur.GetClosestPointTo(p1, false);
Point3d p21 = cur.GetClosestPointTo(p2, false);
#region Break Line
if (cur is Line)
{
//pcm.WriteLine("Break Line start ", 1);
Line l1 = (Line)cur;
Line l2 = (Line)l1.Clone();
if (l1.GetDistAtPoint(p11) len12)
{
if ((double)param32 != param22)
{
double bul12 = pl1.GetBulgeAt(param32 - 1);
double bul22 = 0;
if (bul12 != 0.0)
{
double len22 = pl1.GetDistanceAtParameter(param32) - pl1.GetDistanceAtParameter(param32 - 1);
double len32 = pl1.GetDistanceAtParameter(param32) - pl1.GetDistanceAtParameter(param22);
bul22 = Math.Tan(len32 * Math.Atan(bul12) / len22);
}
p31 = pl1.GetPointAtParameter(param22);
pl2.AddVertexAt(0, new Point2d(p31.X, p31.Y), bul22, 0, 0);
}
for (int i = param32; i ray1.BasePoint.DistanceTo(p21))
{
l1 = new Line(ray1.BasePoint, p21);
l1.SetPropertiesFrom(ray1);
ray1.BasePoint = p11;
}
else
{
l1 = new Line(ray1.BasePoint, p11);
l1.SetPropertiesFrom(ray1);
ray1.BasePoint = p21;
}
DrawEntity(l1);
}
#endregion Break Ray
ctrans.Commit();
return true;
}
}
catch (System.Exception ex)
{ pcm.WriteLine(ex); return false; }
} |
|