Author Topic: Rename all Dimstyles  (Read 1361 times)

0 Members and 1 Guest are viewing this topic.

Biscuits

  • Swamp Rat
  • Posts: 502
Rename all Dimstyles
« on: July 15, 2016, 01:49:57 PM »
Using AutoCAD 2015
Using LISP,  I'm looking to rename all dimstyles in a drawing file by adding a suffix.
Anyone have an idea where to start on a routine like this?

Thanks

tedg

  • Swamp Rat
  • Posts: 811
Re: Rename all Dimstyles
« Reply #1 on: July 15, 2016, 02:14:37 PM »
Why don't you just use the "Rename" command, choose Dimstyles.


Rename * to *-YOURSUFFIX


(using wild cards)
Windows 10 Pro 64bit, AutoCAD 2023, REVIT 2023

tedg

  • Swamp Rat
  • Posts: 811
Re: Rename all Dimstyles
« Reply #2 on: July 15, 2016, 02:19:22 PM »
Ok maybe not, I tried my example and it won't work as I thought...
Surely there's a way with rename and wildcards ??


Update,
for some reason you can add a prefix with my example, not a suffix:
Rename * to MYPREFIX-*
« Last Edit: July 15, 2016, 02:22:53 PM by tedg »
Windows 10 Pro 64bit, AutoCAD 2023, REVIT 2023

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Rename all Dimstyles
« Reply #3 on: July 15, 2016, 02:26:38 PM »
Quick & Dirty is all I've time for ...

Code: [Select]
(defun _AddSuffixToTableEntries ( table suffix / pattern table_name old_name new_name )

    (setq
        pattern    (strcase (strcat "*" suffix))
        table_name (substr (vla-get-objectname (vla-item table 0)) 5)
        table_name (substr table_name 1 (- (strlen table_name) (strlen "TableRecord")))
    )

    (vlax-for entry table
        (princ
            (strcat
                "\n" table_name " \""
                (setq old_name (vla-get-name entry)) "\" "
                (if (wcmatch (strcase old_name) pattern)
                    "<no need to rename>"
                    (if
                        (vl-catch-all-error-p
                            (vl-catch-all-apply 'vla-put-name
                               (list entry (setq new_name (strcat old_name suffix)))
                            )
                        )
                        "<cannot rename>"
                        (strcat "renamed to <\"" new_name "\">")
                    )
                )
            )
        )
    )

    (princ)

)
   
Example usage ...

Code: [Select]
(vl-load-com)

(_AddSuffixToTableEntries
    (vla-get-dimstyles (vla-get-activedocument (vlax-get-acad-object)))
    "_WTF"
)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst