LauKwokFai Posted June 5, 2012 Posted June 5, 2012 Hi all, I wonder if there is any method to "activate" a selected viewport using AutoLisp (rather not VLisp, cos I don't know any VLisp at all !!!) for example if I draw a rectangle on a viewport in paper space and I want to transfer this rectangle into model space, I would use CAD command "chspace", but then I need to click on the particlar viewport so that the rectangle goes to the right place. Also if I want to make the viewport image to a particular scale, say 1:20, I also have to click into the viewport and type "zoom" "1/20xp". What I cannot figure out is how I can use AutoLisp to "activate" a selected viewport. Thank you so much Quote
MSasu Posted June 5, 2012 Posted June 5, 2012 The ID of each viewport is stored in DXF code 69 (use ENTGET function to list). Next use CVPORT system variable to activate a particular viewport. (command "_MSPACE") (setvar "CVPORT" 2) Quote
MSasu Posted June 5, 2012 Posted June 5, 2012 There is also the VPORTS function that will list the viewports defined in a layout (1 is always Paper Space). ;;; Cycle Through Viewports (05-VI-2012) (defun c:CTV( / oldCmdEcho listVPorts itemVPort ) (vl-load-com) (setq oldCmdEcho (getvar "CMDECHO")) (setvar "CMDECHO" 0) (if (/= (getvar "CTAB") "Model") (progn (setq listVPorts (vl-sort (vports) '(lambda(v1 v2) (< (car v1) (car v2))))) (if (> (length listVPorts) 1) (progn (command "_MSPACE") (foreach itemVPort (cdr listVPorts) (setvar "CVPORT" (car itemVPort)) (getkword "\nPress <ENTER> to go to next viewport") ) (command "_PSPACE") ) (prompt "\nThere are no viewports defined in this Layout!") ) ) (prompt "\nThis routine works only in Layout!") ) (setvar "CMDECHO" oldCmdEcho) (princ) ) Quote
LauKwokFai Posted June 5, 2012 Author Posted June 5, 2012 great, it should solve my problems !!! Thank you very much Msasu Quote
Lee Mac Posted June 5, 2012 Posted June 5, 2012 Another method: (defun c:vpon ( / d s ) (vl-load-com) (if (setq s (ssget "_+.:S:E:L" '((0 . "VIEWPORT")))) (progn (setq d (vla-get-activedocument (vlax-get-acad-object))) (vla-put-mspace d :vlax-true) (vla-put-activeviewport d (vlax-ename->vla-object (ssname s 0))) ) ) (princ) ) And to 'deactivate': (defun c:vpoff ( ) (vla-put-mspace (vla-get-activedocument (vlax-get-acad-object)) :vlax-false) (princ) ) 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.