cart: empty [ Login ]

How can I adjust the zoom level at opening in Autocad ?

1/27/2011 8:18 AM
Hello, When I open a CadLib generated drawing in Autocad the zoom level is too close. So I have each time to do an extended zoom to display the full drawing (in object space). Is there any way/option in CadLib to set the zoom level in order to display the whole drawing at opening ? Best regards, Pascal
1/27/2011 2:03 PM
Hi Pascal, there is a way, but it may not be as easy as you like. AutoCAD defines its initial view by a complex combination of header, table and object entries. So in the following I'll assume that you use the default configuration of the various settings (i.e. what you have if you create a DxfModel, add some entities and save that). In that case the initial view is defined by a VPORT entry in the VPORT table with the name '*Active'. So in order to define the initial view you have to provide such a VPORT with the correct settings. If you just want to display the model projected to an X-Y plane, you can use something like (after the model is created):
C# Code:
      // create VPORT for initial view       BoundsCalculator boundsCalculator = new BoundsCalculator();       boundsCalculator.GetBounds(model);       Bounds3D bounds = boundsCalculator.Bounds;              DxfVPort active = model.VPorts.GetOrCreateActiveVPort();       active.Height = bounds.Delta.Y;       active.AspectRatio = bounds.Delta.X/bounds.Delta.Y;       active.Center = (Point2D) bounds.Center;
Please note that the AspectRatio is defined by the ratio of the window's width and height, so the above code will put the model always to the left side of the AutoCAD window.
1/27/2011 4:25 PM
Thanks for your explanation Rammi. Your solution works perfectly.
9/25/2023 12:28 PM
Hi Rammi, Thanks for the sample code. If I use it then I end up with a viewport inside a viewport. See sample dxf file.
Visual Basic Code:
Sub ZoomExtents(ByRef model As DxfModel) 'create VPORT for initial view Dim BoundsCalculator As BoundsCalculator = New BoundsCalculator() BoundsCalculator.GetBounds(model) Dim Bounds As Bounds3D = BoundsCalculator.Bounds Dim active As DxfVPort = New DxfVPort(DxfVPort.ActiveVPortName) active.Height = Bounds.Delta.Y active.AspectRatio = Bounds.Delta.X / Bounds.Delta.Y active.Center = CType(Bounds.Center, Point2D) model.VPorts.Add(active) End Sub
9/26/2023 10:33 AM
Your DXF already has an active VPORT object, so you now have 2 after your addition. You can also use method DxfModel.Zoom(Bounds3D bounds) for this or DxfModel.ZoomExtents(). - Wout