Message 1 of 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi and wish every one a peaceful year.
Im confused with blkRef.BlockTransform concept.
I have a block reference which is nested.
I use GetNestedEntity to select a nested entity but Im only interested in the block references. so I would use the GetContainer method.
but Im not getting the right geometric extents.
what am I doing wrong?
using (Transaction tr = db.TransactionManager.StartTransaction())
{
var pner = ed.GetNestedEntity("\nSelect block - possibly nested");
if (pner.Status != PromptStatus.OK)
return;
var objIds = pner.GetContainers().ToList();
if (objIds is null)
return;
if (objIds.Count == 0)
return;
var child = tr.GetObject(objIds[0], OpenMode.ForRead) as BlockReference;
var parent = tr.GetObject(objIds[objIds.Count-1], OpenMode.ForRead) as BlockReference;
var pl = StandardColumnCreator(child, parent.BlockTransform);
var md = tr.GetObject(db.CurrentSpaceId,OpenMode.ForWrite) as BlockTableRecord;
md.AppendEntity(pl);
tr.AddNewlyCreatedDBObject(pl, true);
tr.Commit();
}
private static Polyline StandardColumnCreator(Entity rawEntity, Matrix3d? transform = null)
{
var extents = rawEntity.GeometricExtents;
var point1 = extents.MinPoint;
var point2 = extents.MaxPoint;
if (transform.HasValue)
{
point1 = point1.TransformBy(transform.Value);
point2 = point2.TransformBy(transform.Value);
}
var minPoint = new Point2d(
point1.X < point2.X ? point1.X : point2.X, point1.Y < point2.Y ? point1.Y : point2.Y);
var maxPoint = new Point2d(
point1.X > point2.X ? point1.X : point2.X, point1.Y > point2.Y ? point1.Y : point2.Y);
var rectanglePolyline = new Polyline();
rectanglePolyline.AddVertexAt(0, minPoint, 0, 0, 0);
rectanglePolyline.AddVertexAt(1, new Point2d(maxPoint.X, minPoint.Y), 0, 0, 0);
rectanglePolyline.AddVertexAt(2, maxPoint, 0, 0, 0);
rectanglePolyline.AddVertexAt(3, new Point2d(minPoint.X, maxPoint.Y), 0, 0, 0);
rectanglePolyline.Closed = true;
return rectanglePolyline;
}
Solved! Go to Solution.