- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
[CommandMethod("smp")]
public void ShowMidPointOnEachSegment()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
Entity ename;
PromptEntityOptions peo = new PromptEntityOptions("\nSelect Polyline: ");
peo.SetRejectMessage("\nMust be a Polyline.");
peo.AddAllowedClass(typeof(Polyline), false);
PromptEntityResult retval = ed.GetEntity(peo);
if (retval.Status != PromptStatus.OK) return;
Curve curv;
ObjectId id;
id = retval.ObjectId;
ename = tr.GetObject(id, OpenMode.ForWrite) as Entity;
curv = ename as Curve;
if (curv == null)
{
ed.WriteMessage("\nCould not cast object as Curve.");
return;
}
if (!curv.IsWriteEnabled)
curv.UpgradeOpen();
double startParam, endParam;
// get the start param, usually it starts at 0 or 1
startParam = curv.StartParam;
ed.WriteMessage("\nStartParam is: {0:f3}\n", startParam);
// get the end param, for a polyline it's the total number of
// vertex's -1
endParam = curv.EndParam;
ed.WriteMessage("\nEndParam is: {0:f3}\n", endParam);
// now loop the parameters, adding 1.0 each iteration
for (double i = startParam; i < endParam; ++i)
{
Point3d pt;
pt = curv.GetPointAtParameter(i + 0.5);
// DBPoint dp = new DBPoint(pt);
Circle cr = new Circle(pt, Vector3d.ZAxis, 2.5);
btr.AppendEntity(cr);
tr.AddNewlyCreatedDBObject(cr, true);
ed.WriteMessage("\nPoint: {0}, {1}, {2}\n", pt[0], pt[1], pt[2]);
}
tr.Commit();
}
} |
|