PDA

View Full Version : lower & upper bounds of the current window/view?



n8wex
2009-08-21, 04:42 PM
How can I get the lower & upper bounds of the current MS window/view extents?

Dim lowerbounds1 As New Geometry.Point3d(-10000, -10000, 0)
Dim UpperBounds1 As New Geometry.Point3d(10000, 10000, 0)

The code below works perfect for what I need but it zooms into the hardcoded coordinates above I need it to zoom into same location from the last drawing opened.

Can anyone help?

Thanks.


Dim Mytransman As Autodesk.AutoCAD.DatabaseServices.TransactionManager
Dim Mytrans As Autodesk.AutoCAD.DatabaseServices.Transaction
Dim MyDWG As Autodesk.AutoCAD.ApplicationServices.Document
Dim MyDWGDB As Autodesk.AutoCAD.DatabaseServices.Database
Dim MyEd As EditorInput.Editor
MyDWG = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
Mytransman = MyDWG.TransactionManager
Mytrans = Mytransman.StartTransaction
MyDWGDB = MyDWG.Database
MyEd = MyDWG.Editor
Dim currentvisstyle As New Autodesk.AutoCAD.GraphicsInterface.VisualStyle


Dim lowerbounds1 As New Geometry.Point3d(-10000, -10000, 0)
Dim UpperBounds1 As New Geometry.Point3d(10000, 10000, 0)


Dim cVP1 As Integer = System.Convert.ToInt32(Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("CVPORT"))
Dim ZoomWindow1 As Autodesk.AutoCAD.GraphicsSystem.View = MyDWG.GraphicsManager.GetGsView(cVP1, True)
ZoomWindow1.ZoomExtents(lowerbounds1, UpperBounds1)
MyDWG.GraphicsManager.SetViewportFromView(cVP1, ZoomWindow1, True, True, False)
'MyEd.Regen()


ZoomWindow1.Dispose()
Mytrans.Commit()
Mytrans.Dispose()
Mytransman.Dispose()

howardjosh
2009-08-22, 03:21 AM
from the sounds of it. All you need to do is find a place to store some numbers. After that you would need a test to see if the place you stored them currently has value. I guess it really depends on what the point of this is. If you are planning on making it so that autocad remembers it every time. You could demand load your app and store the values in the registry somewhere.

If it is going to be part of a command that is "activated" at some point (possibly through the act of storing the value). Then you could probably get away with a global variable. In which case you could declare those as point3d variables and just use them in place of your hard coded ones "when available"

if pt1 <> nothing andalso pt2 <> nothing then
ZoomWindow1.ZoomExtents(pt1, pt2)
else
ZoomWindow1.ZoomExtents(lowerbounds1, UpperBounds1)
endif

in case you don't know; globals are declared per class. So just after your opening class statement you could put "Dim pt1,pt2 as point3d"

unlike lisp your .net commands stay loaded even if there is no document open that would use them. So to the best of my knowledge you should be able to load a document reactor once and keep recycling it to accomplish what you are wanting to do. *shrug* I am still new at this so I could be way off base there.

edit: keep in mind that if <> nothing doesn't work IsNot nothing often does, and sometimes = or Is nothing seems to be the only thing that doesn't yield an error. play with those and you'll find the right combo

edit2: ok I just read that again... I missed the point, I read your other post and I would say its probably more spot on. Here is a way of getting the current viewtable record
Dim dbo As DBObject = ed.GetCurrentView
Dim vtr As ViewTableRecord = CType(dbo, ViewTableRecord )

n8wex
2009-09-27, 09:42 AM
I ended up writing a class to store this information from the active doc and reset it in the next open / active document seems to work well apart from when there is a UCS and in paperspace layouts. I am currently trying to sort out these last 2 issues. Any help appreciated.

View class


Imports AC_App = Autodesk.AutoCAD.ApplicationServices.Application

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput


Public Class FloorSurferView

Private m_ptMax As Point3d
Private m_ptMin As Point3d

Public Sub New()
SetMinMax()
End Sub

Private Sub SetMinMax()
Dim acDoc As Document = AC_App.DocumentManager.MdiActiveDocument

Using acView As ViewTableRecord = acDoc.Editor.GetCurrentView()

Dim pCenter As Point3d = New Point3d(acView.CenterPoint.X, acView.CenterPoint.Y, 0)
m_ptMin = New Point3d(pCenter.X - (acView.Width / 2), pCenter.Y - (acView.Height / 2), 0)
m_ptMax = New Point3d(pCenter.X + (acView.Width / 2), pCenter.Y + (acView.Height / 2), 0)
End Using
End Sub

Public Sub Zoom()

If m_ptMin.Equals(New Point3d()) = True And m_ptMax.Equals(New Point3d()) = True Then
Exit Sub
End If

Dim min2d As Point2d = New Point2d(m_ptMin.X, m_ptMin.Y)
Dim max2d As Point2d = New Point2d(m_ptMax.X, m_ptMax.Y)
Dim view As ViewTableRecord = New ViewTableRecord
view.CenterPoint = (min2d + ((max2d - min2d) / 2))
view.Height = (max2d.Y - min2d.Y)
view.Width = (max2d.X - min2d.X)
On Error Resume Next
AC_App.DocumentManager.MdiActiveDocument.Editor.SetCurrentView(view)
End Sub

Private ReadOnly Property Min()
Get
Return m_ptMin
End Get
End Property

Private ReadOnly Property Max()
Get
Return m_ptMax
End Get
End Property
End Class


call example


Private Sub Activate()


View = New FloorSurferView

'Activate new document

View.Zoom()

End Sub

n8wex
2009-09-27, 10:16 AM
My question is how do I apply the following code to a layout?



Using acView As ViewTableRecord = acDoc.Editor.GetCurrentView()

Dim pCenter As Point3d = New Point3d(acView.CenterPoint.X, acView.CenterPoint.Y, 0)
m_ptMin = New Point3d(pCenter.X - (acView.Width / 2), pCenter.Y - (acView.Height / 2), 0)
m_ptMax = New Point3d(pCenter.X + (acView.Width / 2), pCenter.Y + (acView.Height / 2), 0)
End Using

n8wex
2009-09-29, 01:12 PM
This works perfect.



Imports AC_App = Autodesk.AutoCAD.ApplicationServices.Application

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Interop

Public Class FloorSurferView

Private pMax As Point3d
Private pMin As Point3d

Public Sub New()
SaveView()
End Sub

Private Sub SaveView()

Dim ed As Editor = AC_App.DocumentManager.MdiActiveDocument.Editor

Using acView As ViewTableRecord = ed.GetCurrentView()

Dim pCenter As Point3d = New Point3d(acView.CenterPoint.X, acView.CenterPoint.Y, 0)
pMin = New Point3d(pCenter.X - (acView.Width / 2), pCenter.Y - (acView.Height / 2), 0)
pMax = New Point3d(pCenter.X + (acView.Width / 2), pCenter.Y + (acView.Height / 2), 0)

End Using

End Sub

Public Sub Zoom()

Dim app As AcadApplication = CType(Application.AcadApplication, AcadApplication)
Dim lower() As Double = New Double() {pMin.X, pMin.Y, pMin.Z}
Dim upper() As Double = New Double() {pMax.X, pMax.Y, pMax.Z}
app.ZoomWindow(lower, upper)

End Sub

End Class