See the top rated post in this thread. Click here

Results 1 to 6 of 6

Thread: Automating Viewports in AutoLISP

  1. #1
    Member
    Join Date
    2011-08
    Posts
    8
    Login to Give a bone
    0

    Default Automating Viewports in AutoLISP

    Have not used lisp in ages...

    Working with viewports...

    I want to make active the viewport in the layout I am working in.
    Automatically select the only viewport I have within the layout
    Zoom to any scale in which I am prompted.
    Deactivate the viewport
    Then regenall

    Below is a "very" basic routine (almost embarrased to show) but hopefully it will demonstrate what I am wanting to do.
    Note: The red text is the the code I am having difficulties with. I have seem many variations where developers have code to turn on or off the viewports but have not been able to translate it into my existing routine... I just don't have a high enough level of understanding ActiveX or AutoLISP. I tried using MSPACE and VPORTS commands (to toggle and or turn on/off) in my code but was not successful...

    Note: There is only one viewport in layout....

    (defun c:zxp ()
    ;;;;MSPACE active (code needed)
    (setq myxp (getstring "Enter Scale Factor: "))
    (command "zoom" (strcat "1/" myxp "XP"))
    ;;;;VPORT deactivated (code needed)
    (command "regenall")
    )

    Hope someone can help thanks!!!

    Cheers
    Last edited by sdrewinc432892; 2012-05-18 at 08:46 PM. Reason: Changed sentence

  2. #2
    Administrator rkmcswain's Avatar
    Join Date
    2004-09
    Location
    Earth
    Posts
    9,805
    Login to Give a bone
    0

    Default Re: Automating Viewports in AutoLISP

    Check out the CVPORT system variable.

    Also, check out this routine. It may have some chunks of code you can use.

    http://cadtips.cadalyst.com/viewports/viewport-zoom
    Last edited by rkmcswain; 2012-05-18 at 06:55 PM. Reason: correct sentence
    R.K. McSwain | CAD Panacea |

  3. #3
    Member
    Join Date
    2011-08
    Posts
    8
    Login to Give a bone
    0

    Default Re: Automating Viewports in AutoLISP

    Thanks,

    I will give it a go but like I said I struggle with syntax and code placement...
    Last edited by sdrewinc432892; 2012-05-18 at 08:20 PM.

  4. #4
    Member
    Join Date
    2011-08
    Posts
    8
    Login to Give a bone
    0

    Default Re: Automating Viewports in AutoLISP

    I tried this but it didn't fly...
    Everything works except the unlocking and locking of (model space)
    Evidently locking and unlocking vports are not that staightforward in AutoLISP...
    Anyone have any suggestions?

    Code:
    (vl-load-com)
    (defun c:zxp ()
    (command "vports" l off)
    (vl-cmdf "_.MSPACE")
    (setq MYXP (getstring "Enter Scale Factor: "))
    (command "zoom" (strcat "1/" MYXP "XP"))
    (command "regenall")
    (vl-cmdf "_.PSPACE")
    (command "vports" l on)
    )
    Last edited by rkmcswain; 2012-05-21 at 07:53 PM. Reason: sentence correction, add [CODE] tags

  5. #5
    All AUGI, all the time
    Join Date
    2010-10
    Posts
    535
    Login to Give a bone
    1

    Default Re: Automating Viewports in AutoLISP

    Quote Originally Posted by sdrewinc432892 View Post

    Note: There is only one viewport in layout....
    Your code and some
    Code:
    (defun c:vps  (/ vp e MYXP)
          (if (and (setq vp   (ssget "_X"
                                     (list '(0 . "VIEWPORT")
                                           (cons 410 (getvar 'ctab)))))
                   (= (sslength vp) 2))
                (progn
                      (command
                            "vports"
                            "_lock"
                            "_off"
                            (setq e (ssname vp 0))
                            "")
                      (command "_mspace")
                      (setq MYXP (getstring "Enter Scale Factor: "))
                      (command "zoom" (strcat "1/" MYXP "XP"))
                      (command "_.PSPACE")
                      (command "regenall")
                      (command "vports" "_lock" "_on" e "")
                      )
                )(princ)
          )

  6. #6
    Member
    Join Date
    2011-08
    Posts
    8
    Login to Give a bone
    0

    Default Re: Automating Viewports in AutoLISP

    Awesome...
    This is the ticket!!!

    Thank you very much...

Similar Threads

  1. CM31-1: Automating CAD Standards
    By Autodesk University in forum CAD Management
    Replies: 0
    Last Post: 2013-03-30, 02:04 AM
  2. 2012: Automating Viewports in AutoLISP
    By sdrewinc432892 in forum AutoCAD General
    Replies: 2
    Last Post: 2012-05-18, 08:07 PM
  3. Switching Between Viewports in Autolisp
    By dreamslaughter in forum AutoLISP
    Replies: 2
    Last Post: 2008-03-24, 11:39 AM
  4. Replies: 4
    Last Post: 2006-07-12, 01:27 PM
  5. Selecting smaller viewports within larger viewports
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 9
    Last Post: 2005-09-22, 01:18 PM

Posting Permissions

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