Jump to content

Recommended Posts

Posted (edited)

Hello, guys!

I need a lisp to rename the current open file. I already have a routine that takes the current file name and creates a string with the new file name (Just six numbers in the old name needs to change)... But I coudn't change the old name for the new name. I've tried to use the (Vl-File-Rename), but I think that i didn't use it right.... Here's go the code:

 

(defun C:changename (n1 n2 n3 n4 n5 n6)

 

(setq new_number (strcat (itoa n1)

(itoa n2)

(itoa n3)

(itoa n4)

(itoa n5)

(itoa n6)))

 

(setq old_name (strcat (getvar "DWGPREFIX") (getvar "DWGNAME")))

 

(setq size (strlen old_name))

 

(setq final (- size 18 )) ;

 

(setq start_name (substr old_name 1 final ))

 

(setq end_name (substr old_name (+ final 7) (- size final)))

 

(setq new_name (strcat start_name new_number end_name))

 

(alert old_name)

 

(alert new_name)

 

(vl-file-rename old_name new_name)

 

); end defun

 

 

The old name is: D:\Profiles\s-Andre.Almeida\Desktop\Autocad\3-157941-012-005.dwg

 

The new name, for example, could be: D:\Profiles\s-Andre.Almeida\Desktop\Autocad\3-666666-012-005.dwg

 

I just need to change the names with the (vl-file-rename)

 

could someone help me?

Edited by andr3flaviano
Posted

I doubt you can rename a file while it is open. Why not choose instead to do a "saveas" under a new file name?

Posted

Here :

 

(setq end_name (substr old_name (+ final 7) (- size final)))

 

 

(- size final) is sufficient... You could just use :

 

(setq end_name (substr old_name (+ final 7)))

Posted

Hmmmmm...

I thought that i could rename the opened file, but i will use the "Save as" so... Thank you, guys!

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