Variable for viewport will not recognize as a viewport

Variable for viewport will not recognize as a viewport

Gorra
Advocate Advocate
936 Views
12 Replies
Message 1 of 13

Variable for viewport will not recognize as a viewport

Gorra
Advocate
Advocate

Hello,

I am having trouble making an loop for user-selecting a viewport as a variable, and test to make sure it is a viewport before proceeding to the next one. I've had the problem before but the usual tweaks aren't working. Whether I use ssget and then ssname, or if I use entsel and then car, I'm still getting the target as an ename and not a viewport. If I convert to a vla it becomes a vla object and some methods can be applied, but its object type is a vla-object and not a viewport. I am using the (0 . "VIEWPORT") filter on ssget, but this doesn't give an error on selection to re-select, it just chokes on the resulting nil value farther down the lisp.

 

(alert "\nSelect viewports one at a time from top to bottom")
(setq VwPrt1 (ssget "_+.:E:S" '((0 . "VIEWPORT"))))
(setq VP1v (vlax-ename->vla-object (ssname VwPrt1 0)))
(while (/= (type VP1v) "VIEWPORT")
  (progn
    (princ "Object must be a viewport")
(setq VwPrt1 (ssget "_+.:E:S" '((0 . "VIEWPORT"))))
  )
 
Thanks for any help
Gorra
0 Likes
Accepted solutions (1)
937 Views
12 Replies
Replies (12)
Message 2 of 13

paullimapa
Mentor
Mentor

perhaps the problem occurs when an object is selected as the vport?

share a sample dwg with the vports you're trying to select.

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 13

paullimapa
Mentor
Mentor

@Gorra updated

FYI: this line of code is incorrect:

(/= (type VP1v) "VIEWPORT")

Should be:

(/= (vla-get-objectname VP1v) "AcDbViewport")

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 4 of 13

Gorra
Advocate
Advocate

@paullimapa Thanks for the reply. That's probably the problem but testing it isn't going smoothly. I will try to extract what I'm allowed to post online but that will take a bit.

 

Gorra

0 Likes
Message 5 of 13

Sea-Haven
Mentor
Mentor

Checking you have chosen a viewport, tone is an abrupt exit which is not really a clean way, you can use a (progn instead and wrap all the following code in it, oh yeah a while.

 

(if (setq VwPrt1 (ssget "_+.:E:S" '((0 . "VIEWPORT"))))
(progn (alert "You did not pick a viewport /n/nThe program will now Exit please run again")
(EXIT)
))

(if (setq VwPrt1 (ssget "_+.:E:S" '((0 . "VIEWPORT"))))
(progn
...... all your code
) ; progn
(alert "You did not pick a viewport /n/nThe program will now Exit please run again")
) ; if

setq VwPrt1 (ssget "_+.:E:S" '((0 . "VIEWPORT"))))
(while (/= VwPrt1 nil)
(setq ok "Yes")
...... all your code
(setq vwprt1 nil)
) ; while
(if (= ok "Yes")
  (princ)
  (alert "You did not pick a viewport /n/nThe program will now Exit please run again")
)

 

0 Likes
Message 6 of 13

komondormrex
Mentor
Mentor

hey,

following your algorithm logic

(alert "\nSelect viewports one at a time from top to bottom")
(while (not (setq VwPrt1 (ssget "_+.:E:S" '((0 . "VIEWPORT")))))
    (princ "\rObject must be a viewport")
)
(setq VP1v (vlax-ename->vla-object (ssname VwPrt1 0)))
0 Likes
Message 7 of 13

Gorra
Advocate
Advocate

@komondormrex @Sea-Haven @paullimapa 

 

Tried all three solutions with no change: the selection accepts any object and moves along to the next selection (without setting it to nil). Do I have an error in my ssget strings? 

I can't think of any other reason it should be ignoring its restrictions. The sub function is this:

 

(defun GetLayout (CLName / VP1v VP2v VP3v)
  (if (< LytCnt 2) ;; If only 1 layout
    (progn
      (command-s "-layout" "D" "PL002") ;; delete sheet PL002
      (command-s "-layout" "S" "PL001")
      (GetViewports)
    )
    (progn
      (setq VwPrt1 nil) ;; Clearing any residual values
      (setq VwPrt2 nil)
      (setq VwPrt3 nil)
      (setq VP1v nil)
      (setq VP2v nil)
      (setq VP3v nil)
      (if (eq CLName "PL001")    ;; if more than one sheet and this is PL001 being processed
        (progn
          (alert "\nSelect viewports one at a time from top to bottom")
          (while (not (setq VwPrt1 (ssget "_+.:E:S" '((0 . "VIEWPORT")))))
            (princ "\nObject must be a viewport")
          )
          (setq VP1v (vlax-ename->vla-object (ssname VwPrt1 0)))
          (vla-put-center VP1v (vlax-3D-point '(8.5 8.866396 0.0)))
          (alert "top vp placed")
          (while (not (setq VwPrt2 (ssget "_+.:E:S" '((0 . "VIEWPORT")))))
            (princ "\nSecond target must be a viewport")
          )
          (setq VP2v (vlax-ename->vla-object (ssname VwPrt2 0)))
          (vla-put-center VP2v (vlax-3D-point '(8.5 6.316396 0.0)))
          (alert "\nsecond vport placed")
          (while (not (setq VwPrt3 (ssget "_+.:E:S" '((0 . "VIEWPORT")))))
            (princ "\nBottom target must be a viewport")
          )
          (setq VP3v (vlax-ename->vla-object (ssname VwPrt3 0)))
          (vla-put-center VP3v (vlax-3D-point '(8.5 3.766396 0.0)))
          (alert "bottom vport placed")
          (setq VPCnt 3)
        ) ;;end PL001 true progn
        (progn
          (setq CrrntTb (+ TrLyt CrrntLyt))
          (CreateLayout CLName)
          (GetViewports)
        ) ;; end PL001 false progn
      )  ;; end if PL001
  )  ;; end single layout false 
 )  ;; end if single layout
(alert "viewports positioned")
) end GetLayout

 

VwPrt1/2/3 are global variables.

 

Thanks,

Gorra

0 Likes
Message 8 of 13

paullimapa
Mentor
Mentor

could you share an example dwg?


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 9 of 13

Gorra
Advocate
Advocate

Attached is a sample dwg and the rest of the code. The rest of the code has other issues but the task in question is the first interaction it does with the user.

0 Likes
Message 10 of 13

paullimapa
Mentor
Mentor
Accepted solution

Here's the tst.lsp code I'm using just on the first vport of your sample dwg:

(defun c:tst (/ vwprt1 vp1v)
 (setq vwprt1 nil vp1v nil)
 (while (not (setq VwPrt1 (ssget "_+.:E:S" '((0 . "VIEWPORT")))))
    (princ "\nObject must be a viewport")
 )
 (if vwprt1
  (progn
   (setq VP1v (vlax-ename->vla-object (ssname VwPrt1 0)))
;   (vlax-dump-object VP1v)
    (vla-put-center VP1v (vlax-3D-point '(8.5 8.866396 0.0)))
    (alert "top vp placed")
  )
  (alert"not a valid object")
 )
 (princ)
)

I purposely moved the vports including the pline away before running tst.lsp

Here's a screenshot of the vports before:

_.PNG

After loading tst.lsp, I then enter at the command prompt tst and selected the top vport.

The AutoCAD message box would appear notifying "top vp placed" and after clicking ok here's the screenshot afterwards:

__.PNG

The vport moved as programmed.  Is this not what's happening for you?

Try my sample tst.lsp and see if at least this portion of the code works for you.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 11 of 13

Gorra
Advocate
Advocate

@paullimapa 

It does indeed work in the stripped-down version dwg I posted, but not in the working drawing I was using. Looks like there's some layout name mis-matches that are making it fail rather than the code. Thanks for all the effort!

 

Gorra

0 Likes
Message 12 of 13

paullimapa
Mentor
Mentor

you're welcome...cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 13 of 13

Sea-Haven
Mentor
Mentor

I may have an answer for you a completely different way of approaching this problem i have a couple of make viewport programs, in particular walk along a pline making rectangs that represent Viewports, part two of the code select all rectangs and new layouts are made with matching viewports. They include adding a twist as in your sample dwg you have not followed the shape where it bends what I have does that.

 

Look at the images and have a look at the movie. Rectangs can be added, rotated, moved or even deleted before making layouts. Pretty sure was asked before for a multi viewport answer. I don't think I finished but is possible to do,

 

Let me know if interested.

 

Multi radio 2 col 34.pnglayout 1.png

0 Likes