Guest looseLISP 发表于 2022-7-6 11:41:04

* (astrix) dose not work in li

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???

ReMark 发表于 2022-7-6 11:50:10

It appears it doesn't work at the command line either (returns the prompt Invalid layer name).

MSasu 发表于 2022-7-6 11:55:34

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,

David Bethel 发表于 2022-7-6 12:00:34

 
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

alanjt 发表于 2022-7-6 12:03:30

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.

alanjt 发表于 2022-7-6 12:12:11

OH yeah, don't forget (vl-load-com) if you don't have it loaded.

alanjt 发表于 2022-7-6 12:16:50

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

Guest looseLISP 发表于 2022-7-6 12:23:34

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

Lee Mac 发表于 2022-7-6 12:26:23

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...

alanjt 发表于 2022-7-6 12:35:31

Well, I suppose as long as you're happy.
页: [1] 2
查看完整版本: * (astrix) dose not work in li