Jump to content

Recommended Posts

Posted

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

Posted

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)

Posted

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)
)

Posted

great, it should solve my problems !!!

 

Thank you very much Msasu

Posted

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)
)

  • Like 1

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...