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

Zoom Extents on new Database

16 REPLIES 16
Reply
Message 1 of 17
Techno Destructo
4317 Views, 16 Replies

Zoom Extents on new Database

I have created a new database:
Database newDb = new Database(true, true)
Inserted a block into modelspace
and now I want to zoom extent before saving.

Can this be done working on a new database in memory?
all the examples I have seen on this board use Interop on a open document.

Does anyone have a point in the right direction
16 REPLIES 16
Message 2 of 17
djonio
in reply to: Techno Destructo

Others have posted lots of good working methodologies ... search on zoomextents

Maybe these lines will give you a start ....

AcadApplication app = (AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
db.TileMode = false;//*PAPER_SPACE
db.TileMode = true;//*MODEL_SPACE
app.ZoomExtents();
------------------
LayoutManager layoutMgr = LayoutManager.Current;
layoutMgr.CurrentLayout = "Model";
AcadApplication pApp = (Autodesk.AutoCAD.Interop.AcadApplication)Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication;
pApp.ZoomExtents();
db.UpdateExt(true);
Message 3 of 17

Thanks for the reply

It seems Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication
ONLY apply to the document currently displayed in autocad.

Maybe I am missing a step but let me try to explain the problem again.
I have a drawing (drawing1) open.
I run my command that creates a NEW database in memory.
I insert a block in the NEW database (in memory) and I want to
Zoom extents and then save the database (drawing2).
When I use the examples in this forum including yours it zoom extents alright but in drawing1, not the new database.

I am still learning so I could be overlooking something
Any help is appreciated.
Message 4 of 17

I'm not sure, but I don't think that ActiveX commands can be applied to the in-memory drawing.
Again, I might be mistaken.
Message 5 of 17
mohnston
in reply to: Techno Destructo

I don't think you can zoom a *database*.
A *document* is required.
CAD Programming Solutions
Message 6 of 17
Ed.Jobe
in reply to: Techno Destructo

Correct, it has to be the current dwg in the editor to do display changes.

Ed

EESignature

Message 7 of 17
Anonymous
in reply to: Techno Destructo

Who told you that?

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5726557@discussion.autodesk.com...
Correct, it has to be the current dwg in the editor to do display changes.
Message 8 of 17

Thanks everyone

Maybe I can come at it from a different angle then.
When I complete the operations to the database save it and then open it as a drawing in AutoCAD, the view has been set for me, not where I would like (the extents of the block inserted)

How does one control where the initial view is located when creating a database?

Or is that view default and the need to specify has been overlooked?
Message 9 of 17
mohnston
in reply to: Techno Destructo

Tony,
Is there a way to "zoom" a database?
I made my comment based on my attempts at doing just that. I browsed the object model but saw no zoom functionality associated with the databaseservices. I only found zoom used with the application object and that only effected the active document.
Am I missing something? I know that there are plenty of undocumented or otherwise hidden pieces to the programming puzzle.

By the way, your CommandLine.cs worked fine for zooming but again that would only work on the currently active drawing.
CAD Programming Solutions
Message 10 of 17

SO maybe zoom extents is not what I want.

Is there a way to specify the initial view on a new database.
The view is set by autocad when you create a new db can we change that default view I guess is the question?

Anyone know how?
Is it possible
Message 11 of 17
Anonymous
in reply to: Techno Destructo

Yes Mark, there is a way to "zoom a database"

In the case of a database that's not open in the
AutoCAD editor, "zoom" means to set the view
parameters to whatever is required to achieve
the desired view (e.g., the center, magnification,
direction, etc.).

If you think about it, AutoCAD must read something
in the drawing file to determine the initial view
when it opens the file (which for a drawing that was
previously open in the editor, is the view that was
current when the file was saved).

See this thread for the gory details:

http://discussion.autodesk.com/adskcsp/thread.jspa?messageID=5541432

For zooming to the extents, you could call the
UpdateExts() method of the Database, and then
read the Extmin and Extmax properties to get
the box that has to fit in the view. If the view
is not plan, then it becomes a bit more difficult.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5727528@discussion.autodesk.com...

Tony,
Is there a way to "zoom" a database?
I made my comment based on my attempts at doing just that. I browsed the object model but saw no zoom functionality associated with the databaseservices. I only found zoom used with the application object and that only effected the active document.
Am I missing something? I know that there are plenty of undocumented or otherwise hidden pieces to the programming puzzle.

By the way, your CommandLine.cs worked fine for zooming but again that would only work on the currently active drawing. Message was edited by: Discussion Admin
Message 12 of 17
Anonymous
in reply to: Techno Destructo

See my reply to Mark.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5727623@discussion.autodesk.com...
SO maybe zoom extents is not what I want.

Is there a way to specify the initial view on a new database.
The view is set by autocad when you create a new db can we change that default view I guess is the question?

Anyone know how?
Is it possible
Message 13 of 17
cblais
in reply to: Techno Destructo

Anyboby has a sample of code in paperspace ? This function works well in modelspace :

Sub ZoomExtents(ByVal myDB As Autodesk.AutoCAD.DatabaseServices.Database)
Dim tm As Autodesk.AutoCAD.DatabaseServices.Transaction = myDB.TransactionManager.StartTransaction
Try
If myDB.TileMode = True Then 'Model
Dim vpt As ViewportTable = tm.GetObject(myDB.ViewportTableId, OpenMode.ForRead)
Dim vptr As ViewportTableRecord = tm.GetObject(vpt.Item("*Active"), OpenMode.ForWrite)
Dim pt3Max As Point3d = myDB.Extmax
Dim pt3Min As Point3d = myDB.Extmin
Dim pt2Max As Autodesk.AutoCAD.Geometry.Point2d = New Autodesk.AutoCAD.Geometry.Point2d(pt3Max.X, pt3Max.Y)
Dim pt2Min As Autodesk.AutoCAD.Geometry.Point2d = New Autodesk.AutoCAD.Geometry.Point2d(pt3Min.X, pt3Min.Y)
vptr.CenterPoint = (pt2Min + (pt2Max - pt2Min) / 2.0)
vptr.Height = (pt2Max.Y - pt2Min.Y)
vptr.Width = (pt2Max.X - pt2Min.X)
myDB.UpdateExt(True)
Else 'Papier



End If
Catch ex As Exception
MsgBox("Erreur de zoom, " & ex.Message)
Finally
tm.Commit()
tm.Dispose()
End Try
End Sub
Message 14 of 17
aksaks
in reply to: cblais

Thanks cblais for the code. I needed to use it, but in order for this to work a myDB.UpdateExt(True) must be executed before retrieving the Extmax and Extmin values just as Tony Z stated on 9/20/07.

 

aks

Message 15 of 17
Ajilal.Vijayan
in reply to: aksaks

I am trying change the code mentioned in here to use for paperspace.

I tried by changing the code as highlighted below and its not working.

Can anyone help me to show what I am doing wrong or any another way to zoom extent the paperspace of a document which is not active in the editor ?

 

        /// <summary>
        /// Sets a zoom extents of the Database model space
        /// </summary>
        /// <param name="db">The Database instance this method applies to.</param>
        public static void ZoomExtents(this Database db)
        {
            db.TileMode = false;
            Point2d scrSize = (Point2d)AcAp.GetSystemVariable("screensize");
            double ratio = scrSize.X / scrSize.Y;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            using (Line line = new Line(db.Pextmin, db.Pextmax))
            {
                ViewportTable vpt =
                    (ViewportTable)tr.GetObject(db.ViewportTableId, OpenMode.ForRead);
                ViewportTableRecord vptr =
                    (ViewportTableRecord)tr.GetObject(vpt["*Active"], OpenMode.ForWrite);
                Extents3d ext = line.GeometricExtents;
                ext.TransformBy(vptr.WorldToEye());
                Point2d pmin = new Point2d(ext.MinPoint.X, ext.MinPoint.Y);
                Point2d pmax = new Point2d(ext.MaxPoint.X, ext.MaxPoint.Y);
                double height = pmax.Y - pmin.Y;
                double width = pmax.X - pmin.X;
                if (width / height < ratio)
                {
                    vptr.Height = height;
                    vptr.Width = height * ratio;
                }
                else
                {
                    vptr.Width = width;
                    vptr.Height = width / ratio;
                }
                vptr.CenterPoint = pmin + (pmax - pmin) / 2.0;
                tr.Commit();
            }
        }

 

Message 16 of 17

I don't know if you can easily adapt the code you posted or not, because it is dependent on a number of things that require the document and the paperspace layout to be active (for example, the SCREENSIZE system variable, the *Active ViewportTableRecord, etc.). If the document is not active in the editor 

 

I'm not suggesting it isn't possible to do, but given how the code is written, a great deal of it is dependent on the active document and layout.

 

Ajilal.Vijayan wrote:

I am trying change the code mentioned in here to use for paperspace.

I tried by changing the code as highlighted below and its not working.

Can anyone help me to show what I am doing wrong or any another way to zoom extent the paperspace of a document which is not active in the editor ?

 

        /// <summary>
        /// Sets a zoom extents of the Database model space
        /// </summary>
        /// <param name="db">The Database instance this method applies to.</param>
        public static void ZoomExtents(this Database db)
        {
            db.TileMode = false;
            Point2d scrSize = (Point2d)AcAp.GetSystemVariable("screensize");
            double ratio = scrSize.X / scrSize.Y;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            using (Line line = new Line(db.Pextmin, db.Pextmax))
            {
                ViewportTable vpt =
                    (ViewportTable)tr.GetObject(db.ViewportTableId, OpenMode.ForRead);
                ViewportTableRecord vptr =
                    (ViewportTableRecord)tr.GetObject(vpt["*Active"], OpenMode.ForWrite);
                Extents3d ext = line.GeometricExtents;
                ext.TransformBy(vptr.WorldToEye());
                Point2d pmin = new Point2d(ext.MinPoint.X, ext.MinPoint.Y);
                Point2d pmax = new Point2d(ext.MaxPoint.X, ext.MaxPoint.Y);
                double height = pmax.Y - pmin.Y;
                double width = pmax.X - pmin.X;
                if (width / height < ratio)
                {
                    vptr.Height = height;
                    vptr.Width = height * ratio;
                }
                else
                {
                    vptr.Width = width;
                    vptr.Height = width / ratio;
                }
                vptr.CenterPoint = pmin + (pmax - pmin) / 2.0;
                tr.Commit();
            }
        }

 


 

Message 17 of 17

Thanks for the reply @ActivistInvestor

In modelsapce this code works with the the documents which are not active in the editor.

So I tried with _db.GetViewports(true) and used the first objectid of that collection to get the Viewport.

This seems to be working.

 

ObjectIdCollection vpcol = _db.GetViewports(true);
                    if (vpcol.Count > 0)//Check whether the layout is initialiazed
                    {
                        Viewport vport = (Viewport)_tr.GetObject(vpcol[0], OpenMode.ForWrite);
                        vport.ViewHeight = (width / height) < ratio ? height : width / ratio;
                        vport.ViewCenter = pmin + (pmax - pmin) / 2.0;
                    }

 

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