TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: V-Man on October 14, 2008, 10:18:35 AM

Title: Layer 0 check
Post by: V-Man on October 14, 2008, 10:18:35 AM
A little assistance needed here. I am trying to get this to check for any items on Layer 0 and omit the Viewport and report back to the use if any found besides the Viewport back to the user via Alert. Can someone shed some light on this or is there a better way?

Code: [Select]
(defun chk_layer_0 (/ ss)
  (princ "\nChecking for objects on layer 0")
  (if (setq ss (ssget "x" '((8 . "0"))))
    (if (= 1 (sslength ss))
      (if (and (= "VIEWPORT" (cdr (assoc 0 (entget (ssname ss 0)))))
      (= 1 (cdr (assoc 69 (entget (ssname ss 0)))))
 )
(progn
 (princ "\nNo objects found on layer 0.")
) ;end progn
(progn
 (princ (strcat "\nLocated "
(itoa (sslength ss))
" objects on layer 0."
)
 )
)
      )
    )
  )
  (progn
    (princ "\nNo objects found on layer 0.")
  )
)

Thanks,

Don
Title: Re: Layer 0 check
Post by: ronjonp on October 14, 2008, 11:13:49 AM
How about something like this:

Code: [Select]
(defun chk_layer_0 (/ ss)
  (if (setq ss (ssget "x"
      '((8 . "0") (-4 . "<NOT") (0 . "VIEWPORT") (-4 . "NOT>"))
       )
      )
    (progn
      (princ (strcat "\nLocated "
     (itoa (sslength ss))
     " objects on layer 0."
     )
      )
      (sssetfirst nil ss)
    )
    (princ "\nNo objects found on layer 0.")
  )
  (princ)
)
(chk_layer_0)
Title: Re: Layer 0 check
Post by: CAB on October 14, 2008, 11:30:12 AM
Nice Ron but it does pick up VPs from clipped or converted viewports because there is an object associated with that VP.
Title: Re: Layer 0 check
Post by: ronjonp on October 14, 2008, 11:59:51 AM
Nice Ron but it does pick up VPs from clipped or converted viewports because there is an object associated with that VP.


Picky picky picky  :-P

*edit...from my tests it does not select any viewports? It will select the object associated with the VP if it is on layer 0.
Title: Re: Layer 0 check
Post by: CAB on October 14, 2008, 12:12:51 PM
Picky picky picky  :-P
:-D

That's right but that object is part of the VP definition in my mind.
A CIRCLE VP has a circle entity associated with it and I suspect should be ignored.
Just my openion.  8-)
Title: Re: Layer 0 check
Post by: Joe Burke on October 15, 2008, 08:41:20 AM
Objects within blocks on layer 0 are intentionally ignored?
Title: Re: Layer 0 check
Post by: ronjonp on October 15, 2008, 10:15:59 AM
Objects within blocks on layer 0 are intentionally ignored?

I would think so? All of our blocks are intentionally created with objects on layer 0 so they will inherit the layer color they are placed on.
Title: Re: Layer 0 check
Post by: CAB on October 15, 2008, 10:42:56 AM
Modified version to ignore VP related objects.
Code: [Select]
(defun chk_layer_0 (/ ss ename elist vptest removelist)
  (if (setq ss (ssget "x" '((8 . "0")(0 . "~VIEWPORT"))))
    (progn
      (setq i -1)
      (while (setq ename (ssname ss (setq i (1+ i))))
        (setq elist (entget ename))
        (if (and
              (setq vptest (member '(102 . "{ACAD_REACTORS") elist))
              (setq vptest (member '(102 . "}") (reverse vptest)))
              (assoc 330 vptest)
            )
          (setq removelist (cons ename removelist))
        )
      )
      (mapcar '(lambda (x) (ssdel x ss)) removelist)
      (if (and ss (> (sslength ss) 0))
        (progn
          (princ (strcat "\nLocated "
                         (itoa (sslength ss))
                         " objects on layer 0."
                 )
          )
          (sssetfirst nil ss)
        )
      )
    )
    (princ "\nNo objects found on layer 0.")
  )
  (princ)
)
Title: Re: Layer 0 check
Post by: ronjonp on October 15, 2008, 11:15:50 AM
Nice CAB...forgot about the ~ in the filter 8-)

Question...would this work as well?


Code: [Select]
      '((8 . "0")
(-4 . "<NOT")
(102 . "{ACAD_REACTORS")
(-4 . "NOT>")
(0 . "~VIEWPORT")
       )

Title: Re: Layer 0 check
Post by: CAB on October 15, 2008, 11:20:50 AM
Some other object may have an ACAD reactor. Not sure which ones but wouldn't want to bet on it.