request 2 lisp to rename layout with csv

request 2 lisp to rename layout with csv

jtm2020hyo
Collaborator Collaborator
2,888 Views
11 Replies
Message 1 of 12

request 2 lisp to rename layout with csv

jtm2020hyo
Collaborator
Collaborator

request for one lisp to export layout names to .csv, edit .csv, then import that .csv to rename layouts with another lisp.

0 Likes
Accepted solutions (2)
2,889 Views
11 Replies
Replies (11)
Message 2 of 12

hak_vz
Advisor
Advisor
Accepted solution

@jtm2020hyo wrote:

request for one lisp to export layout names to .csv, edit .csv, then import that .csv to rename layouts with another lisp.


Instead of csv I'll use txt file. Here you got two functions.

Function LAY_TO_TXT writes out all layouts to txt file you chose and at the end open that txt file to notepad

After you finish renaming layouts save it and close,

Start command LAY_FROM_TXT to apply those changes you have made.

 

Warning: Retain layer sequence, don't delete any name, and leave MODEL where it is.

Text file will remain in directory you have created it, but you can use it to rewrite, and apply changes in some other document.  First all layer names out to file, then apply changes.

 

(defun c:lay_to_txt ( / app doc layouts f file name *error*)
;write layout names to csw
(defun *error* () (close file) (princ))
(vl-load-com)
(setq 
    app (vlax-get-acad-object)
    doc (vla-get-activedocument app)
    layouts (vla-get-layouts doc)
    f (getfiled "Open File to write layout names" (getvar "dwgprefix") "txt" 3)
    file (open f "w")
    
)
 (vlax-for lay layouts(write-line (vla-get-name lay) file))
 (close file)
 (startapp "notepad" f)
 (princ)
)

(defun c:lay_from_txt ( / app doc layouts f file old_name new_name *error*)
(defun *error* () (close file) (princ))

;write layout names to csw
(vl-load-com)
(setq 
    app (vlax-get-acad-object)
    doc (vla-get-activedocument app)
    layouts (vla-get-layouts doc)
    f (getfiled "Open File to read new layout names" (getvar "dwgprefix") "txt" 2)
    file (open f "r")
    
)
(vlax-for lay layouts
   (setq 
        old_name (vla-get-name lay)
        new_name (read-line file)
   )
   (if (not (eq "MODEL" (strcase old_name)))
     (vla-put-name lay new_name)
   )
 ) 
 (close file)
 (princ)
)

 Usage:

lay_to_text 
Layout1
Layout2
Model

Rename layouts

New layout name 1
New layout name 2
Model

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 3 of 12

jtm2020hyo
Collaborator
Collaborator

nice code.
you are the best.
thanks for your help.

0 Likes
Message 4 of 12

pvpatel
Enthusiast
Enthusiast

Is there a way to use this lisp code for multiple files in a folder? Perhaps a dialog box allows you to select the files that require renaming.

 

Thanks!

Pravin

0 Likes
Message 5 of 12

devitg
Advisor
Advisor

Hi@pvpatel , do you mean to make a 1 CSV from each dwg . or a only one CSV with all dwgs . 

Or please specify what you want to do .

If possible , upload a few dwg samples, to try to do it. 

 

Best regards

 

 

0 Likes
Message 6 of 12

pvpatel
Enthusiast
Enthusiast

Hi @devitg One csv with all the dwg layout names.

All drawings in our AutoCAD Electrical Project come with one layout that has a certain layout name. However we are required to change the layout names on each drawing when the drawings are ready for final transmittal. It would be beneficial if we were able to run a lisp routine that would pick all or user has the ability to select certain drawings from a folder to export the layout names to a csv file. The user then modifies the layout names in the csv folder and imports them back to the drawings.

 

Thanks!

0 Likes
Message 7 of 12

devitg
Advisor
Advisor

Hi @pvpatel , if no sample dwg , I can  elaborate  nothing.  

0 Likes
Message 8 of 12

Sea-Haven
Mentor
Mentor

You could write a script from excel that simply opens a dwg, layout,rename, oldname, newname, close and go to next dwg.

 

Yes would need a create csv file 1st from say a lisp. Selecting files using findfile has been around for a long time a google should find what you want.

 

 excel column using concatenate, copy to notepad and save as a script .scr file Blank last line for last close

 

open d:\acadtemp\drawing1.dwg layout rename layout2 layoutyy close N 

open d:\acadtemp\drawing2.dwg layout rename layout1 layoutxx close N 

Message 9 of 12

jtm2020hyo
Collaborator
Collaborator

I think that @pvpatel is trying to say that he wants a DCL and LSP. this for select multiple drawings, then use batch export each drawing with their layouts names with the format that your propose (d:\acadtemp\drawing2.dwg layout1 layout-renamed) and then use a batch re-import.

 

... this is everything that one electric design needs. the electric designer's world will be grateful for those who create this hypothetical dcl+lsp.

 

here an example:

 

dcl+lsp start selecting next files with a GUI:

 

d:\acadtemp\drawing2.dwg 
d:\acadtemp\drawing1.dwg 

 

 

 

then import to any file as txt or CSV with layout names:

 

d:\acadtemp\drawing2.dwg layout1 
d:\acadtemp\drawing2.dwg layout2

d:\acadtemp\drawing1.dwg layoutx1
d:\acadtemp\drawing1.dwg layoutx2

 

 

rename to:

 

 

path                     original name          renamed layout  
d:\acadtemp\drawing2.dwg   layout1               l1-renamed1 
d:\acadtemp\drawing2.dwg   layout2               l2-renamed2

d:\acadtemp\drawing1.dwg   layoutx1              lx1-renamed3
d:\acadtemp\drawing1.dwg   layoutx2              lx2-renamed4

 

 

then use the option to batch rename layouts in the selected drawings.

 

 

 

 

Message 10 of 12

devitg
Advisor
Advisor
Accepted solution

@jtm2020hyo , check for  LM:getfiles   here  

Message 11 of 12

pvpatel
Enthusiast
Enthusiast

Sorry for the late response. I am going to send you two files that have no content (complying with our current company policy not to share files externally) but have layouts in them. Drawingtest1 has a layout called TEST-01-01 and Drawingtest2 has a layout name called TEST-02-02. The ultimate goal is to have the layouts of these two files renamed to for example TEST-01 and TEST-02.

I have read the thread below and it looks like @jtm2020hyo is on the right track but I am not sure what do to next after downloading GetFilesV1-6.lsp.

I am not good at programming at all so please bear with me.

0 Likes
Message 12 of 12

pbejse
Mentor
Mentor

@pvpatel wrote:

....I am not good at programming at all so please bear with me.


Yup, I see it too. 

 

pvpatel.png

 

0 Likes