(progn
(vl-load-com)
(vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
(if (wcmatch (strcase (setq name (vla-get-name layer))) "~*NEW")
(vl-catch-all-apply 'vla-put-name
(list layer (strcat name "new"))
)
)
)
(princ)
)
Subtitle: Mapcar is a great function but not the solution for everything.
So you are trying to rename a layer if the layer is found, based on two lists?Code - Lisp: [Select]
(foreach i (mapcar (function cons) list1 list2) (if .... search of '(car i)' ... rename '(car i)' to '(cdr i)'.. ) )
Typed in message, so be careful, but the idea is there.[/code]
What my caffeine deprived brain thinks ...Code: [Select](progn
(vl-load-com)
(vlax-for layer (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
(if (wcmatch (strcase (setq name (vla-get-name layer))) "~*NEW")
(vl-catch-all-apply 'vla-put-name
(list layer (strcat name "new"))
)
)
)
(princ)
)
Subtitle: Mapcar is a great function but not the solution for everything.
So you are trying to rename a layer if the layer is found, based on two lists?Code - Lisp: [Select]
(foreach i (mapcar (function cons) list1 list2) (if .... search of '(car i)' ... rename '(car i)' to '(cdr i)'.. ) )
Typed in message, so be careful, but the idea is there.[/code]
i dont want rename layer because if layer 1new have in drawing. i mean creat lst layer new then merge layer_old with new. I have not found the answer loop.
(defun c:123 (/ lst1 lst2 n layer1 layer2)
(setq lst1 (list "1" "2" "3" "4" "5" "6"))
(setq lst2 (list "1new" "2new" "3new" "4new" "5new" "6new"))
(setq n 0)
(repeat
(SsLength lst1)
(setq layer1 (nth n lst1))
(setq layer2 (nth n lst2))
(if (tblsearch "LAYER" layer1)
(if (tblsearch "LAYER" layer2)
(command "_.LAYMRG" "_Name" layer1 "" "_N" layer2 "_Y")
);if layer2
);if layer1
(setq n (+ n 1))
)
(princ)
)
Pls check it.
If I've correctly understood:Code - Auto/Visual Lisp: [Select]
) ) )Code - Auto/Visual Lisp: [Select]
Hi Tim, if one intends to add or delete items from a collection then it would be ill advised to do so while iterating it. In the code snip I provided I'm merely abusing a collection item's property (name) that has no impact upon the container (aside from potential duplicate key or non modifiable layer, ergo the catch code).
For example, if I were iterating thru the dictionary collection looking to delete any dictionary entry with an "AEC" prefix I'd collect the offending dictionaries in a temporary list and then delete all the items in said temporary list.
(defun _Items ( collection / items )
(vlax-for i collection (setq items (cons i items)))
;; Since this is a general function reflect
;; the collection's original item order.
(reverse items)
)
(defun _Purge ( collection n )
;; Try to delete collection entries n times
;; (to deal with intra-entry dependencies).
( (lambda ( live n / dead )
(repeat n
(foreach i live
(vl-catch-all-apply 'vla-delete (list i))
(if (vlax-erased-p i) (setq dead (cons i dead)))
)
(setq live (vl-remove-if (function (lambda (i) (member i dead))) live))
)
(length dead)
)
;; Process newest entries first.
(reverse (_Items collection))
;; Idiot proof the n argument.
(if (eq 'int (type n)) n 1)
)
)