Matrix3d Block Entity Position

Matrix3d Block Entity Position

Anonymous
Not applicable
582 Views
2 Replies
Message 1 of 3

Matrix3d Block Entity Position

Anonymous
Not applicable

Hi, i have been trying to get the matrix3d transform for any entity, solid3d block but thing seems like not work out for me. I tried with a simple line, using the start point and end point of the line to compute my own matrix3d transform but what about if the line is in a block. The start point and end point of a line in block is always the same, maybe it referencing to the block origin. 

 

below is a simple prompt to get the entity and if the entity is a block reference then it will add a line with start(-15,0,0) End(15,0,0) so is there any way to get the start point and end point of the line in WCS? and not referencing to the block?

 

 

 

Entity aEntity = (Entity)Trans.GetObject(PromptResult.ObjectId, OpenMode.ForRead);
if (aEntity.GetType() == typeof(BlockReference))
{
BlockReference aBlockReference = (BlockReference)aEntity;
Line aLine = new Line(new Point3d(-15, 0, 0), new Point3d(15, 0, 0));
BlockTableRecord btr = (BlockTableRecord)Trans.GetObject(aBlockReference.BlockTableRecord, OpenMode.ForRead);
btr.UpgradeOpen();
btr.AppendEntity(aLine);
Trans.AddNewlyCreatedDBObject(aLine, true);
Trans.Commit();
}

 Thanks

 

0 Likes
583 Views
2 Replies
Replies (2)
Message 2 of 3

_gile
Consultant
Consultant

Hi,

 

If your entity is within a block, you can use the PromptNestedEntityResult.Transform property.

 

 

[CommandMethod("test")]
        public void test()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            PromptNestedEntityResult pner = ed.GetNestedEntity("\nSelect an entity within a block: ");
            if (pner.Status != PromptStatus.OK)
                return;
            Matrix3d mat = pner.Transform;
            ed.WriteMessage(mat.ToString());
        }

 

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 3

chiefbraincloud
Collaborator
Collaborator

Every Block Reference has a BlockTransform Property, so if you have a BlockReference open, you just use that for all the sub objects of the block.

 

The PromptNestedEntityResult.Transform could be of use if you don't have the BlockRef open, but otherwise it's just an extra step.

Dave O.                                                                  Sig-Logos32.png
0 Likes