获取圆心点和直线的两个端点
请教老师:当运行程序时选择一些圆和线,分别获取圆心点和直线的两个端点,并在获取的圆心点和直线的两个端点处各绘制一个圆...效果如下图片:
这……你写程序的时候有什么具体的问题? 本帖最后由 chpmould 于 2010-12-14 10:56 编辑
关键是不知如何窗选实体,并得到圆心点和直线的端点... 圆心是圆的Center属性
直线的端点是直线的StartPoint属性和EndPoint属性
Line l;
Circle c;
Point3d pt1=l.StartPoint;
Point3d pt2= l.EndPoint;
Point3d pt3= c.Center; 如何创建一个选择集来获取,最好有个简单的例子,我想这样比较容易理解... ed.GetSelXXX...
public void testfunction2()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed =doc.Editor;
Database db = HostApplicationServices.WorkingDatabase;
SelectionFilter sf = new SelectionFilter(new TypedValue[] { new TypedValue(0,"Line,Circle") });
PromptSelectionResult psr = ed.GetSelection(sf);
if (psr.Status != PromptStatus.OK)
return;
using (Transaction tr=db.TransactionManager.StartTransaction())
{
BlockTableRecord curSpace=tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
foreach (ObjectId id in psr.Value.GetObjectIds())
{
Entity ent = tr.GetObject(id, OpenMode.ForRead) as Entity;
if (ent.GetType() == typeof(Line))
{
Line l = ent as Line;
Point3d pt1 = l.StartPoint;
Point3d pt2 = l.EndPoint;
Circle c1 = new Circle(pt1, Vector3d.ZAxis, 1);
Circle c2 = new Circle(pt2, Vector3d.ZAxis, 1);
curSpace.AppendEntity(c1);
curSpace.AppendEntity(c2);
tr.AddNewlyCreatedDBObject(c1, true);
tr.AddNewlyCreatedDBObject(c2, true);
}
else
{
Circle c = ent as Circle;
Point3d pt = c.Center;
Circle c1 = new Circle(pt, Vector3d.ZAxis, 1);
curSpace.AppendEntity(c1);
tr.AddNewlyCreatedDBObject(c1, true);
}
}
tr.Commit();
}
} 添加半径是1的圆,比较小 谢谢老师的指点,我去慢慢理解。。。
页:
[1]