Author Topic: Layer 0 check  (Read 3547 times)

0 Members and 1 Guest are viewing this topic.

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Layer 0 check
« 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
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Layer 0 check
« Reply #1 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)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Layer 0 check
« Reply #2 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.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Layer 0 check
« Reply #3 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.
« Last Edit: October 14, 2008, 12:05:40 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Layer 0 check
« Reply #4 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-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Joe Burke

  • Guest
Re: Layer 0 check
« Reply #5 on: October 15, 2008, 08:41:20 AM »
Objects within blocks on layer 0 are intentionally ignored?

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Layer 0 check
« Reply #6 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.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Layer 0 check
« Reply #7 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)
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Layer 0 check
« Reply #8 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")
       )


Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Layer 0 check
« Reply #9 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.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.