PDA

View Full Version : Creating Viewports


bweir
2007-06-25, 09:31 PM
How can you zoom a view port to a given point in model space?

I am creating a function that creates a view port zoomed to a given point. I'm having difficulty with changing the center of the view port to be the point I want in Model space. I assumed the Target property of the view port was what I needed to change but this does not seem to work.

Here's a snippet I've been using for testing.

(setq Dwg (vla-get-activedocument (vlax-get-acad-object)))
(setq Space (vla-get-paperspace Dwg))
(setq ViewPort (vla-AddPViewport Space (vlax-3d-point 1000 1000) 500 500))
(vla-put-target ViewPort (vlax-3d-point 60 70 0))

T.Willey
2007-06-25, 10:03 PM
To use 'vlax-3d-point' you must give it a point (a list of three numbers). So try
(vlax-3d-point '(60 70 0))

bweir
2007-06-25, 10:54 PM
(vlax-3d-point ...) also has the option of excepting two (X & Y) or three (X, Y, & Z) values. Check the AutoCAD Help: Developer Document ion, it explains the variable options for this function.

T.Willey
2007-06-25, 11:21 PM
Guess that is what happens when you don't use a function anymore. Thanks I learned something new today.

Maybe you have to make the viewport active, then use the zoom method on the acad object.

CAB2k
2007-06-25, 11:42 PM
vla-put-target ?
http://tinyurl.com/22yagb

kennet.sjoberg
2007-06-26, 11:18 AM
There is
modelspace coordinates
paperspace coordinates
and
display coordinates
here is a simple code to pan a viewport to the center

(command "._ucs" "" )
(setq PsPnt (getpoint)) ; PaperSpacePoint, or assoc 10 of the VIEWPORT object to get the centre of it

(command "._mspace" )
(setq MsPnt1 (trans PsPnt 3 2 ) ) ; Convert PaperSpaceCoordinate to DisplayCoordinate of the current model space viewport
(setq MsPnt2 (getpoint "\nPick model point to center : " ) )
(command "._-pan" MsPnt2 MsPnt1 )


: ) Happy Computing !

kennet

bweir
2007-06-26, 04:02 PM
Here's my solution, not exactly what I was hoping for but it'll work for now.


; Draw the view port.
(setq ViewPort (vla-AddPViewport (vla-get-paperspace Dwg) (vlax-3d-point 524.5 1223.125) 954.25 540))
; Change the layer.
(vl-catch-all-apply 'vla-put-layer (list ViewPort "VPorts"))
; Turn on the view port, critical step to activate the viewport.
(vla-display ViewPort :vlax-true)
; Activate a view port.
(vla-put-mspace Dwg :vlax-true)
; Set the new view port as the active view port.
(vla-put-activepviewport Dwg ViewPort)
; Zoom to the required location.
(vla-zoomcenter (vlax-get-acad-object) (vlax-3d-point X Y 0) 1)
; Deactivate the view port (jump back to paper space).
(vla-put-mspace Dwg :vlax-false)
; Set the scale.
(vla-put-StandardScale ViewPort 1)
(vla-put-customscale ViewPort (/ 2 3.0))