.NET

Reply
Valued Contributor
Ertqwa
Posts: 93
Registered: ‎10-03-2011
Message 1 of 5 (346 Views)
Accepted Solution

Block size

346 Views, 4 Replies
03-24-2013 05:01 AM

Hello,

 

I want to determine the size of a (non-dynamic non-annotative) block definition (BlockTableRecord). Does a block have a boundry or limits?
For example, if the block would contain a simple square, the size of the block would be equal to the size of the square.

 

Thank you.

*Expert Elite*
Alfred.NESWADBA
Posts: 8,994
Registered: ‎06-29-2007
Message 2 of 5 (338 Views)

Re: Block size

03-24-2013 05:06 AM in reply to: Ertqwa

Hi,

 

do you look for that?

Public Overridable ReadOnly Property GeometricExtents As Autodesk.AutoCAD.DatabaseServices.Extents3d
     Member von Autodesk.AutoCAD.DatabaseServices.Entity

 

[EDIT] sorry, I saw to late that you wrote "block-definition", not block-reference.

So you can either scan through the elements within the blockdefinition or you create one reference virtually and take that reference for .GeometricExtents. [/EDIT]

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 3 of 5 (316 Views)

Re: Block size

03-24-2013 09:19 AM in reply to: Ertqwa

You can check bound property of block as well:

        [CommandMethod("bsz")]
        static public void BlockRecordSize()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = HostApplicationServices.WorkingDatabase;

            PromptStringOptions pso = new PromptStringOptions("\nEnter block name:");
            pso.AllowSpaces = true;
            PromptResult res;
            res = ed.GetString(pso);
            if (res.Status != PromptStatus.OK)  return;

            string blockname = res.StringResult;

            ed.WriteMessage("\nBock name entered\t{0}\n",  blockname);
   
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable bt= tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                if (!bt.Has(blockname)) 
                { 
                    ed.WriteMessage("\nBock \"{0}\" does not exists.\n", blockname); 
                    return;
                }
                BlockTableRecord btrec = (BlockTableRecord)tr.GetObject(bt[blockname], OpenMode.ForRead,false);
                Extents3d? bounds;
                 bounds = btrec.Bounds;
                if (bounds.HasValue)
                {
                    Extents3d ext = bounds.Value;
                    double width = ext.MaxPoint.X - ext.MinPoint.X;
                    double height = ext.MaxPoint.Y - ext.MinPoint.Y;
                    ed.WriteMessage("\nBock {0} hase width= {1:f3}; height = {2:f3}\n", blockname, width, height);

                }
                else
                {
                    BlockReference bref = new BlockReference(Point3d.Origin, bt[blockname]);
                    bounds =bref.Bounds;
                    Extents3d ext = bounds.Value;
                    double width = ext.MaxPoint.X - ext.MinPoint.X;
                    double height = ext.MaxPoint.Y - ext.MinPoint.Y;
                    ed.WriteMessage("\nBock {0} hase width= {1:f3}; height = {2:f3}\n", blockname, width, height);
                    bref.Dispose();
                }
                tr.Commit();
            }            
        }

 

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Valued Contributor
Ertqwa
Posts: 93
Registered: ‎10-03-2011
Message 4 of 5 (282 Views)

Re: Block size

03-25-2013 01:35 PM in reply to: Hallex

Great, both replies are what I am looking for. Ty!

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 5 of 5 (274 Views)

Re: Block size

03-25-2013 02:16 PM in reply to: Ertqwa

Glad you got it working

Cheers :smileyhappy:

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.