Jump to content

Remove $ from layer name


mostafa badran

Recommended Posts

hi all,I need help, I need lisp which can remove $ from layer name ,block name ,style text ,etc. with explain the steps of syntax of lisp.

thanks for help.

mostafa

Link to comment
Share on other sites

You can already accomplish this with the RENAME tool, utilizing wildcard matches to edit all names in these categories.

Thanks tzframpton fro respond,can you to clarify more,there's too much layers, blocks,the RENAME tool renamed as single category.

Link to comment
Share on other sites

Start withthis one

(defun c:BF


;/////////////////////////////////////////////////////////////////////////
  ;
  ;  BindFix15.lsp (AutoCAD 2000+)
  ;
  ;  Copyright 2003 | Michael Puckett | All Rights Reserved
  ;

;/////////////////////////////////////////////////////////////////////////

  (  /
     ;  local defuns
     __GetTableEntries
     __RenameTableEntry
     __RenameTableEntryViaObjname
     __RenameTableEntryViaActiveX
     __StripBindingArtifacts
     __GetUniqueTableEntryName
     ;  local vars
     doc
     newname
  )


;/////////////////////////////////////////////////////////////////////////
  ;
  ;  local defun
  ;

;/////////////////////////////////////////////////////////////////////////

  (defun __GetTableEntries ( table / data result )
     (while (setq data (tblnext table (null data)))
        (setq result
           (cons (cdr (assoc 2 data)) result)
        )
     )
     result
  )


;/////////////////////////////////////////////////////////////////////////
  ;
  ;  local defun
  ;

;/////////////////////////////////////////////////////////////////////////

  (defun __RenameTableEntry ( doc table oldname newname / data )
     ;  wrapper for __RenameTableEntryViaObjname
     ;  and __RenameTableEntryViaActiveX functions
     (setq table
        (cond
           ((eq (setq table (strcase table t)) "ltype") "linetype")
           (t table)
        )
     )
     (if (member table '("style" "dimstyle"))
        ;  autodesk made textstyles and dimstyles read-only to
        ;  the automation model w/regards to the symbol name, why?
        (__RenameTableEntryViaObjname table oldname newname)
        (__RenameTableEntryViaActiveX doc table oldname newname)
     )
  )


;/////////////////////////////////////////////////////////////////////////
  ;
  ;  local defun
  ;

;/////////////////////////////////////////////////////////////////////////

  (defun __RenameTableEntryViaObjname ( table oldname newname / data )
     ;  calling function responsible for
     ;  ensuring appropriate data passed
     (entmod
        (subst
           (cons 2 newname)
           (assoc 2 (setq data (entget (tblobjname table oldname))))
           data
        )
     )
  )


;/////////////////////////////////////////////////////////////////////////
  ;
  ;  local defun
  ;

;/////////////////////////////////////////////////////////////////////////

  (defun __RenameTableEntryViaActiveX ( doc table oldname newname / data )
     ;  calling function responsible for
     ;  ensuring appropriate data passed
     (vla-put-name
        (vla-item
           (eval
              (list
                 (read (strcat "vla-get-" table "s"))
                 doc
              )
           )
           oldname
        )
        newname
     )
     ;  if you wanted this to be more robust
     ;  you could use the following ...
     ;
     ;  (vl-catch-all-apply
     ;     (function
     ;        (lambda ()
     ;           (vla-put-name ...)
     ;        )
     ;     )
     ;  )
     ;
     ;  I chose to pass valid data instead
  )


;/////////////////////////////////////////////////////////////////////////
  ;
  ;  local defun
  ;

;/////////////////////////////////////////////////////////////////////////

  (defun __StripBindingArtifacts ( entry / i done )
     (cond
        (  (wcmatch entry "*`$#`$*")
           (setq i 0 ceiling (strlen entry))
           (while (and (not done) (< i ceiling))
              (if (wcmatch (substr entry (setq i (1+ i)) 3) "`$#`$*")
                 (setq
                    entry (substr entry (+ i 3))
                    done  t
                 )
              )
           )
        )
     )
     entry
  )


;/////////////////////////////////////////////////////////////////////////
  ;
  ;  local defun
  ;

;/////////////////////////////////////////////////////////////////////////

  (defun __GetUniqueTableEntryName ( table entry )
     (cond
        (  (tblsearch table entry)
           (setq i 1)
           (while
              (tblsearch table
                 (strcat entry "_" (itoa (setq i (1+ i))))
              )
           )
           (strcat entry "_" (itoa i))
        )
        (  t entry  )
     )
  )


;/////////////////////////////////////////////////////////////////////////
  ;
  ;  "main"
  ;

;/////////////////////////////////////////////////////////////////////////

  (cond

     (  (< 14 (atoi (getvar "acadver")))

        (vl-load-com)

        (setq doc (vla-get-activedocument (vlax-get-acad-object)))

        (foreach table '("block" "dimstyle" "layer" "ltype" "style")
           (foreach entry (reverse (__GetTableEntries table))
              (cond
                 (  (wcmatch entry "*`$#`$*")
                    (__RenameTableEntry
                       doc
                       table
                       entry
                       (setq newname
                          (__GetUniqueTableEntryName table
                             (__StripBindingArtifacts entry)
                          )
                       )
                    )
                    (princ
                       (strcat "\n"
                          (if (tblsearch table newname)
                             (strcat
                                "Renamed "
                                table " "
                                entry " => "
                                newname "."
                             )
                             (strcat
                                "Could not rename "
                                table " "
                                entry "."
                             )
                          )
                       )
                    )
                 )
              )
           )
        )
     )

     (  t (princ "\nSorry, penned for AutoCAD 2000+."))

  )

  (princ)

)

Link to comment
Share on other sites

Start withthis one

(defun c:BF


;/////////////////////////////////////////////////////////////////////////
  ;
  ;  BindFix15.lsp (AutoCAD 2000+)
  ;
  ;  Copyright 2003 | Michael Puckett | All Rights Reserved
  ;

;/////////////////////////////////////////////////////////////////////////

  (  /
     ;  local defuns
     __GetTableEntries
     __RenameTableEntry
     __RenameTableEntryViaObjname
     __RenameTableEntryViaActiveX
     __StripBindingArtifacts
     __GetUniqueTableEntryName
     ;  local vars
     doc
     newname
  )


;/////////////////////////////////////////////////////////////////////////
  ;
  ;  local defun
  ;

;/////////////////////////////////////////////////////////////////////////

  (defun __GetTableEntries ( table / data result )
     (while (setq data (tblnext table (null data)))
        (setq result
           (cons (cdr (assoc 2 data)) result)
        )
     )
     result
  )


;/////////////////////////////////////////////////////////////////////////
  ;
  ;  local defun
  ;

;/////////////////////////////////////////////////////////////////////////

  (defun __RenameTableEntry ( doc table oldname newname / data )
     ;  wrapper for __RenameTableEntryViaObjname
     ;  and __RenameTableEntryViaActiveX functions
     (setq table
        (cond
           ((eq (setq table (strcase table t)) "ltype") "linetype")
           (t table)
        )
     )
     (if (member table '("style" "dimstyle"))
        ;  autodesk made textstyles and dimstyles read-only to
        ;  the automation model w/regards to the symbol name, why?
        (__RenameTableEntryViaObjname table oldname newname)
        (__RenameTableEntryViaActiveX doc table oldname newname)
     )
  )


;/////////////////////////////////////////////////////////////////////////
  ;
  ;  local defun
  ;

;/////////////////////////////////////////////////////////////////////////

  (defun __RenameTableEntryViaObjname ( table oldname newname / data )
     ;  calling function responsible for
     ;  ensuring appropriate data passed
     (entmod
        (subst
           (cons 2 newname)
           (assoc 2 (setq data (entget (tblobjname table oldname))))
           data
        )
     )
  )


;/////////////////////////////////////////////////////////////////////////
  ;
  ;  local defun
  ;

;/////////////////////////////////////////////////////////////////////////

  (defun __RenameTableEntryViaActiveX ( doc table oldname newname / data )
     ;  calling function responsible for
     ;  ensuring appropriate data passed
     (vla-put-name
        (vla-item
           (eval
              (list
                 (read (strcat "vla-get-" table "s"))
                 doc
              )
           )
           oldname
        )
        newname
     )
     ;  if you wanted this to be more robust
     ;  you could use the following ...
     ;
     ;  (vl-catch-all-apply
     ;     (function
     ;        (lambda ()
     ;           (vla-put-name ...)
     ;        )
     ;     )
     ;  )
     ;
     ;  I chose to pass valid data instead
  )


;/////////////////////////////////////////////////////////////////////////
  ;
  ;  local defun
  ;

;/////////////////////////////////////////////////////////////////////////

  (defun __StripBindingArtifacts ( entry / i done )
     (cond
        (  (wcmatch entry "*`$#`$*")
           (setq i 0 ceiling (strlen entry))
           (while (and (not done) (< i ceiling))
              (if (wcmatch (substr entry (setq i (1+ i)) 3) "`$#`$*")
                 (setq
                    entry (substr entry (+ i 3))
                    done  t
                 )
              )
           )
        )
     )
     entry
  )


;/////////////////////////////////////////////////////////////////////////
  ;
  ;  local defun
  ;

;/////////////////////////////////////////////////////////////////////////

  (defun __GetUniqueTableEntryName ( table entry )
     (cond
        (  (tblsearch table entry)
           (setq i 1)
           (while
              (tblsearch table
                 (strcat entry "_" (itoa (setq i (1+ i))))
              )
           )
           (strcat entry "_" (itoa i))
        )
        (  t entry  )
     )
  )


;/////////////////////////////////////////////////////////////////////////
  ;
  ;  "main"
  ;

;/////////////////////////////////////////////////////////////////////////

  (cond

     (  (< 14 (atoi (getvar "acadver")))

        (vl-load-com)

        (setq doc (vla-get-activedocument (vlax-get-acad-object)))

        (foreach table '("block" "dimstyle" "layer" "ltype" "style")
           (foreach entry (reverse (__GetTableEntries table))
              (cond
                 (  (wcmatch entry "*`$#`$*")
                    (__RenameTableEntry
                       doc
                       table
                       entry
                       (setq newname
                          (__GetUniqueTableEntryName table
                             (__StripBindingArtifacts entry)
                          )
                       )
                    )
                    (princ
                       (strcat "\n"
                          (if (tblsearch table newname)
                             (strcat
                                "Renamed "
                                table " "
                                entry " => "
                                newname "."
                             )
                             (strcat
                                "Could not rename "
                                table " "
                                entry "."
                             )
                          )
                       )
                    )
                 )
              )
           )
        )
     )

     (  t (princ "\nSorry, penned for AutoCAD 2000+."))

  )

  (princ)  

)

Thanks Mr asos2000 I will try this,thanks for your response.

Link to comment
Share on other sites

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