TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Adesu on August 04, 2008, 03:27:45 AM

Title: How to set active viewport
Post by: Adesu on August 04, 2008, 03:27:45 AM
I got problem to active one of 4 viewports, anyone have code? or please guide me
(defun c:test (/)
  (command "_vports" 4 "")
  ; I want viewport upper left corner active how to set it
  )
Title: Re: How to set active viewport
Post by: Patrick_35 on August 04, 2008, 05:04:54 AM
Hi

You go in modelspace to change cvport

@+
Title: Re: How to set active viewport
Post by: SKUI_BREAKER on August 04, 2008, 07:31:42 AM
I FOUND THIS OUT BY ACCIDENT AND I WILL NEVER FORGET IT
CTRL-R TO CYCLE TRHOUGH THE VIEWPORTS
Title: Re: How to set active viewport
Post by: Alan Cullen on August 04, 2008, 07:39:39 AM
Hey, SKUI_BREAKER......

Well done mate...but did you really have to scream into my headphones with that revelation? I'm still trying to find my earpiece.........aha...found it........now, can I get back to normal?  :lmao: :lmao:
Title: Re: How to set active viewport
Post by: SKUI_BREAKER on August 04, 2008, 08:14:10 AM
SORRY BOUT THE CAPS I ALWAYS KEEP IT ON BY HABIT
Title: Re: How to set active viewport
Post by: Crank on August 04, 2008, 09:18:16 AM
(http://www.offthemarkcartoons.com/cartoons/2004-10-09.gif)
Title: Re: How to set active viewport
Post by: CAB on August 04, 2008, 03:13:13 PM
Try this:
Code: [Select]
       (vla-put-mspace doc :vlax-true)
       (setvar "cvport" vpid) ; CAB activate correct vp

Not a complete code so ask if you don't get it.
Title: Re: How to set active viewport
Post by: CAB on August 04, 2008, 03:15:28 PM
This will give you some more info.
Used to select two entity viewports.
Code: [Select]
;;;       ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;;;       +                 Viewport Select                        +
;;;       +            Created by C. Alan Butler                   +
;;;       +               Copyright 2005                           +
;;;       +   by Precision Drafting & Design All Rights Reserved.  +
;;;       +    Contact at ab2draft@TampaBay.rr.com                 +
;;;       ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;;;  Returns the viewport entity name, ignoring second entities used when
;;;  a non-standard viewport is created, circle, ellipse, LWpolyline
(defun vp_sel (/ vpflag sel-vport entvport vptest)
  (if (= (getvar "TileMode") 1) ; in model space
    ;;------------------------------------------------
    (progn
      (alert "****  You must be in Paper Space to run this routine.  ****")
    )
    ;;------------------------------------------------
    (progn ;else in a layout
      (if (/= (getvar "cvport") 1)
        (command "_.pspace") ; close the view port
      )
      (setq vpflag (getvar "cvport")) ; get viewport #
      (while (= vpflag 1) ; No active viewport, Loop until one is picked
        (setq sel-vport (car (entsel "\nSelect view port: ")))
        (if (= sel-vport nil)
          (alert
            "You must select a viewport\r\n    --=<  Try again!  >=--"
          )
          (progn
            (setq entvport (entget sel-vport))
            (if (and ;; not all vp objects are LWPolylines
                     ;;(= (cdr (assoc 0 entvport)) "LWPOLYLINE")
                     (setq vptest (member '(102 . "{ACAD_REACTORS") entvport))
                     (setq vptest (member '(102 . "}") (reverse vptest)))
                     (assoc 330 vptest)
                )
              (setq entvport (entget (cdr (assoc 330 vptest))))
            )
            ;;  Make VP active
            (if (= (cdr (assoc 0 entvport)) "VIEWPORT")
              (progn
                (setq vpflag (cdr (assoc 69 entvport)))
                (command "mspace") ; activate the last vp active
                (setvar "cvport" vpflag) ; switch to this vp
              ) ;  endif  viewport
            )
          )
        ) ;  endif cond  sel-vport
      ) ;endwhile (= vpFlag 1)
      (command "_.pspace") ; close the view port
    )
  )
  ;;  return the ename of vp or nil
  (cond (entvport (cdr (assoc -1 entvport))))
)
Title: Re: How to set active viewport
Post by: Adesu on August 04, 2008, 08:37:06 PM
Hi CAB,
I only change for one position(only for "UL"), but not for others, anyone know to find what wrong in my code.
Code: [Select]
(defun c:test (/ pos tm)
  (setq tm (getvar "tilemode"))
  (if
    (= tm 1)
    (setvar "tilemode" 0)
    ) ; if
  (if
    (/= (getvar "cvport") 1)
    (command "_vports" 4 "")
    )
  (while
    (setq pos (strcase (getstring "\nSelect VPORTS position[UL/LL/UR/LR]<UL>: ")))
    (if (= pos "")(setq pos "UL"))
    (cond
      ((= pos "UL")(setq pos 4))
      ((= pos "LL")(setq pos 5))
      ((= pos "UR")(setq pos 3))
      ((= pos "LR")(setq pos 6)))
    (setvar "cvport" pos)
    ) ; while
  (princ)
  ) ; defun

Try this:
Code: [Select]
       (vla-put-mspace doc :vlax-true)
       (setvar "cvport" vpid) ; CAB activate correct vp

Not a complete code so ask if you don't get it.
Title: Re: How to set active viewport
Post by: Crank on August 05, 2008, 10:10:04 AM
It works for me, but I think your viewport numbers are different.
You should try to find those numbers first:
Code: [Select]
(setq l (lastent))
(command "_vports" 4 "")
(setq vp1 (entnext l) vp2 (entnext vp1) vp3 (entnext vp2) vp4 (entnext vp3))
(setq vp1nr (cdr (assoc 69 (entget vp1))) posVP1 (cdr (assoc 10 (entget vp1))))
...
Code: [Select]
(defun LASTENT (/ E0 EN)
(setq E0 (entlast))
(while (setq EN (entnext E0))
(setq E0 EN)
)
E0
)