Jump to content

Recommended Posts

Posted

Another tip if your setting multiple variables. You can handle them with 4 lines of code.

 

(defun C:lnze (/ lyt)
  ;(setq oldEcho (getvar "CMDECHO")
  ;      oldNOMUTT (getvar "NOMUTT")
  ;      lyt (getvar "CTAB")
  ;)
  (setq vars '(cmdecho nomutt ctab)  ;list of variables as many as you want.
        vals (mapcar 'getvar vars)   ;store old values to a list
  )
  ;(setvar 'CMDECHO 0)
  ;(setvar 'NOMUTT 1)
  (mapcar 'setvar vars '(0 1))  ;this sets cmdecho 0 and nomutt 1, stops at short list so ctab isn't changed.
  (vl-catch-all-apply
    '(lambda ()
      (foreach lay (layoutlist)
        (setvar 'CTAB lay)
        (setvar 'CVPORT 1)
        (vl-cmdf "_.ZOOM" "_E")
      )
    )
  )
  ;(setvar "CTAB" lyt)
  ;(setvar "CMDECHO" oldEcho)
  ;(setvar "NOMUTT" oldNOMUTT)
  (mapcar 'setvar vars vals)  ;restore old values
  (princ)
)

 

Posted
38 minutes ago, ronjonp said:

Side topic but I've found that this:
 

(setq ss (ssget "_X" '((0 . "VIEWPORT") (-4 . "!=") (69 . 1))))

 

Does not work with layouts that are not initialized.

 

CAB at TheSwamp put this together many moons ago and it's been solid ( don't remember what the function was originally named 😳)

(defun rjp-getvports (/ a b c lst ss)
  (if (setq ss (ssget "_X" '((0 . "VIEWPORT"))))
    (progn (foreach e (mapcar 'cadr (ssnamex ss))
	     ;;Paper space block
	     (if (and (setq a (cdr (assoc 330 (entget e))))
		      ;;Layout
		      (setq b (cdr (assoc 340 (entget a))))
		      ;;Viewport not wanted
		      (setq c (cdr (assoc 331 (entget b))))
		 )
	       (or (equal c e) (setq lst (cons (list e (cdr (assoc 71 (entget b)))) lst)))
	     )
	   )
    )
  )
  ;;Sort the list by taborder L 2 R
  (mapcar 'car (vl-sort lst (function (lambda (x y) (< (cadr x) (cadr y))))))
)


 

 

@ronjonp  When I first open the sample TrueViewports.dwg I shared in a previous post which defaults to Layout2 and I run (length (rjp-getvports)) I get 7. Even after initializing by clicking on Layout1. I still get 7.

But after clicking on Layout2 when I run @DavidP code I get 6: 

(sslength(setq ss (ssget "_X" '((0 . "VIEWPORT") (-4 . "<>") (69 . 1) (410 . "~Model")))))

Likewise when I run my code I posted earlier I also get 6:

(sslength (ssget "_X" '((0 . "VIEWPORT") (67 . 1) (-4 . "/=") (69 . 1))))

I think mine & @DavidP code is similar. But what I don't see is whether @DavidP code is filtering out something more than compared to mine.

 

Posted

 

Just a comment using Bricscad only finds.

 

D05
(sslength (ssget "_X" '((0 . "VIEWPORT") (67 . 1) (-4 . "/=") (69 . 1))))
returns 4

D03 = 4
D05
(sslength (setq ss (ssget "_X" (list (cons 0  "VIEWPORT") (cons 410 (getvar 'ctab))))))
returns 1 ie no normal viewports

D03 = 2 a pspace and 1 viewport

 

 The order of SS is Viewport...Viewport Pspace may be different in Acad. I copied viewports for testing. Then erased one by one using (ssname ss X) can not erase pspace of course.

 

  • 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...