Can see dwg created with RealDWG only after clicking Zoom Extents button

Can see dwg created with RealDWG only after clicking Zoom Extents button

Anonymous
Not applicable
2,071 Views
6 Replies
Message 1 of 7

Can see dwg created with RealDWG only after clicking Zoom Extents button

Anonymous
Not applicable

Hello,

I created a dwg file using RealDWG 2018, but when I open it in TrueView, nothing shown until I press Zoom Extents button.

Then the drawing appears correctly in the center of the screen.

 

What should I do so that it would appear correctly right after being opened without the need to press this button?

 

Thank you

0 Likes
2,072 Views
6 Replies
Replies (6)
Message 2 of 7

MattKincaid
Advocate
Advocate

Anyone ever figure this one out?  I'm stuck on the same thing.

 

I see the View class has a method called ZoomExtents().  But how do you get the relevant View?  My end goal is to have it so my app creates a DWG with zoomExtents already applied to Model Space.

 

Thanks!

0 Likes
Message 3 of 7

ActivistInvestor
Mentor
Mentor

The first entry in the ViewportTable (which has the name "*Active") is the view that AutoCAD uses when you open a DWG file.

 

So you have to modify/add that entry to establish the view that will be shown when you open the file.

 


@MattKincaid wrote:

Anyone ever figure this one out?  I'm stuck on the same thing.

 

I see the View class has a method called ZoomExtents().  But how do you get the relevant View?  My end goal is to have it so my app creates a DWG with zoomExtents already applied to Model Space.

 

Thanks!


 

0 Likes
Message 4 of 7

MattKincaid
Advocate
Advocate

Thanks ActivistInvestor.  That sort of gets at what I'm trying to do.

 

The issue is that I'm developing this as a RealDWG app (i.e. no instance of AutoCad is opened). The goal is to have ZoomExtents already done the next time someone opens the file in Acad (as the OP is also trying to do). In this state, it appears the ViewPortTable is empty for newly created DWGs.

 

So is the correct strategy something like as follows?

 

1.  Create a new ViewPortTableRecord

2.  Add that record to the ViewPortTable.

3.  Then what?  The ViewPortTableRecord class doesn't have a ZoomExtents method.  Is there a way to cast a ViewPortTableRecord as a View?

 

Many thanks!

0 Likes
Message 5 of 7

ActivistInvestor
Mentor
Mentor

Any ZoomExtents() method will most-likely not work in RealDwg.

 

I'm not sure if Database.UpdateExt() will work in RealDwg, but if it does then you would call it, and then read the Database's Extmin and Extmax properties to get the extents rectangle.

 

If UpdateExt() doesn't work in RealDwg, the only other way to calculate the extents is by iterating over the objects in the space shown in the view, and unioning each of their GeometricExtents together (e.g., Create a new Extents3d instance, and then repeatedly use it's AddExtents() method to add the GeometricExtents of each entity in the space).

 

So, if your view is in model space, you have to create a new ViewportTableRecord, and then compute the extents rectangle using either means described above, and set the center and height properties of the ViewportTableRecord to the center and height of the calculated extents rectangle.

 


@MattKincaid wrote:

Thanks ActivistInvestor.  That sort of gets at what I'm trying to do.

 

The issue is that I'm developing this as a RealDWG app (i.e. no instance of AutoCad is opened). The goal is to have ZoomExtents already done the next time someone opens the file in Acad (as the OP is also trying to do). In this state, it appears the ViewPortTable is empty for newly created DWGs.

 

So is the correct strategy something like as follows?

 

1.  Create a new ViewPortTableRecord

2.  Add that record to the ViewPortTable.

3.  Then what?  The ViewPortTableRecord class doesn't have a ZoomExtents method.  Is there a way to cast a ViewPortTableRecord as a View?

 

Many thanks!


 

 

Message 6 of 7

Anonymous
Not applicable

it can be use: Database.UpdateExt()

 

Message 7 of 7

MattKincaid
Advocate
Advocate

Thanks guys.  UpdateExtents did work for getting the extents, and I was able to access the "*Active" Viewport after all, even w/o an opened acad instance.  Here's the code.

 

            viewPortTable = tr.GetObject(AcadDatabase.ViewportTableId, OpenMode.ForWrite)
            viewPortRecord = tr.GetObject(viewPortTable.Item("*Active"), OpenMode.ForWrite)


            'Update database extents
            AcadDatabase.UpdateExt(doBestFit)

            'Get screen aspect ratio
            Dim aspect = viewPortRecord.Width / viewPortRecord.Height

            'Get bounding box extents
            Dim mMaxExt As Point3d = AcadDatabase.Extmax
            Dim mMinExt As Point3d = AcadDatabase.Extmin

            ' prepare Matrix for DCS to WCS transformation 
            Dim transformMatrix As Matrix3d
            transformMatrix = Matrix3d.PlaneToWorld(viewPortRecord.ViewDirection)

            transformMatrix = Matrix3d.Displacement(New Vector3d(viewPortRecord.Target.X, viewPortRecord.Target.Y, viewPortRecord.Target.Z)) * transformMatrix

            transformMatrix = Matrix3d.Rotation(-viewPortRecord.ViewTwist, viewPortRecord.ViewDirection, viewPortRecord.Target) * transformMatrix

            transformMatrix = transformMatrix.Inverse()


            ' tranform the extents to the DCS 
            Dim mExtents As New Extents3d(mMinExt, mMaxExt)
            mExtents.TransformBy(transformMatrix)

            ' width of the extents in current view 
            Dim mWidth As Double
            mWidth = (mExtents.MaxPoint.X - mExtents.MinPoint.X)

            ' height of the extents in current view 
            Dim mHeight As Double
            mHeight = (mExtents.MaxPoint.Y - mExtents.MinPoint.Y)

            ' get the view center point 
            Dim mCentPt As New Point2d(((mExtents.MaxPoint.X + mExtents.MinPoint.X) * 0.5), ((mExtents.MaxPoint.Y + mExtents.MinPoint.Y) * 0.5))


            ' check if the width 'fits' in current window,  if not then get the new height as per the viewports aspect ratio 

            If mWidth > (mHeight * aspect) Then
                mHeight = mWidth / aspect
            End If


            ' Set the viewport parameters
            viewPortRecord.Height = mHeight * 1.01
            viewPortRecord.Width = viewPortRecord.Height * aspect
            viewPortRecord.CenterPoint = mCentPt

 

0 Likes