- UID
- 769950
- 积分
- 64
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2017-7-25
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
如果只是选择几个样条曲线,转多段线没有什么问题,
如果选择很多的话,比如1000个,autocad就会崩溃,提示致命错误。
代码如下
//Spline变多段线
[CommandMethod("MyEx")]
public static void MyEx()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptSelectionResult result = ed.GetSelection();
SelectionSet set = result.Value;
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
//以读方式打开块表..
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
//以写方式打开模型空间块表记录
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
if (set != null && set.Count > 0)
{
// List<DBText> textlist = new List<DBText>();
int nCount = 0;
foreach (ObjectId id in set.GetObjectIds())
{
Entity ent = (Entity)id.GetObject(OpenMode.ForWrite);
if (ent is Spline)
{
nCount = nCount + 1;
Debug.WriteLine(nCount);
Debug.WriteLine(id);
Spline sp = (Spline)ent;
int d = sp.Degree;
NurbCurve3d nurb = ToNurbCurve3d(sp);
Point3d[] pt3= nurb.GetSamplePoints(20);
Polyline pl = new Polyline();
for (int i = 0; i < pt3.Length ; i++)
{
pl.AddVertexAt(i, new Point2d(pt3[i].X, pt3[i].Y), 0, 0, 0);
}
if (sp.Closed)
{
pl.Closed = true;
}
sp.Erase(true);
//将图形对象的信息添加到块表记录中,并返回ObjectId对象.
btr.AppendEntity(pl);
//把对象添加到事务处理中.
trans.AddNewlyCreatedDBObject(pl, true);
}
}
//提交事务处理
trans.Commit();
}
}
}
|
|