Jump to content

Recommended Posts

Posted

I'm trying to select all the true view port in each layout but I'm running into issues. There are more view ports in the drawing than what's visible to the user(not sure why this is as I only create one single view port in each layout).  So I need to filter for the actual view ports.

(defun c:CollectLayoutViewports (/ ss i ent ed layout number status pt items counts item)
  (setq items nil
        counts nil
        ss (ssget "_X" '((0 . "VIEWPORT") (67 . 1)))
  )
  (princ (strcat "\nSelection count: " (if ss (itoa (sslength ss)) "0")))
  (if ss
    (progn
      (setq i 0)
      (while (< i (sslength ss))
        (setq ent (ssname ss i)
              ed (entget ent)
              layout (cdr (assoc 410 ed))
              number (cdr (assoc 69 ed))
              status (cdr (assoc 68 ed))
              pt (cdr (assoc 10 ed))
        )
        (if (and layout
         (/= (strcase layout) "MODEL")
         (> number 1)
         (> status 0))      
          (progn
            (setq items (cons ent items))
          )
        )
        (setq i (+ i 1))
      )
    )
  )

  items

)

is there a DXF code I can filter by or any other suggestion...

 

ViewPortTest.dwg

Posted

Try this selection filter which should remove the paperspace object itself which is also considered as a vport

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

Posted
32 minutes ago, Paul Li said:

Try this selection filter which should remove the paperspace object itself which is also considered as a vport

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

That didn't work but I notice some have code 340,  other don't (Clipping boundary) so filtering post ssget worked... Just not exactly sure this true in every case.

(defun c:CollectLayoutViewports (/ ss i ent ed layout number status pt items counts item)
  (setq items nil
        ss (ssget "_X" '((0 . "VIEWPORT") (67 . 1)))
  )
  (princ (strcat "\nSelection count: " (if ss (itoa (sslength ss)) "0")))
  (if ss
    (progn
      (setq i 0)
      (while (< i (sslength ss))
        (setq ent (ssname ss i)
              ed (entget ent)
              layout (cdr (assoc 410 ed))
        )
        (if (and layout (/= (strcase layout) "MODEL") (assoc 340 ed))        
            (setq items (cons ent items))
        )
        (setq i (+ i 1))
      )
    )
  )
  (princ (strcat "\nResult count: " (if items (itoa (length items)) "0")))
)

 

Posted

if you're only looking for true rectangular vports then testing for the dxf 340 is the best way to filter that out.

Posted

so you now know how to filter out the selection of a "true view port"?

Posted (edited)

if your trying to select all Paperspace viewports at once. this filters all viewports that are not in model or the first (paperspace) 

(defun C:CLV () (C:CollectLayoutViewports))
(defun C:CollectLayoutViewports (/ ss)
  (if (not (setq ss (ssget "_X" '((0 . "VIEWPORT") (410 . "~Model") (-4 . ">") (69 . 1) (-4 . ">")  (68 . 0)))))
    (princ "\nNo Active Paperspace Viewports Found")
    (princ (strcat "\n" (itoa (sslength ss)) " Viewports Found"))
  )
  ss 
)

 

Edited by mhupp
Updated code
Posted

@mhupp unfortunately this ssget filter in autocad returns nothing:

(ssget "_X" '((0 . "VIEWPORT") (-4 . "!=") (410 . "Model") (-4 . "!=")(-4 . ">") ))

 

  • Agree 1
Posted

I also believe some of the flags change as you move to different layouts/  change the zoom scale or move view port off screen..(I am getting inconstant result between drawings an auto-cad sessions.) 

I have a lisp to report the result to a text file but I been having issues posting posting.

 

Posted

Code 68 and 69 is not consistent and when you first open a drawing most of these codes show 0 for a value... When you switch to the each of the layouts the value updates. So for now looping through the layouts and zooming extents appears to solve the issue. Then I'm just filtering for  69 > 1.. still a bit confused. Also these values in some case are -1 but still valid viewports and I run a second time and changes to positive value.. Still not 100% sure of what's going on.

Posted

@DavidP Yes, you do need to activate each layout in order for the vports to come alive. So looping through them is a good way to deal with this.

Posted (edited)

Just a comment Bricscad sometimes does not support the "(( make a list method. so this does work and I added get for current layout, in case have multi viewports in a layout. You could loop through the layouts rather than getting all. If make a list of properties then have the layout name.

 

Having problems post in <> get error message finally got it.

A test

(sslength (setq ss (ssget "_X" (list (cons 0  "VIEWPORT") (cons 67  1) (cons -4  "/=") (cons 69 1)(cons 410 (getvar 'ctab))))))

 

Edited by BIGAL
Posted

Yeah @Paul Li had to look at my notes when I got home.

My updated code above should give David what they are looking for in one ssget.

kept the 410 just to be safe but used ~ to ignore instead of (-4 

 

ViewPortTest.png

Posted

@mhupp I think @DavidP wants to filter out those viewports that are not "true view ports" which means when objects are used as view ports. As a test I run his c:COLLECTLAYOUTVIEWPORTS lisp code on the attach drawing the return value is 3:

image.png.0dc3ed4956207d2e75885bf01e04c85d.png

But when I run your lisp code on the same drawing the return value is 6:

image.png.0d593ca8cac7ddf1352fbcc212ff43ce.png

TrueViewports.dwg

Posted
7 hours ago, DavidP said:

Code 68 and 69 is not consistent and when you first open a drawing most of these codes show 0 for a value... When you switch to the each of the layouts the value updates. So for now looping through the layouts and zooming extents appears to solve the issue. Then I'm just filtering for  69 > 1.. still a bit confused. Also these values in some case are -1 but still valid viewports and I run a second time and changes to positive value.. Still not 100% sure of what's going on.

 

Think the 0 thing is for rendering but not 100% on that.

for (68 . -1) means the viewport is off screen also for rending.

 

This zoom ext all tabs and returns to the one you were on.

;;----------------------------------------------------------------------------;;
;; Zoom Extents All Tabs
(defun C:ZA (/ lyt)
  (setq lyt (getvar 'ctab))
  (foreach lay (layoutlist)
    (setvar 'ctab lay)
    (setvar 'cvport 1)
    (vl-cmdf "_.Zoom" "E")
  )
  (setvar 'ctab lyt)
)

 

@Paul Li I'm just posting the ssget not full code.

 

Might also want to check this out.

https://www.lee-mac.com/vpoutline.html

 

Posted

My other option would be to ensure the view port sits in specific layer. The danger with that is I depend on the user to create the VP correctly.

 

@mhupp thanks for the zoom ext all tabs.

Good looks like  (vl-cmdf "_.Zoom" "E") behaves similar to "command-s" as we need to ensure AutoCAD updates every system variable before moving to the selection set.

FYI: lee-mac's vpoutline routine has the same problem as it draws the PS extra view ports near 0,0.

Adding calling C:ZA  in Lees routine fix the issue it that.

 

The idea is to use them to generate selection polygons in MS. Basically Lee's routine is accomplishing that minus the filtered for the actual view ports.
 

 

Posted (edited)

I made ZA because a coworker would leave things zoomed in.

 

Might just need to hit it with

 

(vl-load-com)
(vla-Regen (vla-get-ActiveDocument (vlax-get-acad-object)) acAllViewports)

 

to fix the 0,0 problem.

Edited by mhupp
Posted

Thanks ZA appears to work fine.

LOL I hear you... We often hear complains from clients  that drawing is broken and we usually we can narrow it down to a few things...useer define ucs is set,  UCSfollow set to 1 or garbage has been left both in PS or MS an zoom extent result to just dots on the scree.  

 

So I too run the zoom E in PS as well just to see if there any garbage outside the TB.

 

FYI does work either:  (vla-Regen (vla-get-ActiveDocument (vlax-get-acad-object)) acAllViewports) doesn't update them.

 

I added some prompt suppression...

(defun DP:llnze (/ lyt)
  (setq oldEcho (getvar "CMDECHO")
        oldNOMUTT (getvar "NOMUTT")
        lyt (getvar "CTAB")
  )
  (setvar "CMDECHO" 0)
  (setvar "NOMUTT" 1)
  (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)
  (princ)

)

 

now Using this works fine.:

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

 

So for this is working great

  • Like 1
Posted (edited)

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


 

Edited by ronjonp

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