+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Full Member LauKwokFai's Avatar
    Discipline
    See details...
    LauKwokFai's Discipline Details
    Occupation
    Interior Design, CAD superior
    Discipline
    See details below.
    Details
    Interior Design
    Using
    AutoCAD 2011
    Join Date
    Sep 2009
    Location
    Hong Kong
    Posts
    63

    Default How to using Lisp to "activate" a viewport

    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

  2. #2
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    3,743

    Default

    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.
    Code:
    (command "_MSPACE")
    (setvar "CVPORT" 2)
    Regards,
    Mircea

    AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3

  3. #3
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    3,743

    Default

    There is also the VPORTS function that will list the viewports defined in a layout (1 is always Paper Space).
    Code:
     ;;; 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)
    )
    Regards,
    Mircea

    AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3

  4. #4
    Full Member LauKwokFai's Avatar
    Discipline
    See details...
    LauKwokFai's Discipline Details
    Occupation
    Interior Design, CAD superior
    Discipline
    See details below.
    Details
    Interior Design
    Using
    AutoCAD 2011
    Join Date
    Sep 2009
    Location
    Hong Kong
    Posts
    63

    Default

    great, it should solve my problems !!!

    Thank you very much Msasu

  5. #5
    Forum Deity MSasu's Avatar
    Discipline
    Construction
    MSasu's Discipline Details
    Occupation
    engineer
    Discipline
    Construction
    Details
    AutoLISP programmer
    Using
    AutoCAD 2013
    Join Date
    Mar 2009
    Location
    Brasov, Romania
    Posts
    3,743

    Default

    You're entirely welcome!
    Regards,
    Mircea

    AutoCAD's happy user equation: FILEDIA + PICKADD² + PICKFIRST = 3

  6. #6
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    16,619

    Default

    Registered forum members do not see this ad.

    Another method:

    Code:
    (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':

    Code:
    (defun c:vpoff ( )
        (vla-put-mspace (vla-get-activedocument (vlax-get-acad-object)) :vlax-false)
        (princ)
    )
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

Similar Threads

  1. Export properties ("measurement") of "Aligned Dimension" to Excel
    By nhatquyelec in forum AutoLISP, Visual LISP & DCL
    Replies: 8
    Last Post: 1st Feb 2013, 07:58 am
  2. Extracting the "Custom scale" value from an existing viewport
    By landsurveying in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 18th Dec 2011, 10:45 am
  3. "Hidden" line turns to "continuous" in layout view
    By jeck in forum AutoCAD General
    Replies: 12
    Last Post: 19th Jun 2011, 12:44 pm
  4. Replies: 1
    Last Post: 25th Nov 2009, 06:35 pm
  5. "Freeze in current viewport" does not work...
    By bnsc in forum AutoCAD Beginners' Area
    Replies: 2
    Last Post: 17th Jun 2008, 07:28 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts