;-----------------------------------------------------------------
; 19.6.92 AW - aus der Zeitschrift CADENCE
; - gegenber des Originals werden die Pfade ge„ndert
; GLOBAL LAYER CHANGE SYSTEM
; Utility functions for changing layer names in complete drawings
; LISTLYR  Generates a file using the drawing name plus extension LYR
;          that contains a line for each layer in a drawing
; UPDLYR   Reads the LYR table file after the new layer assignments
;          have been defined and RENAMES each layert
; SPARSE   Library routine for parsing strings into lists
;----------------------------------------------------------------
(prompt "\nLade LISTLYR")
(defun c:listlyr ()
	(setq 
	S  (tblnext "LAYER" T)
	FH (open (strcat (getvar "DWGNAME") ".LYR") "w")
	)
	(while S
		(write-line (cdr (assoc 2 S)) FH)
		(setq S (tblnext "LAYER"))
	)
	(setq FH (close FH))
	(prompt (strcat "\nIn die Datei : " (getvar "DWGNAME") ".LYR"))
	(prompt "\ndie neuen Layer eintragen")
	(princ))
;---------------------------------------------------------------------
(prompt "\nLade UPDLYR")
(defun c:updlyr ()
	(setq FH (open (strcat (getvar "DWGNAME") ".LYR") "r") CNT 0)
	(while (setq S (read-line FH))
		(setq S (sparse S "=")
			CNT (1+ CNT)
			SS1 (ssget "X" (list (cons 8 (car S)))))
	(if SS1
		(command "LAYER" "SE" "0" "")
	(cond
		((= (cadr S)NIL)(prompt (strcat "\nLayer bersprungen " (car s)"\n"))
			(setq SF (open "c:\\daten\\acad\\dwg\\skiplayr.lyr" "a"))
			(write-line (car s) SF)
			(close SF))
;		(t(command "UMBENENN" "LA" (car s) (cadr s))))))
		((command "UMBENENN" "LA" (car s) (cadr s))))))
		(setq FH (close FH))
	)
;--------------------------------------------------------------------------------------------
(defun sparse (s d / RR RS)
	(setq RS "")
	(repeat (strlen S)
		(if (= (substr S 1 1) d)
		    (setq RR (cons RS RR) RS "")
		    (setq RS (strcat RS (substr S 1 1))))
		(setq S (substr S 2)))
	(reverse (cons RS RR)))
(textscr)
(prompt "\nFunktionen geladen.")
(prompt "\nMit LISTLYR wird eine Datei mit der Layerliste erstellt.")
(prompt "\nDann mit dem AutoCAD SHELL einen Texteditor aufrufen")
(prompt "\nund die Datei bearbeiten. Wenn z.B. die Ebene ")
(prompt "\nL-1__40 in der Zeichnung L-1 heiáen soll, wird die")
(prompt "\nentsprechende Zeile in L-1__40=L-1 ge„ndert.")
(prompt "\nWenn die Žnderungen durchgefhrt sind zurck zu AutoCAD ")
(prompt "\nMit UPDLYR werden die Žnderungen automatisch durchgefhrt")
(princ)



