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

How to get the bounding box of a drawing

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
1189 Views, 2 Replies

How to get the bounding box of a drawing

Hi guys!

 

I'm using the following code to take a snapshot of the model:

 

private Bitmap GetScreenshot() {
            int cvPort = Convert.ToInt32(Application.GetSystemVariable(RenderingManager.CVPORT_SYS_VAR));

            using (View view = new View()) {
                this.graphicsManager.SetViewFromViewport(view, cvPort);
                view.VisualStyle = new VisualStyle(VisualStyleType.Hidden);
                using (Device dev = this.graphicsManager.CreateAutoCADOffScreenDevice()) {
                    dev.OnSize(graphicsManager.DisplaySize);
                    dev.DeviceRenderType = RendererType.Default;
                    dev.BackgroundColor = System.Drawing.Color.White;
                    dev.Add(view);
                    dev.Update();
                    using (Model model = graphicsManager.CreateAutoCADModel()) {
                        using (Transaction transaction = this.database.TransactionManager.StartTransaction()) {
                            BlockTable blockTable = (BlockTable)transaction.GetObject(this.database.BlockTableId, OpenMode.ForRead);
                            BlockTableRecord blockTableRecord = (BlockTableRecord)transaction.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForRead);
                            view.Add(blockTableRecord, model);
                            transaction.Commit();
                        }

                        Bitmap bitmap = view.GetSnapshot(view.Viewport);
                        view.EraseAll();
                        dev.Erase(view);

                        return bitmap;
                    }
                }
            }
        }

 I'm currently passing the entire viewport to the GetSnapshot method, but I'd like to restrict it to the minumun rectangle containing the drawing. The following image explains what  I mean (in red the viewport, in black what i need):

 

SwIso.jpg

 

how can I compute the black rectangle? Thanks in advance for any answer!

 

2 REPLIES 2
Message 2 of 3
Matti72
in reply to: Anonymous

You can select all the entitys in the drawing and then you can get the 

GeometricExtents of each entity. This you can combine to the Bounding Box of the drawing.

In fact the Extents3d class can manage that for you.

 

Extents3d ext = new Extents3d;

for each entity in drawing // here you need an editor.SeletAll() to obtain them

ext.AddExtents(entity.GeometricExtents);

 

 

After that ext will contain the bounding box of your drawing in world coordinates.

 

 

Message 3 of 3
Anonymous
in reply to: Matti72

Ok! I'll try this!...Once I get the extents in this way, I have to convert them from WCS to DCS before passing them to GetSnapshot, right?

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