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

Zooming to an Object in Acad 2006

3 REPLIES 3
Reply
Message 1 of 4
Anonymous
211 Views, 3 Replies

Zooming to an Object in Acad 2006

Having looked around and used code listed in previous posts I am trying to write a generic function to zoom to an object.

Private Sub ZoomObject(TargetID As ObjectId )
Using db As Database = Application.DocumentManager.MdiActiveDocument.Database
Using trans As Transaction =db.TransactionManager.StartTransaction
Using btr As BlockTableRecord = trans.GetObject(db.CurrentSpaceId,OpenMode.ForWrite, False)
Dim pApp As AcadApplication
pApp = Autodesk.AutoCAD.ApplicationServices. Application.AcadApplication
Dim zoomobj As Autodesk.AutoCAD.DatabaseServices.Entity =trans.GetObject(targetid, OpenMode.ForRead)
dim zoomext as Extents3d = zoomobj.GeomExtents

dim ptll as Point3d = zoomext.MinPoint
Dim ptur As Point3d =zoomext.MaxPoint

'Write the points to the command line for debugging purposes
editor.WriteMessage(vbNewLine & "LL Corner " & ptll.ToString)
editor.WriteMessage(vbNewLine & "UR Corner " & ptUR.ToString)

pApp.ZoomWindow ( ptll.ToArray() , ptur.ToArray())
papp = Nothing
End Using
End Using
End Using

End Sub


The problem is this seems not to do anything. The display is not updated. Any idea where I am going wrong??
3 REPLIES 3
Message 2 of 4
MarkPendergraft
in reply to: Anonymous

don't ask me why, but i think it has something to do with using the pApp.zoomwindow function inside a Using block.

try this code, its the same thing but with the zoomwindow method moved to the end of the sub, it works for me



Private Sub ZoomObject(ByVal TargetID As ObjectId)
Dim editor As Editor = Application.DocumentManager.MdiActiveDocument.Editor

Dim ptll As Point3d
Dim ptur As Point3d
Dim pApp As Autodesk.AutoCAD.Interop.AcadApplication
pApp = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication

Using db As Database = Application.DocumentManager.MdiActiveDocument.Database
Using trans As Transaction = db.TransactionManager.StartTransaction
Using btr As BlockTableRecord = trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite, False)

Dim zoomobj As Autodesk.AutoCAD.DatabaseServices.Entity = trans.GetObject(TargetID, OpenMode.ForRead)
Dim zoomext As Extents3d = zoomobj.GeomExtents

ptll = zoomext.MinPoint
ptur = zoomext.MaxPoint

'Write the points to the command line for debugging purposes
editor.WriteMessage(vbNewLine & "LL Corner " & ptll.ToString)
editor.WriteMessage(vbNewLine & "UR Corner " & ptur.ToString)


End Using
End Using
End Using

pApp.ZoomWindow(ptll.ToArray(), ptur.ToArray())
pApp = Nothing

End Sub
Message 3 of 4
Anonymous
in reply to: Anonymous

That works great Thank you.

On this note, is it possible to halt further program execution until the zoom is finished? I have a problem that I am copying a polyline and any hatch it contains to the modelspace extents (to get clear space) exploding the hatch and then using the lines to form boundaries and then using the boundary command . The Main problem is that you cannot interact with the new objects as they are not in the current display (using the polyline to build a crossing window selection will not select any objects, hence the need to zoom to the polyline so that everything is now in the display area.) Unfortunatly as the program execution passes the zoom window command, in a large drawing this may take a few seconds to refresh, if the objects cannot be "seen" the program fails. Have you any advice on how to either interact with objects outside the display area ?
Message 4 of 4
MarkPendergraft
in reply to: Anonymous

i don't really have any experience with what your talking about. Have you tried zooming to the object, and then using the editor.getkeyword() method.

If you call editor.getkeyword(), you could set the program up to only continue when the user presses a certain button (like "enter")

you could set your program to zoom, and then have AutoCAD pause for user input, with a message to the user "Press Enter Once Zoom Operation is Complete"

When they press enter the program continues.


I'm not quite sure what you mean by interacting with objects outside the display area. You shouldn't have any issues selecting objects programatically anywhere in the drawing. However user interaction is a different story. Does the user have to select the polyline more than once?

What is the end goal of your program? Often i find that there are several ways to accomplish what you want to do, the important part is the end result. Maybe there is a different solution to explore if you are having issues.

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