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

get bounding box

6 REPLIES 6
Reply
Message 1 of 7
a7v1n
4544 Views, 6 Replies

get bounding box

hi. how do you get the bounding box of a block in the drawing using vb.net? Can someone point me to the right direction? I'm going crazy over here. Thanks... Im using AutoCAD 2008 by the way. thanks Edited by: a7v1n on Apr 6, 2010 12:19 AM
6 REPLIES 6
Message 2 of 7
norman.yuan
in reply to: a7v1n

Check out BlockReference.GeometricExtents property and/or BlockReference.GeometricExtentsBestFit() method.

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 7
06041983
in reply to: norman.yuan

Hi, Norman!

I ask you, please, tell in detail how to do it, because we are new and do not know all the details. To me the answer could not help. I just lose my mind yet deal with that.

I hope you understand me, because I am from Russia and I find it hard to explain my problem, but the issue with GetBoundingBox me too important.

 

Please, if you have a solution to this problem, and describe it in detail. All the people you are only grateful.

Message 4 of 7
SENL1362
in reply to: 06041983

        [CommandMethod("TestGetBlkRefExtents")]
        public void TestGetBlkRefExtents()
        {
            Document doc = null;
            Database db = null;
            Editor ed = null;

            string blkName = "MyBlk";
            Point3d insPnt = new Point3d(10, 20, 0);
            double rotInRad = 30 * (Math.PI / 180);
            double scaleFct = 2;
            try
            {
                doc = AcadApp.DocumentManager.MdiActiveDocument;
                if (doc == null)
                    return;
                db = doc.Database;
                ed = doc.Editor;


                //1. Insert Block in Modelspace
                ObjectId blkRefId = ObjectId.Null;
                using (Transaction tr=db.TransactionManager.StartTransaction())
                {
                    var bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                    var blkId = bt[blkName];
                    BlockReference blkRef=null;
                    if (bt.Has(blkName))
                    {
                        var ms = (BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead);
                        blkRef = new BlockReference(insPnt, blkId);
                        blkRef.SetDatabaseDefaults(db);
                        ms.UpgradeOpen();
                        ms.AppendEntity(blkRef);
                        tr.AddNewlyCreatedDBObject(blkRef, true);

                        if (rotInRad != 0)
                            blkRef.Rotation = rotInRad;

                        if (scaleFct != 1)
                            blkRef.ScaleFactors = new Scale3d(scaleFct);
                        blkRefId = blkRef.ObjectId;
                    }
                    tr.Commit();
                }
                if(blkRefId.IsNull)
                    throw new System.Exception("Failed to insert Block: " + blkName);


                //2. Get Block Extension
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    var blkRef = (BlockReference)tr.GetObject(blkRefId, OpenMode.ForRead);
                    Extents3d blkRefExt=blkRef.GeometricExtents;
                    ed.WriteMessage("\n BlockReference: {0}", blkName);
                    ed.WriteMessage("\n\t Position: {0}", blkRef.Position);
                    ed.WriteMessage("\n\t Rotation: {0}", blkRef.Rotation * (180/Math.PI ));
                    ed.WriteMessage("\n\t Scale: {0},{1},{2}", blkRef.ScaleFactors.X, blkRef.ScaleFactors.Y, blkRef.ScaleFactors.Z);
                    ed.WriteMessage("\n\t Size: {0}..{1}", blkRefExt.MinPoint, blkRefExt.MaxPoint);
                    tr.Commit();
                }


            }
            catch (System.Exception ex)
            {
                if (ed != null)
                    ed.WriteMessage("\n Error: " + ex.Message);
                else
                    MessageBox.Show("Error: " + ex.Message, "TestGetBlkRefExtents", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Message 5 of 7
06041983
in reply to: SENL1362

Hi, -SENL1362-!

 

Thank you for answer and code.

Unfortunately I did not understand anything in it))) I'm still at a very early stage of education.

 

I understand this code (from AutoCAD ActiveX and VBA Reference):

 

Sub Example_GetBoundingBox()
' Этот пример строит в пространстве модели линию и определяет размеры области объекта Dim startPoint(0 To 2) As Double Dim endPoint(0 To 2) As Double Dim lineObj As AcadLine ' Создаем линию в пространстве модели (или определяем ее) startPoint(0) = 2#: startPoint(1) = 2#: startPoint(2) = 0# endPoint(0) = 4#: endPoint(1) = 4#: endPoint(2) = 0# Set lineObj = ThisDrawing.ModelSpace.AddLine(startPoint, endPoint) ZoomAll Dim minExt As Variant Dim maxExt As Variant ' Метод возвращает максимальную и минимальную точку области объекта lineObj.GetBoundingBox minExt, maxExt ' Печатаем минимальные и максимальные размеры области MsgBox "Текущие размеры объекта:" & vbCrLf _ & "Min Extent: " & minExt(0) & "," & minExt(1) & "," & minExt(2) _ & vbCrLf & "Max Extent: " & maxExt(0) & "," & maxExt(1) & "," & maxExt(2), vbInformation, "GetBoundingBox пример" End Sub

Very easy: Create object in model space, get his bounding box and print in message box!

 

I do not understand the concept of AutoCAD NET API and this is sad 😞

 

Something like I've done with the help of "Using Autodesk.AutoCAD.Interop", but I have new problem: I can't show Form with report after it. 😞

 

Sad, sad and sad!

Where can I find a good explanation of the concept of AutoCAD NET API?

 

Thank you for your responsiveness!

Message 6 of 7
SENL1362
in reply to: 06041983

Message 7 of 7
dgorsman
in reply to: SENL1362

If you start with AutoCAD without knowing the basics of VB.NET you'll basically be lost.  Find a good primer for that first.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


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