Lisp to save a named layer draworder per viewport layout

Lisp to save a named layer draworder per viewport layout

Anonymous
Not applicable
760 Views
1 Reply
Message 1 of 2

Lisp to save a named layer draworder per viewport layout

Anonymous
Not applicable

Looking for a lisp routine that will allow me to be inside a viewport and arrange layer state including layer draworder (front & back) the way I want for that viewport, then allow me to save that layer state including layer draworder to a name.

 

Then be able to go to other viewport layouts and arrange the layers as I need them and save those to another name.

 

Then be able to switch back and forth to my various viewport layouts and restore one of my named layer states that I created.  (note: the restore needs to be able to adjust the layer draworder)

 

Why we need this:

In our drawing files we have several viewport layouts that represent our plan sheets, Site Plan, Utility Plan, Grading Plan, Erosion Control Plan, etc. etc.    We use a lot of layer screening for different objects on different sheets for plotting and in order for them to look decent we are always having to go into each layout and isolate objects and move them to the back or to the front then plot, then go to the next layout and again move objects to the front or the back and plot, etc. etc.   It would be nice if we could set the draworder up in each viewport layout and save them so that when we need to plot a particular sheet we could just go to that viewport layout and somehow restore a named layer draworder that we had previously saved.

 

Does anyone know if a lisp exists that does something like this, can it even be done?

0 Likes
761 Views
1 Reply
Reply (1)
Message 2 of 2

CodeDing
Advisor
Advisor

@Anonymous,

 

This is not completely what you're looking for since it does not allow the user to "save" at will, nor address layer states. But it's a start for draw orders..

Just update the <name> and <layers> inside the presetList.

(defun c:DROP ( / presetList len p iStr gStr ss  ans d dOrder tmpSS)
;DRaw Order Presets
;-------------------------------------------------------
(setq presetList (list
;<name, lowercase/nospaces>   <layers, top -> bottom>
"Somepreset" (list "0" "defpoints")
"Anotherpreset" (list "defpoints" "0")
;;add other presets here.. <name> (list <layers>)
;<name> = initget string, no special characters!
;<layers> = list of strings, layer names (not case sensitive) from top -> bottom
));setq
;-------------------------------------------------------
;set init string and getkword string
(setq len (length presetList) iStr "" gStr "" tmp 1 ss nil)
(if (> len 0)
  (foreach p presetList
    (cond
      ((= tmp 1) (setq iStr p gStr p))
      ((/= 0 (rem tmp 2)) (setq iStr (strcat iStr " " p) gStr (strcat gStr "/" p)))
    );cond
    (setq tmp (1+ tmp))
  );foreach
);if
;get preset from user
(initget 1 iStr)
(setq ans (getkword (strcat "\nSelect Preset Order [" gStr "]: "))) 
(while (not ss)
  (prompt "\nSelect items to order: ")
  (setq ss (ssget))
);while
;find order list, and apply draworder
(setq dOrder (cadr (member ans presetList)) tmpSS (ssadd))
(foreach d (reverse dOrder)
  (if (tblsearch "LAYER" d)
    (progn
      (repeat (setq tmp (sslength ss))
        (setq tmp (1- tmp) e (ssname ss tmp))
        (if (eq (strcase d) (strcase (cdr (assoc 8 (entget e)))))
	  (ssadd e tmpSS)
        );if
	(setq e nil)
      );repeat
      (if (> (sslength tmpSS) 0)
        (command "_.DRAWORDER" tmpSS "" "_f")
        (prompt (strcat "\nNo items found on layer: " d "..."))
      );if
      (setq tmpSS nil tmpSS (ssadd))
    );progn
    (prompt (strcat "\nLayer " d " does not exist..."))
  );if
);foreach
(prompt "\nDROP Complete.")
(princ)
);defun

Hope this helps!

Best,

~DD

0 Likes