- 积分
- 24557
- 明经币
- 个
- 注册时间
- 2004-3-17
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2010-7-23 13:53:00
|
显示全部楼层
VB.Net写不习惯了,自己转换一下吧
其实代码并不复杂-
- [CommandMethod("tt5")]
- public static void test25()
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Editor ed = doc.Editor;
- PromptEntityOptions opts = new PromptEntityOptions("\n请选择一个块:");
- opts.SetRejectMessage("只能选择块参照");
- opts.AddAllowedClass(typeof(BlockReference), false);
- PromptEntityResult res = ed.GetEntity(opts);
- if (res.Status != PromptStatus.OK)
- return;
- Database db = doc.Database;
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- BlockReference bref = tr.GetObject(res.ObjectId, OpenMode.ForRead) as BlockReference;
- BlockTableRecord btr = tr.GetObject(bref.BlockTableRecord, OpenMode.ForRead) as BlockTableRecord;
- foreach (ObjectId id in btr)
- {
- Circle cir = tr.GetObject(id, OpenMode.ForRead) as Circle;
- if (cir != null)
- {
- Point3d pt = cir.Center.TransformBy(bref.BlockTransform);
- ed.DrawPoint(pt.Convert2d(new Plane()), 1, 1, 8);
- }
- }
- }
- }
扩展函数DrawPoint-
- public static void DrawVectors(this Editor editor, IEnumerable<Point2d> pnts, short colorIndex)
- {
- var itor = pnts.GetEnumerator();
- if (!itor.MoveNext())
- return;
- TypedValue tvFirst = new TypedValue((int)LispDataType.Point2d, itor.Current);
- ResultBuffer rb =
- new ResultBuffer
- {
- new TypedValue((int)LispDataType.Int16, colorIndex),
- tvFirst,
- };
- while (itor.MoveNext())
- {
- var tv = new TypedValue((int)LispDataType.Point2d, itor.Current);
- rb.Add(tv);
- rb.Add(tv);
- }
- rb.Add(tvFirst);
- editor.DrawVectors(rb, Matrix3d.Identity);
- }
- public static void DrawPoint(this Editor editor, Point2d pnt, short colorIndex, double radius, int numEdges)
- {
- Vector2d vec = Vector2d.XAxis * radius;
- double angle = Math.PI * 2 / numEdges;
- List<Point2d> pnts = new List<Point2d>();
- for (int i = 0; i < numEdges; i++)
- {
- pnts.Add(pnt + vec.RotateBy(angle * i));
- }
- editor.DrawVectors(pnts, colorIndex);
- }
复制代码 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
x
|