Jump to content

* (astrix) dose not work in lisp


Recommended Posts

Guest looseLISPSsinkSHIPS
Posted

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

Posted

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

Posted

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,

Posted
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

Posted

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.

Posted

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

Posted

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 looseLISPSsinkSHIPS
Posted

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

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

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

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...