Guest looseLISPSsinkSHIPS Posted February 16, 2010 Posted February 16, 2010 Hi, We need to rename all incoming layers, to achieve this I had devised the next lisp: CODE STARTS HERE (Command "rename" "La" "*" "(IMPORTED)*") CODE ENDS HERE However I cannot get the astrix to select all the old layers. Dose anyone know the solution to this??? Quote
ReMark Posted February 16, 2010 Posted February 16, 2010 It appears it doesn't work at the command line either (returns the prompt Invalid layer name). Quote
MSasu Posted February 16, 2010 Posted February 16, 2010 This may help you: (defun AddPrefixToLayerNames( thePrefix / LayerEntry LayerAssocList ) (setq LayerEntry (cdr (assoc 2 (tblnext "LAYER" 1)))) (while LayerEntry (setq LayerAssocList (entget (tblobjname "LAYER" LayerEntry))) (if (/= LayerEntry "0") (progn (setq LayerAssocList (subst (cons '2 (strcat thePrefix LayerEntry)) (assoc 2 LayerAssocList) LayerAssocList)) (entmod LayerAssocList) ) ) (setq LayerEntry (cdr (assoc 2 (tblnext "LAYER")))) ) (princ) ) Use it: (AddPrefixToLayerNames "MyPrefixString") Regards, Quote
David Bethel Posted February 16, 2010 Posted February 16, 2010 Hi, We need to rename all incoming layers, to achieve this I had devised the next lisp: You will need a fairly complex routine to do what you're asking for. You will have to deal with locked layers, nested block entities layers, etc. Sorry -David Quote
alanjt Posted February 16, 2010 Posted February 16, 2010 Give this a try... ;;; Add Prefix and/or Suffix to all layers (excluding 0, Defpoints and XRef layers ;;; #Prefix - Prefix string to append to layer names (nil for nothing) ;;; #Suffix - Suffix string to append to layer names (nil for nothing) ;;; Alan J. Thompson, 02.16.10 (defun LayerPrefixSuffix (#Prefix #Suffix / #Prefix #Suffix) (or *AcadDoc* (setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object)))) (and (or (and (not #Prefix) (setq #Prefix "")) (snvalid #Prefix) (setq #Prefix "")) (or (and (not #Suffix) (setq #Suffix "")) (snvalid #Suffix) (setq #Suffix "")) (progn (vlax-for x (vla-get-layers *AcadDoc*) (or (wcmatch (strcase (vla-get-name x)) "*|*,0,DEFPOINTS") (vl-catch-all-apply 'vla-put-name (list x (strcat #Prefix (vla-get-name x) #Suffix))) ) ;_ or ) ;_ vlax-for T ) ;_ progn ) ;_ and ) ;_ defun Example: (LayerPrefixSuffix "Begin-" "-End") It will allow you to add a prefix and/or a suffix. Works on locked layers and ignores the 0, Defpoints and XRef layers. Quote
alanjt Posted February 16, 2010 Posted February 16, 2010 OH yeah, don't forget (vl-load-com) if you don't have it loaded. Quote
alanjt Posted February 16, 2010 Posted February 16, 2010 Also, here's one I wrote to rename a layer... ;;; Rename layer ;;; #OldName - Layer to rename ;;; #NewName - New name for layer ;;; Returns T if successful, nil if not ;;; Alan J. Thompson, 10.07.09 (defun AT:LayerRename (#OldName #NewName) (and (tblsearch "layer" #OldName) (not (tblsearch "layer" #NewName)) (snvalid #NewName) (or *AcadDoc* (setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))) ) ;_ or (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-put-name (list (vla-item (vla-get-layers *AcadDoc*) #OldName) #NewName) ) ;_ vl-catch-all-apply ) ;_ vl-catch-all-error-p ) ;_ not ) ;_ and ) ;_ defun Quote
Guest looseLISPSsinkSHIPS Posted February 17, 2010 Posted February 17, 2010 lol fixed this successfully in another forum with the following code CODE STARTS HERE (vlax-for layer (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object) ) ) (setq ln (vla-get-name layer)) (if (not (or (= ln "0") (= ln "Defpoints"))) (vla-put-name layer (strcat "(IMPORTED) " ln)) ) ) CODE ENDS HERE Quote
Lee Mac Posted February 17, 2010 Posted February 17, 2010 Why not enclose your code in tags or see here: http://www.cadtutor.net/forum/showthread.php?t=9184 Nobody seems to read the sticky... Quote
alanjt Posted February 17, 2010 Posted February 17, 2010 Well, I suppose as long as you're happy. Quote
Lee Mac Posted February 17, 2010 Posted February 17, 2010 Well, I suppose as long as your happy. Agreed, I would have at least used a catch-all-apply, if not checked for duplicate layer creation or even existing (IMPORTED) prefixes. Quote
alanjt Posted February 17, 2010 Posted February 17, 2010 Agreed, I would have at least used a catch-all-apply, if not checked for duplicate layer creation or even existing (IMPORTED) prefixes. Psh, too many variables. :wink: Look at that horrible grammatical error. Shame on me. 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.