BlockReference SubEntities

BlockReference SubEntities

HJohn1
Advocate Advocate
1,069件の閲覧回数
5件の返信
メッセージ1/6

BlockReference SubEntities

HJohn1
Advocate
Advocate

I need to get the bounding box Min and Max points of a rectangle inside a BlockReference.  I have tried to get the sub entities thru the BlockRecord and then go thru the vertices of the rectangle (Polyline).  However, since this BlockReference is part of a title block in a drawing template, I would also have to deal with the drawing scale, the title block is in the model space.  See attached picture.  I just wandering if there is an easier way to achieve this. I will really appreciate any help.

NestedPolyLine.png

0 件のいいね
解決済み
1,070件の閲覧回数
5件の返信
返信 (5)
メッセージ2/6

_gile
Consultant
Consultant
解決済み

Hi,

 

After getting the coordinates in the BlockTableRecord, you can transform them using the BlockReference.BlockTransform matrix.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

メッセージ3/6

HJohn1
Advocate
Advocate

Gile, thank you very much for your help, it has been really appreciated.

0 件のいいね
メッセージ4/6

Anonymous
適用対象外

Hello,
can you post your source code please,
i am trying to get the name of the Reference Block in the Model space but i couldn't achieve that.

2020-08-28 11_07_58-Window.png

 

 

0 件のいいね
メッセージ5/6

marcin.sachs
Advocate
Advocate

@Anonymous 
You can get the block name using this:

[CommandMethod("blockName")]
static public void blockName()

{
    Document doc = Application.DocumentManager.MdiActiveDocument;

    Database db = doc.Database;

    Editor ed = doc.Editor;

    PromptEntityOptions options =

             new PromptEntityOptions("\nSelect block reference");

    options.SetRejectMessage("\nSelect only block reference");

    options.AddAllowedClass(typeof(BlockReference), false);

    PromptEntityResult acSSPrompt = ed.GetEntity(options);

    using (Transaction tx =

                        db.TransactionManager.StartTransaction())

    {
        BlockReference blockRef = tx.GetObject(acSSPrompt.ObjectId,

                               OpenMode.ForRead) as BlockReference;

        BlockTableRecord block = null;

        if (blockRef.IsDynamicBlock)

        {

            //get the real dynamic block name.

            block = tx.GetObject(blockRef.DynamicBlockTableRecord,

                    OpenMode.ForRead) as BlockTableRecord;

        }

        else

        {
            block = tx.GetObject(blockRef.BlockTableRecord,

                        OpenMode.ForRead) as BlockTableRecord;
        }

        if (block != null)

        {

            ed.WriteMessage("Block name is : "

                                        + block.Name + "\n");

        }

        tx.Commit();

    }

}
メッセージ6/6

Anonymous
適用対象外

Thanks for your Suggestion,

I have to select the block reference, to get its name.
I got the list of the used blocks in the active dwg by this code.

 

 

[CommandMethod("REV1")]
        public void EditBlock1()
        {
            Document acDoc = Application.DocumentManager.MdiActiveDocument;


            Editor ed = acDoc.Editor;
            var acDb = HostApplicationServices.WorkingDatabase;

            using (var acTrans = acDb.TransactionManager.StartTransaction())
            {
                var acBlockTable =
                     acTrans.GetObject(acDb.BlockTableId, OpenMode.ForRead) as BlockTable;
                if (acBlockTable == null) return;

                var acBlockTableRecord = acTrans.GetObject(acBlockTable[BlockTableRecord.ModelSpace],
                                         OpenMode.ForRead) as BlockTableRecord;
                if (acBlockTableRecord == null) return;
                foreach (ObjectId id in acBlockTableRecord)
                {
                    string blockName;

                    BlockReference bref = acTrans.GetObject(id, OpenMode.ForRead) as BlockReference;

                    if (bref != null)

                    {
                        if (bref.IsDynamicBlock)
                        {
                            BlockTableRecord br = (BlockTableRecord)acTrans.GetObject(bref.DynamicBlockTableRecord, OpenMode.ForRead);
                            //blockName = br.Name;
                            blockName = "DynamicBlock";
                        }
                        else
                        {
                            blockName = bref.Name;
                        }
                        //Debug.WriteLine("Found block reference: " + blockName);
                        ed.WriteMessage("\n Found block reference:  {0}\n\n", blockName);
                    }
                }
                acTrans.Commit();
            }
        }

 

0 件のいいね