Author Topic: Deleting of LMAN States  (Read 4983 times)

0 Members and 1 Guest are viewing this topic.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Deleting of LMAN States
« on: August 02, 2006, 03:36:32 PM »
Found this lisp By Tom Stoeckel (a AutoCAD Express Tools Developer) on the Autodesk Discussion Boards Via an AUGI Thread (thanks Mike) and thought it might be of use to someone here.  Durring my search of  the swamp, Dommy2Hotty was looking for something like this awhile back.

I don’t understand how it works.  There is a sub function that create an ignore list but it is not asking for input.  Right now it runs and deletes every layer state which is great.  IT would be even more powerful if you could tell it to ignore this state and that state.  Maybe somebody can explain how the sub-function works.

Lman - deleting unneeded layer states

Express Tools Layer Manager - delete all layer states at once

Code: [Select]
;;; This was posted on an Augi Thread "Lman - Deleting Unneeded Layer States" Oct/05/99
;;; Posted by Tom Stoeckel, a AutoCAD Express Tools Developer
;;;tom.stoeckel@autodesk.com http://www.autodesk.com/expresstools;


Content-Type: text; name="killstates.lsp"
Content-Transfer-Encoding: 8bit
Content-Disposition: inline; filename="killstates.lsp"

(defun c:killstates (/ lyr ent)
  (while (setq lyr (tblnext "layer" (not lyr)))
    (setq ent (entget (tblobjname "layer" (cdr (assoc 2 lyr))) '("RAK")))
    (if (and ent (assoc -3 ent))
      (progn
        (setq ent (subst '(-3 ("RAK")) (assoc -3 ent) ent))
        (entmod ent)
      ) ;progn
    ) ;if
  );while
  (princ)
) ;defun c:killstates


(defun kill_all_states_except ( ignore / lyr ent xd lst inc a stateList state ignore)
  ;; load lman if the function we need isn't around
  (if (not bns_d_layerstate)
    (load "lman.lsp")
  )
  (if bns_d_layerstate
    (progn
      ;; force the members of the ignore list to upper case
      (setq inc -1) ;setq
      (while (< (setq inc (1+ inc)) (length ignore))
        (setq ignore (subst (strcase (nth inc ignore)) (nth inc ignore) ignore))
      );while
     
      (while (setq lyr (tblnext "layer" (not lyr)))
        (setq ent (entget (tblobjname "layer" (cdr (assoc 2 lyr))) '("RAK"))
              xd (cdr (assoc -3 ent))
              lst (cdr (assoc "RAK" xd))
        )
        ;; build list of states for this layer
        (setq inc 0);setq
        (repeat (length lst)
         (setq a (nth inc lst));setq
         (if (or (not (equal (car a) 1000))
                 (not (equal "{" (substr (cdr a) 1 1)))
             );or
             (setq a nil)
             (progn
              (setq a (strcase (substr (cdr a) 2)))
              (if (not (member a stateList))
                (setq stateList (append stateList (list a)))
              );if
             );progn else
         );if
         (setq inc (+ inc 1));setq
        );repeat
       
        (setq inc -1) ;setq
        (while (< (setq inc (1+ inc)) (length stateList))
          (setq state (nth inc stateList)) ;setq
          (if (not (member state ignore))
            (bns_d_layerstate (cdr (assoc 2 ent)) state)
          ) ;if
        );while
      );while
    ) ;progn
  )
  (princ)
)
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Deleting of LMAN States
« Reply #1 on: August 02, 2006, 06:31:10 PM »
There are two routines here.
"killstates" removes all layer states while "kill_all_states_except" expects a list of layer states to keep.

So use it like this
Code: [Select]
(kill_all_states_except '("lyrstate1" "lyrstate2" "lyrstate3"))
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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Deleting of LMAN States
« Reply #2 on: August 02, 2006, 08:49:21 PM »
Bob,
Thank you for your concern.
I too take exception to your tone and criticism.

We do care and each is a case by case evaluation. Sorry my decision wasn't to you liking.
As Mark stated it is a "General Rule"
general: Being usually the case; true or applicable in most instances but not all:
If someone in the Mod Squad wants to remove it, it's fine with me.

My quick evaluation went something like this:
There was no direct link to display the code so that was the posters decision to display the code.
He did try to credit the apparent author, provided links to the source directly & indirectly.
The code did not appear to be something special and there was no claim posted within the code.
So I let it stay.
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.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Deleting of LMAN States
« Reply #3 on: August 02, 2006, 08:59:33 PM »
First of All: I apologized for crossing the line.  Though I am not sure where that line exactly is at the moment.  I thought I was giving credit where credit is due by linking both to AUGI and Autodesk sites.  And I place credit in my Comments in the thread and I was the one who place the first 3 Comments in the code,

Second of all; As I do with every code that I obtain that is not mine even if modify or barrow a piece of code; I give credit.  I also give credit when you guys have help in the past.  Some where in my code, I document it. 

Third of All; Who the hell is Alan?

If I am to understand this correctly, I am not to post code from another site.  I will follow that rule.  Though I do not agree with one aspect of it due to the simple fact that if the person that is following the link may not have registered with the site and the site could be a real pain the A$ register with.  For example; Maverick did some awesome (IMHO) renderings of a house, I tried to send the link to thread to two guys in my office that do renderings, they could not view the tread because they were not registered with the swamp.  They would have to register to view those renderings and they would never return becuase they would never have another reason to come back.  I personally don’t mind registering with a site if it will yield results in the future.  Just a down side to following a link, IMHO. 

Sorry if I kick the hornets nest.
 :-o :?

<Edited becuase I suck at typing>
« Last Edit: August 03, 2006, 08:21:42 AM by Krushert »
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

Serge J. Gianolla

  • Guest
Re: Deleting of LMAN States
« Reply #4 on: August 02, 2006, 09:09:12 PM »
Third of All; Who the hell is Alan?
Check the last line in CAB's signature  8-)

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Deleting of LMAN States
« Reply #5 on: August 02, 2006, 09:17:36 PM »
Third of All; Who the hell is Alan?
Check the last line in CAB's signature  8-)

<Getting out the magnifying glass>
Ahh should have known.
<Putting away the magnifying glass>
I knew his middle name is Alan.  What is with you middle name Alan people anyway.  I have an Alan in my office with a first name Roy.  Jeese   :-) :-)
Sorry Alan, CAB, Charles or whomever:-D :-D.
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Deleting of LMAN States
« Reply #6 on: August 02, 2006, 09:39:22 PM »
Third of All; Who the hell is Alan?

That would be me.

And I don't think you crossed the line.
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.

Bob Wahr

  • Guest
Re: Deleting of LMAN States
« Reply #7 on: August 02, 2006, 11:21:11 PM »
Instead of continuing this, I am deleting the offensive post.


Decided to get rid of any potentially offensive posts but got tired of clicking after 60 or so.  I'll let someone else do it instead.
« Last Edit: August 02, 2006, 11:37:14 PM by Bob Wahr »

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: Deleting of LMAN States
« Reply #8 on: August 03, 2006, 08:06:32 AM »
apologies if this post doesn't make a lot of sense, most of the posts have been deleted, by the authors. This response is meant for those who were involved in the exchange that took place last night.

First of all, sorry you left Bob. You have been a big part of theswamp, your CAD/VBA knowledge will be missed. It saddens me when a member of theswamp leaves, for any reason.

The ( text ) you quoted Bob was from the CAD General forum, it was directed at those folks that try to help those "does anyone have a program that will do X" posts by pasting the code directly into their response. Different forum different rules. If you look at the sticky thread in this forum I only ask "Please do not post copyrighted material unless you are the author or have the authors permission to do so. A link to the code works best, this gives credit where credit is due. Not to mention keeps me away from law suites.", IMO the author of this thread was not out-of-line. I know that sounds like a cop-out, it's not my intention though.

We ( the folks that work in the back ground ) try very hard to keep this place on the up-and-up both legally and morally, it's a tough job. Some of our rules tend to be more gray then black and white, that was intentional. It's hard to for see any and all problems that might arise here in theswamp so we try to leave ourselves a little leeway.

thanks for your time.
TheSwamp.org  (serving the CAD community since 2003)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Deleting of LMAN States
« Reply #9 on: August 03, 2006, 08:18:38 AM »
Sad state of affairs.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Deleting of LMAN States
« Reply #10 on: August 03, 2006, 08:20:35 AM »
Third of All; Who the hell is Alan?
Check the last line in CAB's signature  8-)

<Getting out the magnifying glass>
Ahh should have known.
<Putting away the magnifying glass>
I knew his middle name is Alan.  What is with you middle name Alan people anyway.  I have an Alan in my office with a first name Roy.  Jeese   :-) :-)
Sorry Alan, CAB, Charles or whomever:-D :-D.

Not a problem.
Explanation for middle name:
My Father is Charles Aubrette, my Uncle Charles Edward , my cousin Charles Edwin.
So I've been confused my whole life. Can't choose you parents you know. :-)
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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Deleting of LMAN States
« Reply #11 on: August 04, 2006, 12:04:06 PM »
Here is my version of the express tools layer state delete routine.
Limited testing, please report any problems you may have.

One concern I have is the -3 dxf code. Does express tools have any other -3 codes attached to the layers?
If so are the (-3 ("RAK" ...)) ? That would cause a problem in this routine but I kinda doubt they would do that.

Code: [Select]
;;;===============[ et_layerstate_del_except.lsp ]===============
;;; Author: Copyright© 2006 Charles Alan Butler
;;; Version:  1.0 Aug. 3, 2006
;;; Purpose: To delete express tools layer states.
;;; Sub_Routines: -None
;;; USAGE
;;;  Delete all but the layer states in the list
;;;  (et_layerstate_del_except '("1st floor" "2nd floor"))
;;;
;;;  Delete all layer states
;;;  (et_layerstate_del_except '(""))
;;;
;;; Return: -none
;;;==============================================================

(defun et_layerstate_del_except (keeplst / keepflg lyr ent xd lst nlst)

  (setq keeplst (mapcar 'strcase keeplst)) ; force upper case
  ;;  prepare a start list & an end list
  (setq startlst (mapcar '(lambda (x) (cons 1000 (strcat "{" x))) keeplst))
  (setq endlst (mapcar '(lambda (x) (cons 1000 (strcat x "}"))) keeplst))

  ;;  step through all the layers & remove the layer state data
  (while (setq lyr (tblnext "layer" (not lyr)))
    (setq ent (entget (tblobjname "layer" (cdr (assoc 2 lyr))) '("RAK")))
    (if (and ent
             (setq xd  (cdr (assoc -3 ent))
                   lst (cdr (assoc "RAK" xd))
             )
        )
      (progn ; got layer states, so delete them
        (setq keepflg nil
              nlst    nil
        )
        ;;  reconstruct the layer state list
        (foreach itm lst
          (cond
            (keepflg
             (setq nlst (cons itm nlst))
             (if (vl-position itm endlst)
               (setq keepflg nil)
             )
            )

            ((vl-position itm startlst)
             (setq nlst    (cons itm nlst)
                   keepflg t
             )
            )
          ) ; cond
        )
        (setq nlst (list -3 (cons "RAK" (reverse nlst))))
        (setq ent (subst nlst (assoc -3 ent) ent))
        (entmod ent)
      )
    )
  )
  (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.

Sdoman

  • Guest
Re: Deleting of LMAN States
« Reply #12 on: August 04, 2006, 12:55:20 PM »
..
One concern I have is the -3 dxf code. Does express tools have any other -3 codes attached to the layers?
If so are the (-3 ("RAK" ...)) ?
..

I doubt it, because I remember reading that "RAK" is the authors initials:  Randy A. Kintzley


{found RAK's name, Randy is the author of the express tool LMAN}
« Last Edit: August 04, 2006, 09:06:54 PM by 'steved »

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Deleting of LMAN States
« Reply #13 on: August 04, 2006, 01:36:57 PM »
Here is my version of the express tools layer state delete routine.
Limited testing, please report any problems you may have.

I have tested it a few times by changing the first line.  I had to comment out the "Resetting of Variables" becuase I was getting "too few agruments" at the command line
Code: [Select]
(defun c:et_layerstate_del_except ();(keeplst / keepflg lyr ent xd lst nlst)
Okay I am going to show my ignorance.

Where do I place the "...except" List within your code (or for that matter Stockle's code).
 :|
« Last Edit: August 04, 2006, 01:39:14 PM by Krushert »
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Deleting of LMAN States
« Reply #14 on: August 04, 2006, 02:48:31 PM »
Here is my test routine.
Code: [Select]
(defun c:test ()
  (et_layerstate_del_except '("1st floor" "2nd floor")) ; delete all but theses two
  (et_layerstate_del_except '("")) ; delete all
  (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.