ectech Posted February 3, 2010 Posted February 3, 2010 Dear All, I would like to use the lisp to reanme a layer but failed, I not sure the problem is or is there other method to do that ? the code are : (setq abc "aa123456") (command "-rename" "la" aaa "bb123456") Thanks ! Quote
SteveK Posted February 3, 2010 Posted February 3, 2010 Dear All, I would like to use the lisp to reanme a layer but failed, I not sure the problem is or is there other method to do that ? the code are : (setq abc "aa123456") (command "-rename" "la" aaa "bb123456") Thanks ! I think you want the variables highlighted to be the same..? Quote
Tue_NV Posted February 3, 2010 Posted February 3, 2010 Dear All, I would like to use the lisp to reanme a layer but failed, I not sure the problem is or is there other method to do that ? the code are : (setq abc "aa123456") (command "-rename" "la" aaa "bb123456") Thanks ! You can use code (defun c:REL() (setq abc "aa123456") (if (tblsearch "LAYER" abc) (command "RENAME" "LA" abc "bb123456") ) (princ) ) Quote
ectech Posted February 3, 2010 Author Posted February 3, 2010 I think you want the variables highlighted to be the same..? Yes, aaa is the same. Quote
guitarguy1685 Posted February 3, 2010 Posted February 3, 2010 there doesn't seem to be to be any line for input. Are you doing this to multiple drawings? Quote
ectech Posted February 3, 2010 Author Posted February 3, 2010 You can use code (defun c:REL() (setq abc "aa123456") (if (tblsearch "LAYER" abc) (command "RENAME" "LA" abc "bb123456") ) (princ) ) I don't why when I running the program, it will hang up and have some error message in commnad prompt. Enter the object type to rename. But I have already set "la" in the lisp. Quote
guitarguy1685 Posted February 3, 2010 Posted February 3, 2010 well I created a layer "aa123456" and I ran your lisp and it changed the name of it to ""bb12345" successfully. Quote
guitarguy1685 Posted February 3, 2010 Posted February 3, 2010 come to think of it, since you don't even have any user inpute why not just write the line (defun C:rel () (if (tblsearch "LAYER" abc) (command "_.rename" "la" "aa123456" "bb123456") (princ "\n***Layer does not exist***") ) (princ) ) I don't see a need for setq here. Quote
ectech Posted February 3, 2010 Author Posted February 3, 2010 come to think of it, since you don't even have any user inpute why not just write the line (defun C:rel () (if (tblsearch "LAYER" abc) (command "_.rename" "la" "aa123456" "bb123456") (princ "\n***Layer does not exist***") ) (princ) ) I don't see a need for setq here. The problem maybe come from the dialog box, because I'm wirting the dialog box for user. First of all user need select the item from first dialog box and after the selected the second dialog box will come out and I will select the layer aa123456 from the second dialog box. then it will running the command of rename. but at this moment the first dialog still active. I'm not sure it is affect the rename command to function. And any method to unload the first dialog box ? the code as shown: (defun doButton(a) (cond ((= a 1) (s1) ) ) ) (defun C:others() ;;;--- Load the dcl file (setq dcl_id_others (load_dialog "others.dcl")) ;;;--- Load the dialog definition if it is not already loaded (if (not (new_dialog "others" dcl_id_others)) (progn (alert "The others.DCL file could not be loaded!") (exit) ) ) ;;;--- If an action event occurs, do this function (action_tile "but1" "(doButton 1)") (action_tile "but2" "(doButton 2)") (action_tile "but3" "(doButton 3)") (action_tile "cancel" "(done_dialog)") ;;;--- Display the dialog box (start_dialog) ;;;--- Unload the dialog box (unload_dialog dcl_id_others) ;;;--- Suppress the last echo for a clean exit (princ) ) (defun chkToggle() (setq tog1(atoi(get_tile "tog1"))) // 0 = not chosen 1 = chosen (setq tog2(atoi(get_tile "tog2"))) // 0 = not chosen 1 = chosen (setq tog3(atoi(get_tile "tog3"))) // 0 = not chosen 1 = chosen ) (defun S1() ;;;--- Load the dcl file (setq dcl_id (load_dialog "1.dcl")) ;;;--- Load the dialog definition if it is not already loaded (if (not (new_dialog "1" dcl_id) ) (exit)) ;;;--- If an action event occurs, do this function (action_tile "tog1" "(chkToggle)") (action_tile "tog2" "(chkToggle)") (action_tile "tog3" "(chkToggle)") (action_tile "accept" "(setq ddiag 2)(done_dialog)") (action_tile "cancel" "(setq ddiag 1)(done_dialog)") ;;;--- Display the dialog box (start_dialog) ;;;--- Unload the dialog box (unload_dialog dcl_id) ;;;--- If the user pressed the Cancel button (if(= ddiag 1) (princ "\n press 1") ) ;;;--- If the user pressed the Okay button (if(= ddiag 2) (progn (cond ((= tog1 1) (setq aaa "aa123456") (command "-rename" "la" aaa "bb123456") ) ) ) Quote
Lee Mac Posted February 3, 2010 Posted February 3, 2010 Two functions to rename a layer: (defun Layer_ReName (old new / eLst) (cond ( (and (tblsearch "LAYER" old) (not (or (tblsearch "LAYER" new) (eq "0" old)))) (setq eLst (entget (tblobjname "LAYER" old))) (and (entmod (subst (cons 2 new) (assoc 2 eLst) eLst)))))) VL (defun Layer_ReName2 (old new) (vl-load-com) (setq *doc (cond (*doc) ((vla-get-ActiveDocument (vlax-get-acad-object))))) (cond ( (and (tblsearch "LAYER" old) (not (or (tblsearch "LAYER" new) (eq "0" old)))) (not (vl-catch-all-error-p (vl-catch-all-apply (function vla-put-Name) (list (vla-item (vla-get-Layers *doc) old) new))))))) Quote
ronjonp Posted February 3, 2010 Posted February 3, 2010 Wow....I thought there would 5 or six variants posted here Here's my my entmod version: (defun renamelayer (layername rename / lay el) (and (setq lay (tblobjname "layer" layername)) (setq el (entget lay)) (entmod (subst (cons 2 rename) (assoc 2 el) el)) ) ) ;;usage (renamelayer "mickey" "mouse") Quote
Lee Mac Posted February 3, 2010 Posted February 3, 2010 Wow....I thought there would 5 or six variants posted here True, I think everyone just got hooked on the unreliable command call... Another variant: (defun Layer_ReName3 (old new / lay) (and (setq lay (tblobjname "LAYER" old)) (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-put-name (list (vlax-ename->vla-object lay) new)))))) Quote
ectech Posted February 4, 2010 Author Posted February 4, 2010 Two functions to rename a layer: (defun Layer_ReName (old new / eLst) (cond ( (and (tblsearch "LAYER" old) (not (or (tblsearch "LAYER" new) (eq "0" old)))) (setq eLst (entget (tblobjname "LAYER" old))) (and (entmod (subst (cons 2 new) (assoc 2 eLst) eLst)))))) VL (defun Layer_ReName2 (old new) (vl-load-com) (setq *doc (cond (*doc) ((vla-get-ActiveDocument (vlax-get-acad-object))))) (cond ( (and (tblsearch "LAYER" old) (not (or (tblsearch "LAYER" new) (eq "0" old)))) (not (vl-catch-all-error-p (vl-catch-all-apply (function vla-put-Name) (list (vla-item (vla-get-Layers *doc) old) new))))))) Thanks ! Lee Mac. If I selected 2 or more items from dialog box, it only rename one item. how to make it work for 2 or more items ? Thanks ! Quote
Lee Mac Posted February 4, 2010 Posted February 4, 2010 These are sub-functions, requiring arguments, so you can use them in such statements as mapcar, for example. (defun Layer_ReName (old new / eLst) (cond ( (and (tblsearch "LAYER" old) (not (or (tblsearch "LAYER" new) (eq "0" old)))) (setq eLst (entget (tblobjname "LAYER" old))) (and (entmod (subst (cons 2 new) (assoc 2 eLst) eLst)))))) (mapcar (function Layer_ReName) '("OldLayer1" "OldLayer2") '("NewLayer1" "NewLayer2")) Quote
ectech Posted February 4, 2010 Author Posted February 4, 2010 These are sub-functions, requiring arguments, so you can use them in such statements as mapcar, for example. (defun Layer_ReName (old new / eLst) (cond ( (and (tblsearch "LAYER" old) (not (or (tblsearch "LAYER" new) (eq "0" old)))) (setq eLst (entget (tblobjname "LAYER" old))) (and (entmod (subst (cons 2 new) (assoc 2 eLst) eLst)))))) (mapcar (function Layer_ReName) '("OldLayer1" "OldLayer2") '("NewLayer1" "NewLayer2")) Actually my lisp doing that : 1. call a dialog box 2. select layers I want to check 3. if this layer not found then I call a lisp to popup another dialog box for me to select the correct layer 4. after selected the correct layer then rename it. (if(= ddiag 2) (progn (cond ((= tog1 1) (progn ..... .... (Layer_ReName aaa "aa123456") ) );end condition 1 ((= tog2 1) (progn (Layer_ReName aaa "bb123456") ) ) );end condition 2 The problem is both tog1 and tog2 is selected but only tog1 can rename to aa123456. Quote
Lee Mac Posted February 4, 2010 Posted February 4, 2010 It is because you are using a COND statement, in which only the first test statement to return True is evaluated. PS> No need for progn. Quote
ectech Posted February 4, 2010 Author Posted February 4, 2010 It is because you are using a COND statement, in which only the first test statement to return True is evaluated. PS> No need for progn. Thank you very much for your help Lee Mac, it work now ! Quote
Lee Mac Posted February 4, 2010 Posted February 4, 2010 Thank you very much for your help Lee Mac, it work now ! You're welcome, happy to help out Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.