btraemoore.
First of all, dont put the read-line function inside the while loop.Read and parse the text file once to create a list
Where laylst is the data from reading and parsing the file
Lets say you have the layer ELECTRICAL 7 HIDDEN
<untested>
It reduces the list per loop depending on the first character of the layernameCode:(defun c:moore (/ _match laylst a coll tlst) (defun _match (nm col lt lst / n f) (while (and (setq n (car lst)) (not f)) (if (and (wcmatch (strcase nm) (strcat (car n) "*")) (eq col (cadr n)) (eq (strcase lt) (last n))) (setq f T) (setq lst (cdr lst)))) (car n)) (vl-load-com) (setq acadDocument (vla-get-activedocument (vlax-get-acad-object))) (setq layertable (vla-get-layers acadDocument)) ;;; example Result from a parsing routine ;;; (setq laylst '(("CPRT" 4 "CONTINUOUS") ("CPRT" 7 "CONTINUOUS") ("CUTLINE" 5 "HIDDEN") ("CUTLINE" 7 "HIDDEN") ("DASHED" 2 "DASHED") ("DASHED" 2 "PHANTOM") ("DASHED" 7 "PHANTOM") ("DEFPOINTS" 7 "CONTINUOUS") ("DEPT" 3 "CONTINUOUS") ("DEPT" 7 "CONTINUOUS") ("DIM" 2 "CONTINUOUS") ("DIM" 7 "CONTINUOUS") ("DIMN" 1 "CONTINUOUS") ("DIMN" 7 "CONTINUOUS") ("ELEC" 1 "HIDDEN") ("ELEC" 7 "HIDDEN"))) (while (setq a (tblnext "LAYER" (null a))) (setq coll (list (cdr (assoc 2 a)) (cdr (assoc 62 a)) (cdr (assoc 6 a)))) (if (and (setq tlst (vl-remove-if-not '(lambda (ly) (eq (strcase (substr (car ly) 1 1)) (strcase (substr (car coll) 1 1)))) laylst)) (setq newname (_match (car coll)(cadr coll)(last coll) tlst)) ) (vla-put-name (vla-item layertable (car coll)) newname)) ) )
Then use _match routine for "comparison" test if found returens the New Layer Name
HTH
BTW: what i meant by this
is it one or the other? because you have two lines ELEC 1 HIDDEN ELEC 7 HIDDEN included on the text file.ELECTRICAL/1/HIDDEN will be ELEC, and ELECTRICAL/7/HIDDEN will also be ELEC, is that right?





Reply With Quote


Bookmarks