.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Block size

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Ertqwa
2650 Views, 4 Replies

Block size

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.

4 REPLIES 4
Message 2 of 5
Alfred.NESWADBA
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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 5
Hallex
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
Message 4 of 5
Ertqwa
in reply to: Hallex

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

Message 5 of 5
Hallex
in reply to: Ertqwa

Glad you got it working

Cheers 🙂

_____________________________________
C6309D9E0751D165D0934D0621DFF27919

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost