Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LISP Routine to rename multiple drawings while publishing

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
daniel.orourkeUWE7W
642 Views, 12 Replies

LISP Routine to rename multiple drawings while publishing

I'm looking for a LISP Routine that I could run that will do the following:

 

1. Run the publish command

2. Allow me to select drawings to publish

3. Rename all to something I type in (i.e. a job number shared by each file)

4. Keep the Layout tab as a suffix (like normal)

 

The end result would be publishing multiple sheets with the same prefix followed by the sheet number which is matched by the layout tab:

 

21.0005.00 - E0.01

21.0005.00 - E1.01

21.0005.00 - E1.02

etc.

 

My company has been doing this manually for some time now, and I am very new to figuring out the coding language.  Does anyone know if this can be done?

12 REPLIES 12
Message 2 of 13

@daniel.orourkeUWE7W 

You could install MS Powertoys and use Power Rename for this.

ronjonp_0-1649367506261.png

 

You can also add a prefix to multiple files like so without installing anything:

ronjonp_0-1649367702955.png

 

Message 3 of 13

From what I understand, this bulk renaming feature will only work to remove or add similar text across several files, is that correct?

 

I need something that can take this list:

 

21.0005.00 - E0.01 - E0.01

21.0005.00 - E1.01 - E1.01

21.0005.00 - E2.01A-B - E2.01A

21.0005.00 - E2.01A-B - E2.01B

21.0005.00 - E2.02 - E2.02

 

Into this list:

 

21.0005.00 - E0.01

21.0005.00 - E1.01

21.0005.00 - E2.01A

21.0005.00 - E2.01B

21.0005.00 - E2.02

 

It wouldn't be an issue, but sometimes the list is 100 files long lol.

Message 4 of 13

@daniel.orourkeUWE7W 

Give this a try. It will rename a directory of PDF's that match a file pattern of "* - *.pdf"

 

(defun c:foo (/ dir fls n p pf str)
  ;; RJP » 2022-04-07
  (cond	((and (setq p (getvar 'dwgprefix))
	      (setq dir (getfiled "\nPick a folder to process..." p "pdf" 16))
	      (setq fls (vl-directory-files (setq dir (vl-filename-directory dir)) "*-*.pdf" 1))
	      (/= "" (setq pf (getstring "\nEnter prefix: " t)))
	 )
	 (foreach f fls
	   (setq n (substr f (vl-string-position (ascii "-") f 0 t)))
	   (or (vl-file-rename (strcat dir "\\" f) (strcat dir "\\" (strcat pf (+ 2 n))))
	       (princ (strcat "\nERROR RENAMING: " f))
	   )
	 )
	)
  )
  (princ)
)

 

 

Not a ton of error checking so test it out!

Message 5 of 13


@daniel.orourkeUWE7W wrote:

1. Run the publish command

2. Allow me to select drawings to publish

3. Rename all to something I type in (i.e. a job number shared by each file)

4. Keep the Layout tab as a suffix (like normal)

What you're saying is by skipping item # 3 the result is just a pdf with the layout names YES?

E0.01

E1.01

E1.02

..

 

You can piggy-back a lisp with publish, however it may require a bit of setup on your end.

As an alternative, You can run a program to rename the resulting pdfs from publish similar to @ronjonp contribution and as originally suggested.

 

(defun c:AddprefixToPDF ( /  prefix  path pdfs)
  (if (and
	(setq prefix (getstring "\nEnter prefix: "))
	(setq path (strcat (acet-ui-pickdir "Select Folder" (getvar 'dwgprefix))))
	(setq pdfs (vl-directory-files path "*.pdf" 1))
	(setq path (strcat path "\\"))
	)
    (foreach itm pdfs
      (cond
	((vl-string-search  prefix itm)		);<-- to avoid accidentally doubling up
	((vl-file-rename  (strcat path  itm)
	   	(strcat path prefix " - " itm))
	   )
	 )
      )      
    )
  (princ)  
  )

 

I'm pretty sure you are aware of the  options in  publish command 

 

pbejse_0-1649401746239.png

 

Otherwise use @ronjonp code to "correct" the existing pdfs.

 

 

HTH

 

 

Message 6 of 13


@daniel.orourkeUWE7W wrote:

From what I understand, this bulk renaming feature will only work to remove or add similar text across several files, is that correct?

 

I need something that can take this list:

 

21.0005.00 - E0.01 - E0.01

21.0005.00 - E1.01 - E1.01

21.0005.00 - E2.01A-B - E2.01A

21.0005.00 - E2.01A-B - E2.01B

21.0005.00 - E2.02 - E2.02

 

Into this list:

 

21.0005.00 - E0.01

21.0005.00 - E1.01

21.0005.00 - E2.01A

21.0005.00 - E2.01B

21.0005.00 - E2.02

 

It wouldn't be an issue, but sometimes the list is 100 files long lol.


 

Easy peasy.

Total/Windows Commander HERE. Total must-have.

 

BeekeeCZ_1-1649403793444.png

 

 

Message 7 of 13

This program looks like it does exactly what I am looking for, but it seems to only be a month trial version that later requires a paid license to use.  I'd like to avoid additional subscriptions if at all possible.  Thanks for the suggestion, though!

Message 8 of 13

This comes incredibly close to what I'm looking for!  Here are my results from running the script:

 

Original Files:

Pre-FOO.png

 

Renamed Files:

Post-FOO.png

 

As you can see, an extra character is being generated at the end of the job number.

For this example, I need the list to read as shown here:

 

danielorourkeUWE7W_0-1649420160845.png

 

Message 9 of 13

My friend, you have done it!  Thank you so much!  I did not notice the check box earlier to not use the sheet title with file name.  After simply unchecking that box, I can just enter the job number with your script.  Perfect!

Message 10 of 13

No subscription, just a 27 euro lifetime license.

Even if you exceed the monthly trial, the program continues to work without further restrictions. 

Just try it and you'll see. 

The productivity of working with multiple files cannot be compared with MS Explorer.

Message 11 of 13


@daniel.orourkeUWE7W wrote:

This comes incredibly close to what I'm looking for!  Here are my results from running the script:

 

Original Files:

Pre-FOO.png

 

Renamed Files:

Post-FOO.png

 

As you can see, an extra character is being generated at the end of the job number.

For this example, I need the list to read as shown here:

 

danielorourkeUWE7W_0-1649420160845.png

 


Try my code above again. All I changed was:

 

;; This
(strcat pf n)
;; to this
(strcat pf (+ 2 n))

;; Test example
(SETQ STR "22.0001.00 - E0.1-E0.1.pdf")
(strcat "22.0001.000 - " (substr STR (+ 2 (vl-string-position (ascii "-") STR 0 t))))
;; "22.0001.000 - E0.1.pdf" 

 

Message 12 of 13
ronjonp
in reply to: pbejse

@pbejse 

If you use the method below you don't need to check for an existing prefix as it will always strip everything before the last "-" 😎

(setq n (substr f (vl-string-position (ascii "-") f 0 t)))
Message 13 of 13

It is much easier and more convenient to type and immediately get the desired file name than to rename it later.

Is not it ?

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report