如何得到某块参照中的某子实体
块参照视乎有一个函数叫GetSubEntity,不知道怎么用,或者哪位高手还能知道在已有的块参照中获取某个子实体,比如说,构成他的 某个圆,我想获取这个圆的一些属性,比如说坐标等 <p>这个在块定义里找</p><p>然后坐标转换到块参照</p> 给段example代码看看啥版主 我用的vb.net VB.Net写不习惯了,自己转换一下吧
其实代码并不复杂
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);
}
nice ,very good,thanks 雪山飞狐_lzh 发表于 2010-7-23 13:53 static/image/common/back.gif
VB.Net写不习惯了,自己转换一下吧
其实代码并不复杂
请问Point3d pt = cir.Center.TransformBy(bref.BlockTransform);这句中的bref.BlockTransform在vb中怎么得到?ActiveX帮助中块参照里没有类似的属性,这个值该怎么得到?望指教 谢谢
页:
[1]