Jump to content

cvport variable issue


MiGo

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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

 )

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)?

Link to comment
Share on other sites

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))

Link to comment
Share on other sites

  • 8 years later...

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.

Link to comment
Share on other sites

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)
)

Link to comment
Share on other sites

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