MiGo Posted March 30, 2009 Share Posted March 30, 2009 I am working on a drawing that only has two viewports, so the cvport should be 1 for the paperspace window, 2 for the first viewport, and 3 for the second viewport, but the last viewport is 4. When I try to go to cvport 3 it says invalid input. When I type in (length (vports)) it returns a 3. Any ideas why this is, and a way to correct it? It is messing up a script of mine that performs a function and exits after all viewports have been completed, so It's exiting without doing the second viewport which should be cvport #3. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 30, 2009 Share Posted March 30, 2009 I think Model Space itself is considered a "viewport" entry for the CVPORT listing, if that helps at all. Quote Link to comment Share on other sites More sharing options...
MiGo Posted March 30, 2009 Author Share Posted March 30, 2009 It does return an integer when your in model for the line (length (vports)) of 1, but that doesn't affect the number that the viewport sets as the cvport. Plus this is the only drawing that I have seen with this issue. Every other drawing with the typical one model tab and one layout tab returns the numbers correctly. There was a named view and I removed it, closed and reopened the drawing but the numbers were still the same. Quote Link to comment Share on other sites More sharing options...
MiGo Posted March 31, 2009 Author Share Posted March 31, 2009 Is there an if statement that can see an error? Such as when I change the cvport to 3 If it returns an error go to cvport 4? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 31, 2009 Share Posted March 31, 2009 The CVPORT just switches between the viewports by their individual identification number, so if you create say two viewports you will have something like ((1 (blah blah)) (2 (blah blah)) (3 (blah blah))) But if you now delete a viewport and create another one you will have something like this: ((1 (blah blah)) (2 (blah blah)) (4 (blah blah))) So, you can see why the numbers will be different Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted March 31, 2009 Share Posted March 31, 2009 As for switching using the CVPORT variable, not sure if you can maybe use something like this: (foreach v (vports) (setvar "CVPORT" (car v)) do something here ) Quote Link to comment Share on other sites More sharing options...
MiGo Posted April 2, 2009 Author Share Posted April 2, 2009 You are correct as far as while a drawing remains open that the cvport # of the viewport that was deleted is no longer valid, but when the drawing is closed and reopened then the numbering system resets it'self. So the viewport numbers will then be 2 3 and 4 rather than 2 3 and 5. Quote Link to comment Share on other sites More sharing options...
MiGo Posted April 2, 2009 Author Share Posted April 2, 2009 I found the problem. There were extra viewports in that layout tab that were turned off. They didn't add a value to the (length (vports)) but they held a slot for the variable "cvport". The viewport was a match to the outside border that was colored white, so it wasn't noticable. I assume that while creating the drawing set the person copied the titleblock from one drawing to the next, but brought the viewport along for the ride. Eraseing the viewport fixed the problem. Is there a way to find all off viewports in the current layout tab and erase them(to avoid any situations like this in the future)? Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted April 2, 2009 Share Posted April 2, 2009 This should do the trick: (defun c:test (/ ss) (if (setq ss (ssget "X" (list (cons 0 "VIEWPORT") (if (getvar "CTAB")(cons 410 (getvar "CTAB")) (cons 67 (- 1 (getvar "TILEMODE"))))))) (progn (foreach Obj (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex ss))) (if (eq :vlax-false (vla-get-ViewportOn Obj)) (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-delete (list Obj))) (princ "\n<!> Object on Locked Layer <!>"))))) (princ "\n<!> No Viewports Found <!>")) (princ)) Quote Link to comment Share on other sites More sharing options...
Shoey Posted May 18, 2017 Share Posted May 18, 2017 An old post but....... I was searching for a simple lisp to check for any Viewports that are turned OFF in a layout. My search brought me to this post. I have fiddled it a bit with a if statement to see if any viewports found are off. It works, but Im sure it can be improved and also would like a message to inform that all Viewports are on. (defun c:test (/ ss dfg) (if (setq ss (ssget "X" (list (cons 0 "VIEWPORT") (if (getvar "CTAB")(cons 410 (getvar "CTAB")) (cons 67 (- 1 (getvar "TILEMODE"))))))) (progn (foreach Obj (mapcar 'vlax-ename->vla-object (mapcar 'cadr (ssnamex ss))) (if (eq :vlax-false (vla-get-ViewportOn Obj)) (setq dfg T) (if (= dfg T) (alert "WARNING! Some or ALL Viewports are turned OFF!")) ))) ) (princ)) Thanks for any help. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted May 18, 2017 Share Posted May 18, 2017 Try the following: (defun c:vpoff ( / sel ) (if (setq sel (ssget "_X" (list '(0 . "VIEWPORT") '(68 . 0) (cons 410 (getvar 'ctab))))) (alert (strcat "WARNING!\n\n" (itoa (sslength sel)) (if (= 1 (sslength sel)) " viewport is " " viewports are ") "turned off in this layout." ) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
Shoey Posted May 19, 2017 Share Posted May 19, 2017 Excellent Lee - many thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.