- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
// based on code by Balaji Ramamoorthy
// http://adndevblog.typepad.com/au ... rve-at-a-point.html
[CommandMethod("bre")]
public static void ADSProjectBreak()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Matrix3d ucs = ed.CurrentUserCoordinateSystem;
Database db = HostApplicationServices.WorkingDatabase;
ObjectId id;
Entity ent;
try
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
// Let the user select a curve
id = ed.GetEntity("\nSelect curve: ").ObjectId;
if (id == ObjectId.Null) return;
ent = (Entity)tr.GetObject(id, OpenMode.ForRead, false);
if (ent == null) return;
// Check that it is really a curve
Curve Curve = ent as Curve;
if (Curve == null) return;
// Get the break position and convert to WC coordinates
Point3d breakPnt;
breakPnt = ed.GetPoint("\nPick a point on the curve: ").Value;
breakPnt.TransformBy(ucs.Inverse());
// Check that the point is on the curve
breakPnt = Curve.GetClosestPointTo(breakPnt, false);
Point3dCollection breakPoints = new Point3dCollection();
DBObjectCollection newCurves = new DBObjectCollection();
// Get the segments according to the trim points
breakPoints.Add(breakPnt);
newCurves = Curve.GetSplitCurves(breakPoints);
if (newCurves == null)
{
ed.WriteMessage("\nGetSplitCurves failed : Error");
return;
}
// Here we add the segments to the database with different colors
for (int i = 0; i < newCurves.Count; i++)
{
Entity pent = (Entity)newCurves as Entity;
pent.SetPropertiesFrom(ent);
pent.ColorIndex = i + 1;// to display result only
btr.AppendEntity(pent);
tr.AddNewlyCreatedDBObject(pent, true);
tr.TransactionManager.QueueForGraphicsFlush();
}
ent.UpgradeOpen();
ent.Erase();
doc.TransactionManager.FlushGraphics();
tr.Commit();
}
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(ex.Message + "\n" + ex.StackTrace);
}
finally
{
ed.WriteMessage("\nPokey");
}
} |
|