Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Why I Cannot Activate Some Viewports Found Using ssget?

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
JC_BL
995 Views, 7 Replies

Why I Cannot Activate Some Viewports Found Using ssget?

I am wondering why when I try to use (setvar "CVPORT" id) command to activate some viewports, I get this error message:

 

error: AutoCAD variable setting rejected: "CVPORT" id

 

I find those viewports using the following command:

 

(setq ssVPs (ssget "_X" '((0 . "VIEWPORT"))))

 

On the other hand, I find that those trouble-making viewports are filtered out when I use the viewports-list from (vports).  Obviously, I work around this problem by using the viewports from (vports).  Still I would like to know these:

  • Why are the list of viewports from (ssget) different from the list of viewports from (vports)?
  • What is the reason why I cannot activate those trouble-making viewports?

The following code shows the difference in those 2 approaches of activating viewports (one works, the one doesn't):

 

;This version works fine:
(defun c:vpgood
   ( /
   descriptorCurVP
   nVpId
   )
   (vl-load-com)
   (command "_MSPACE")

   (foreach descriptorCurVP (vports)
      (setq nVpId (car descriptorCurVP))
      (if (> nVpId 1)
         (progn
            (prompt (strcat "\nActivate VP with ID: '" (itoa nVpId) "'"))
            (setvar "CVPORT" nVpId)
   
            (getkword "\nPress any key to activate the next viewport")
         )
      )
   )

   (command "_PSPACE")
   (princ)
) ;defun

;This version gets an error message:
;  error: AutoCAD variable setting rejected: "CVPORT"
(defun c:vpbad
   ( /
   i
   ssVPs
   entnameCurVP
   entdataCurVP
   nVpId
   )
   (vl-load-com)
   (command "_MSPACE")

   (setq i -1)
   (if (setq ssVPs (ssget "_X" '((0 . "VIEWPORT"))))
      (while (setq entnameCurVP (ssname ssVPs (setq i (1+ i))))
         (setq entdataCurVP (entget entnameCurVP))
         (setq nVpId (cdr (assoc 69 entdataCurVP)))
   
         (if (> nVpId 1)
            (progn
               (prompt (strcat "\nActivate VP with ID: '" (itoa nVpId) "'"))
               (setvar "CVPORT" nVpId)
   
               (getkword "\nPress any key to activate the next viewport")
            )
         )
      )
   )

   (command "_PSPACE")
   (princ)
) ;defun

 

I am curious to know.  Thanks in advance for any info.

 

Jay Chan

7 REPLIES 7
Message 2 of 8
hmsilva
in reply to: JC_BL

Hi Jay,

change

(setq ssVPs (ssget "_X" '((0 . "VIEWPORT"))))

to

(setq ssVPs (ssget "_X" (list '(0 . "VIEWPORT") (cons 410 (getvar 'CTAB)))))

to select only the current layout vports...

 

Henrique

EESignature

Message 3 of 8
JC_BL
in reply to: hmsilva

Yes and No.

 

Thanks for showing me the way to filter out viewports that are not in the current layout tab.  This makes sense that I should not try to activate a viewport that is not in the current layout tab.  Your technique indeed works in filtering out viewports that are not in the current layout tab.  Actually this filtering technique is something that I meant to use, but I didn't know how and I was about to ask.  Thanks for letting me know.

 

Unfortunately, the additional filtering technique doesn't fix this problem.  It shows the same error when I run it on a mechanical that has only one paperbase layout tab.  The error message tells me that the viewport ID is wrong.  Seem like (vports) filters out those trouble-making viewports; but (ssget) still includes the trouble-making viewports.  After some trials and errors by removing one viewport at a time, I find one troube-making viewport.  Unfortunately when I examine it, I don't see anything wrong with it.

 

After additional trials and errors, I find that the problem seems to be triggered by a block reference in the lower right corner of the paperbase layout tab that has the customer name, address, our people names.  If I have changed the customer name and people names from the block reference, I find that the "used-to-be" trouble-making view-port doesn't cause trouble any more.  There are still other trouble-making viewports that are causing trouble.  But at least that one viewport is now OK.

 

At this point, I have to stop investigating this error.  The logical next step to investigate this problem is to upload the drawing for all to examine it. But I cannot upload the drawing because it has our customer info in it.  If I change the customer info, the error doesn't occur.  Therefore, I will have to stop investigating it.  Luckily the workaround of using (vports) is OK.

 

Thanks for your help in adding additional filter to only show viewports that are in the current layout tab.

 

Jay Chan

Message 4 of 8
hmsilva
in reply to: JC_BL

You're welcome, Jay Chan!

 

Without your dwg, I can´t reproduce that behavior...

 

Henrique

EESignature

Message 5 of 8
JC_BL
in reply to: hmsilva

I finally manage to remove all the customer info from the drawing and still can trigger the error using that drawing.  Attached please find the drawing.

 

The steps to trigger the error are:

  • Open the drawing.
  • Switch to the only one paperspace layout tab.
  • Don't do anything else, and immediately load the "vpbad" script as shown later in this message.
  • run "vpbad" and keep hitting a key until the script gets an error when it tries to activate viewport-10.

I find that view-port-10 is just a small square with a round red circle and a number '2' in it.  That is in the right edge of a viewport, and the viewport is in the bottom row with dark green texts and lines.  I don't see anything wrong with it.  Seem like the problem may not have to do with the viewport; but the problem may have to do with other things in the paperspace layout tab.

 

Please also note that the error can go away if I change some of the text in the title block in the right hand side.  Sometime, the error may go away if I browse around and zoom in and out in the paperspace layout tab.

 

(defun c:vpbad
   ( /
   i
   ssVPs
   entnameCurVP
   entdataCurVP
   nVpId
   )
   (vl-load-com)
   (command "_MSPACE")

   (setq i -1)
   (if (setq ssVPs (ssget "_X" (list '(0 . "VIEWPORT") (cons 410 (getvar 'CTAB)))))
      (while (setq entnameCurVP (ssname ssVPs (setq i (1+ i))))
         (setq entdataCurVP (entget entnameCurVP))
         (setq nVpId (cdr (assoc 69 entdataCurVP)))
   
         (if (> nVpId 1)
            (progn
               (prompt (strcat "\nActivate VP with ID: '" (itoa nVpId) "'"))
               (setvar "CVPORT" nVpId)
   
               (getkword "\nPress any key to activate the next viewport")
            )
         )
      )
   )

   (command "_PSPACE")
   (princ)
) ;defun

 

Thanks in advance for any help.

 

Jay Chan

Message 6 of 8
hmsilva
in reply to: JC_BL

Hi Jay Chan,


The viewports that are giving error have the dxf group code 68 (Viewport status field) set to -1.

((-1 . <Entity name: 7ef16400>)
  (0 . "VIEWPORT")
...
  (68 . -1)
  (69 . 10)
...
)

From the Help files

-1 = On, but is fully off screen, or is one of the viewports that is not active because the $MAXACTVP count is currently being exceeded.

 

As one can't entmod viewports, I don't know how to solve this.
Hopefully, someone else will step in with a different approach for this issue...

 

EDIT: forcing a zoom extents, before the  MSPACE command, it seems that viewports are updated, and the code runs without issues...

 

Henrique

 

EESignature

Message 7 of 8
JC_BL
in reply to: hmsilva

Smiley Very Happy

 

Yes!  Zoom-extents before changing to model space works.  This fixes the problem of "failure to activate some viewports".

 

The following is the corrected version for the reference of other people:

 

(defun c:vpgood
   ( /
   i
   ssVPs
   entnameCurVP
   entdataCurVP
   nVpId
   )
   (vl-load-com)

   ;We should already be in a paper-space layout tab.
   (command "ZOOM" "E")    ;Zoom extents to avoid the problem.

   (command "_MSPACE")

   (setq i -1)
   (if (setq ssVPs
          (ssget "_X" (list '(0 . "VIEWPORT")
                            (cons 410 (getvar 'CTAB))
                      )
          )
       )
      (while (setq entnameCurVP (ssname ssVPs (setq i (1+ i))))
         (setq entdataCurVP (entget entnameCurVP))
         (setq nVpId (cdr (assoc 69 entdataCurVP)))
   
         (if (> nVpId 1)
            (progn
               (prompt (strcat "\nActivate VP with ID: '" (itoa nVpId) "'"))
               (setvar "CVPORT" nVpId)
   
               (getkword "\nPress any key to activate the next viewport")
            )
         )
      )
   )

   (command "_PSPACE")
   (princ)
) ;defun

 

Thanks a lot of your help.  I greatly appreciate that.

 

Jay Chan

Message 8 of 8
hmsilva
in reply to: JC_BL

You're welcome, Jay Chan
Glad I could help

Henrique

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost