Author Topic: Asci characters in layer names  (Read 5136 times)

0 Members and 1 Guest are viewing this topic.

TJAM51

  • Guest
Asci characters in layer names
« on: February 20, 2008, 11:48:54 AM »
Is there any way a routine could find through some selection a way of renaming layers with asci characters or deleting the asci characters from the layer name.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Asci characters in layer names
« Reply #1 on: February 20, 2008, 12:22:18 PM »
WCMATCH is a great tool.

Would you please define "ASCII characters", as all characters are ASCII characters in my book.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

TJAM51

  • Guest
Re: Asci characters in layer names
« Reply #2 on: February 20, 2008, 12:40:32 PM »
here is an example of the layer name



30x42-ttl$0$G-TTTLT

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Asci characters in layer names
« Reply #3 on: February 20, 2008, 12:44:07 PM »
here is an example of the layer name



30x42-ttl$0$G-TTTLT
Don't bind xref's as binds then.   :-D

Are you just trying to remove anything that isn't a letter or number or hyphen?
Or is it just the dollar signs and whats in between them?
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Asci characters in layer names
« Reply #4 on: February 20, 2008, 12:44:29 PM »
It's long in the tooth but it still may work => link.

Look for the 'topmost' version of BindFix15.lsp.

Edit: Fubar 404 -- Autodesk killed the thread or something. See code below instead:

Code: [Select]
(defun c:BindFix

    ;;====================================================================
    ;;
    ;;  BindFix.lsp (AutoCAD 2000+)
    ;;
    ;;--------------------------------------------------------------------
    ;;
    ;;  Copyright 2003-2014 · Michael Puckett · All Rights Reserved
    ;;
    ;;  Ver 1.00 2003/??/?? (MP) Original code .
    ;;
    ;;  Ver 1.01 2004/04/23 (MP) General fixes.
    ;;
    ;;      Fixed:
    ;;
    ;;      _RenameTableEntry: had superfluous local decl. 'data'.
    ;;      _RenameTableEntryViaActiveX: had superfluous local decl. 'data'
    ;;      _StripBindingArtifacts: missing local decl. 'ceiling'.
    ;;      _GetUniqueTableEntryName: missing local decl. 'i'.
    ;;
    ;;  Ver 1.02 2014/12/08 (MP) Add ability to rename dictionaries etc.
    ;;
    ;;      Added:
    ;;
    ;;      _GetDictEntries: To support renaming dictionary based entries.   
    ;;      _GetName: See above.
    ;;      _RenameDataLinks: As name suggests.
    ;;      _RenameDicts: As name suggests.
    ;;      _Try: General purpose fubar catcher.
    ;;
    ;;      Recoded:
    ;;
    ;;      _StripBindingArtifacts: Didn't deal with nested artifacts.
    ;;
    ;;--------------------------------------------------------------------

    (   /
        _GetDictEntries
        _GetName
        _GetTableEntries
        _GetUniqueTableEntryName
        _Main
        _RenameDataLinks
        _RenameDicts
        _RenameTableEntry
        _RenameTableEntryViaActiveX
        _RenameTableEntryViaObjname
        _StripBindingArtifacts
        _Try
    )

    (defun _Try ( try_statement / try_catch try_result )

        (if
            (vl-catch-all-error-p
                (setq try_catch
                    (vl-catch-all-apply
                        (function
                            (lambda ( )
                                (setq try_result (eval try_statement))
                            )
                        )
                    )
                )
            )
            (setq *try_errors* ;; global
                (cons
                    (list
                        try_statement
                        (vl-catch-all-error-message try_catch)
                    )
                    *try_errors*
                )
            )
        )

        try_result

    )

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

    (defun _RenameTableEntry ( doc table oldname newname )
        ;;  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)
        )
    )

    (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
            )
        )
    )

    (defun _RenameTableEntryViaActiveX ( doc table oldname newname )
        (_Try
           '(vla-put-name
                (vla-item
                    (vlax-get
                        doc
                        (read (strcat table "s"))
                    )
                    oldname
                )
                newname
            )
        )
    )

    (defun _StripBindingArtifacts ( entry / n )

        (while (progn (setq n 0) (wcmatch entry "*$#$*"))
            (while (wcmatch (substr entry (setq n (1+ n))) "~$#$*"))
            (setq entry (substr entry (+ n 3)))
        )

        entry

    )

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

    (defun _GetDictEntries ( doc dictName / result )

        (_Try
           '(vlax-for item (vla-item (vla-get-dictionaries doc) dictName)
                (setq result (cons item result))
            )
        )

        (reverse result)

    )

    (defun _GetName ( object / name )

        (_Try '(setq name (vla-get-name object)))

        (if name name "")

    )

    (defun _RenameDicts ( dictEntries / suffix i name new_name )

        (foreach dict dictEntries
            (if (wcmatch (setq suffix "" i 1 name (_GetName dict)) "*$#$*")
                (progn
                    (setq new_name (_StripBindingArtifacts name))
                    (while
                        (member
                            (strcase
                                (setq new_name
                                    (strcat new_name suffix)
                                )
                            )
                            (mapcar 'strcase (mapcar '_GetName dictEntries))
                        )
                        (setq suffix (strcat "_" (itoa (setq i (1+ i)))))
                    )
                    (_Try '(vla-put-name dict new_name))
                    (princ
                        (strcat "\n"
                            (if (eq new_name (_GetName dict))
                                (strcat
                                    "Renamed "
                                    (vla-get-objectname dict) " "
                                    name " => "
                                    new_name "."
                                )
                                (strcat
                                    "Could not rename "
                                    (vla-get-objectname dict) " "
                                    name "."
                                )
                            )
                        )
                    )
                )
            )
        )
    )

    (defun _RenameDataLinks ( doc / ename data new_names old_names )

        (_Try
           '(setq data
                (entget
                    (setq ename
                        (vlax-vla-object->ename
                            (vla-item
                                (vla-get-dictionaries doc)
                                "ACAD_DATALINK"
                            )
                        )
                    )
                )
            )
        )

        (_Try
           '(entmod
                (mapcar
                    (function
                        (lambda ( pair / i suffix name new_name )
                            (cond
                                (   (and
                                        (eq 3 (car pair))
                                        (wcmatch (setq name (cdr pair)) "*$#$*")
                                        (setq old_names (cons name old_names))
                                        (setq i 1 suffix "" new_name (_StripBindingArtifacts name))
                                    )

                                    (while
                                        (member
                                            (strcase (setq new_name (strcat new_name suffix)))
                                            (mapcar 'strcase new_names)
                                        )
                                        (setq suffix (strcat "_" (itoa (setq i (1+ i)))))
                                    )
                                   
                                    (cons 3
                                        (car
                                            (setq new_names
                                                (cons new_name new_names)
                                            )
                                        )
                                    )

                                )
                                (   t
                                    pair
                                )
                            )
                        )
                    )
                    data
                )
            )
        )
       
        (_Try
           '(setq data
                (entget ename)
            )
        )
       
        (if old_names
            (foreach lst (mapcar 'cons old_names new_names)
                (princ
                    (strcat "\n"
                        (if (member (cons 3 (cdr lst)) data)
                            (strcat
                                "Renamed datalink "
                                (car lst) " => "
                                (cdr lst) "."
                            )
                            (strcat
                                "Could not rename datalink "
                                (car lst) "."
                            )
                        )
                    )
                )
            )
        )

    )

    (defun _Main ( doc / newname )

        ;;  do normal table entries

        (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 "."
                                    )
                                )
                            )
                        )
                    )
                )
            )
        )

        ;;  now do dictionary based entries

        (foreach dictName
           '(   "ACAD_GROUP"
                "ACAD_MLEADERSTYLE"
                "ACAD_MLINESTYLE"
                "ACAD_TABLESTYLE"
            )
            (_RenameDicts (_GetDictEntries doc dictName))
        )

        ;;  now datalinks

        (_RenameDataLinks doc)

        (princ)

    )

    (_Main
        (progn
            (vl-load-com)
            (vla-get-activedocument (vlax-get-acad-object))
        )
    )

)

« Last Edit: December 08, 2014, 01:45:06 PM by MP »
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

TJAM51

  • Guest
Re: Asci characters in layer names
« Reply #5 on: February 20, 2008, 12:53:13 PM »
I am seeking to delete any characters that would be left over from binding an xref and then exploding it. The $0$ seems to be the most comon....I am looking to delete those characters.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Asci characters in layer names
« Reply #6 on: February 20, 2008, 12:57:29 PM »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

TJAM51

  • Guest
Re: Asci characters in layer names
« Reply #7 on: February 20, 2008, 01:04:26 PM »
I am using 2008...it did not work....there are approximately 15 layers in the the drawing as follows

Layer: x68202ebs$0$LEGEND was not renamed.
 Layer: x68202ebs$0$G-HATCH was not renamed.
 Layer: x68202pbs$0$P-TEXT was not renamed.
 Layer: x68202pbs$0$P-DIMS was not renamed.
 Layer: x68202pbs$0$CONCRETE was not renamed.
 Layer: GR634101$0$MP634100$0$A-Wall-Patt was not renamed.
 Layer: GR634101$0$MP634100$0$A-Wall-Comp was not renamed.
 Layer: GR634101$0$MP634100$0$A-Wall-Abov was not renamed.
 Layer: GR634101$0$MP634100$0$A-Wall-Blow was not renamed.
 Text style: x68202ebs$0$bpi60 was not renamed.
 Text style: x68202ebs$0$BPI-STD was not renamed.
 Text style: x68202ebs$0$SIMPLEX was not renamed.
 Text style: x68202ebs$0$BPI-BOLD was not renamed.
 Text style: x68202ebs$0$l100 was not renamed.
 Text style: x68202pbs$0$SIMPLEX was not renamed.
 Text style: x68202pbs$0$BPI-STD was not renamed.
 Text style: x68202pbs$0$x68202pbs$0$SIMPLEX was not renamed.
 Text style: x68202pbs$0$x68202pbs$0$BPI-STD was not renamed.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Asci characters in layer names
« Reply #8 on: February 20, 2008, 01:20:11 PM »
I am using 2008...it did not work....there are approximately 15 layers in the the drawing as follows

Layer: x68202ebs$0$LEGEND was not renamed.
 Layer: x68202ebs$0$G-HATCH was not renamed.
 Layer: x68202pbs$0$P-TEXT was not renamed.
 Layer: x68202pbs$0$P-DIMS was not renamed.
 Layer: x68202pbs$0$CONCRETE was not renamed.
 Layer: GR634101$0$MP634100$0$A-Wall-Patt was not renamed.
 Layer: GR634101$0$MP634100$0$A-Wall-Comp was not renamed.
 Layer: GR634101$0$MP634100$0$A-Wall-Abov was not renamed.
 Layer: GR634101$0$MP634100$0$A-Wall-Blow was not renamed.
 Text style: x68202ebs$0$bpi60 was not renamed.
 Text style: x68202ebs$0$BPI-STD was not renamed.
 Text style: x68202ebs$0$SIMPLEX was not renamed.
 Text style: x68202ebs$0$BPI-BOLD was not renamed.
 Text style: x68202ebs$0$l100 was not renamed.
 Text style: x68202pbs$0$SIMPLEX was not renamed.
 Text style: x68202pbs$0$BPI-STD was not renamed.
 Text style: x68202pbs$0$x68202pbs$0$SIMPLEX was not renamed.
 Text style: x68202pbs$0$x68202pbs$0$BPI-STD was not renamed.

That means that the layers are already in the drawing, so you would have to use laytrans, or some other way of merging the layers.  Or maybe Michael's will work (I haven't tried it).  If I saw his I might not have made mine.   :-)

I have a program that will merge text styles, and you could use that on the text styles.  Here is the link.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

TJAM51

  • Guest
Re: Asci characters in layer names
« Reply #9 on: February 20, 2008, 01:23:52 PM »
Maybe I am completely lost. I am talking about layer names and not specific text styles. The characters I talk about are contained within the layer name.....I may have missed something here..

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Asci characters in layer names
« Reply #10 on: February 20, 2008, 01:33:18 PM »
Maybe I am completely lost. I am talking about layer names and not specific text styles. The characters I talk about are contained within the layer name.....I may have missed something here..
When you bind an xref, all items within that xref that are dependent on the drawing will be named with the dollar sign.  Both the routines you were pointed to will look through all that was known at the time of creation of said routine to rename all items the proper way; without the dollar signs.  If you look in the header of the routine I pointed you to it tells you what it will try and change.  Here it is incase you missed it.
Quote
; RemoveBindPrefixes
; Renames layers, blocks, dimension styles, text styles, user coordinate systems, and views
;  by taking out the bind as bind prefix
; Example Drawing1$0$Layer1 -> Layer1

If you only care about the layers, then you can change the routines to only look at layers, but right now they will look at more than just the layer collection.

Hope that clears some things up.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

TJAM51

  • Guest
Re: Asci characters in layer names
« Reply #11 on: February 20, 2008, 01:40:25 PM »
I used the MTS routine and received the following:

Error--> Automation Error. Null object ID


I do not know enought to identify but ony a few items within a lisp file.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Asci characters in layer names
« Reply #12 on: February 20, 2008, 01:47:32 PM »
I used the MTS routine and received the following:

Error--> Automation Error. Null object ID


I do not know enought to identify but ony a few items within a lisp file.
Add (vl-bt) in the error function, and run again, and then post what is printed to the command line.  This is what I'm talking about
Code: [Select]
(defun *error* (msg)

(if ActDoc (vla-EndUndoMark ActDoc))
(prompt (strcat "\n Error--> " msg))
[color=red]        (vl-bt)[/color]
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

TJAM51

  • Guest
Re: Asci characters in layer names
« Reply #13 on: February 20, 2008, 01:53:53 PM »
New error message...............

 Error--> Automation Error. Null object IDBacktrace:
[0.59] (VL-BT)
[1.55] (*ERROR* "Automation Error. Null object ID")
[2.50] (_call-err-hook #<SUBR @074892e4 *ERROR*> "Automation Error. Null object
ID")
[3.44] (sys-error "Automation Error. Null object ID")
:ERROR-BREAK.39 nil
[4.36] (intelligent-invoke #<VLA-OBJECT IAcadMText 123805f4> "StyleName" 2)
[5.29] (#<SUBR @10c22d48 vlax-get-property> #<VLA-OBJECT IAcadMText 123805f4>
"StyleName")
[6.24] (vla-get-StyleName #<VLA-OBJECT IAcadMText 123805f4>)
[7.19] (C:MTS)
[8.15] (#<SUBR @07489410 -rts_top->)
[9.12] (#<SUBR @07512334 veval-str-body> "(C:MTS)" T #<FILE internal>)
:CALLBACK-ENTRY.6 (:CALLBACK-ENTRY)
:ARQ-SUBR-CALLBACK.3 (nil 0)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Asci characters in layer names
« Reply #14 on: February 20, 2008, 02:11:21 PM »
I'm not sure why it would do that.  It seems to be erroring on an mtext object, but when I test it I don't get any errors.  Maybe try an audit, and then rerun the code, as I'm not sure why it should error with a Null object ID.  If the audit doesn't fix it, do you think you can post it?  If not could you send it to me?  I want to find out why it is erroring.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.