Author Topic: Basic Lisp help copying a file to a new folder  (Read 4280 times)

0 Members and 1 Guest are viewing this topic.

BryanHerron

  • Guest
Basic Lisp help copying a file to a new folder
« on: August 08, 2018, 02:54:44 PM »
I am starting to automate our processes and am starting simple. We have a dynamic block that goes in virtually all our drawings. It's a simple prelim-to-final stamp required by client. The master dynamic block stays in the support folder and the normal procedure is to copy the master to the project folder then rename it with the job # as the prefix. So for example XXX-blockname.dwg gets renamed 1084-blockname.dwg. I am attempting to add this function to a toolbar button and derive the project# in some way, possibly from the sheet set, like reading a field. I started with this code I found, just to copy the file, but all I get is a nil return and no file created in the destination folder. Any assistance or better solution would be appreciated.

(vl-file-copy "C:/XXX-BLOCK.dwg" "C:/Project Files/18-1084 EW1090, Bristle Rd, 31177, Calvin D3/CIV3D/1084-BLOCK.dwg")

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Basic Lisp help copying a file to a new folder
« Reply #1 on: August 08, 2018, 03:20:14 PM »
Do you have the correct permissions set for that directory?

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Basic Lisp help copying a file to a new folder
« Reply #2 on: August 08, 2018, 03:26:07 PM »
What does (findfile "C:/XXX-BLOCK.dwg") return for you?

Or one of the following may be applicable - from the dev docs:
Quote
Some typical reasons for returning nil are:
  • source-file is not readable
  • source-file is a directory
  • append? is absent or nil and destination-file exists
  • destination-file cannot be opened for output (that is, it is an illegal file name or a write-protected file)
  • source-file is the same as destination-file

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Basic Lisp help copying a file to a new folder
« Reply #3 on: August 08, 2018, 03:30:04 PM »
Another idea ... without renaming the block and putting it in the directory you could insert your original block in your drawing and rename it to match you project number like so:

Code - Auto/Visual Lisp: [Select]
  1. (defun _rnbd (oldname newname / e)
  2.   (and (setq e (tblobjname "block" oldname))
  3.        (setq e (cdr (assoc 330 (entget e))))
  4.        (entmod (subst (cons 2 newname) (assoc 2 (entget e)) (entget e)))
  5.   )
  6. )
  7. (_rnbd "XXX-BLOCK.dwg" "1084-BLOCK.dwg")

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

BryanHerron

  • Guest
Re: Basic Lisp help copying a file to a new folder
« Reply #4 on: August 08, 2018, 03:47:50 PM »
Permissions not a problem and to answer the second reply, it returned nil and I found the problem, so I now have it copying to the new folder.

BryanHerron

  • Guest
Re: Basic Lisp help copying a file to a new folder
« Reply #5 on: August 08, 2018, 03:54:13 PM »
Another idea ... without renaming the block and putting it in the directory you could insert your original block in your drawing and rename it to match you project number like so:

Code - Auto/Visual Lisp: [Select]
  1. (defun _rnbd (oldname newname / e)
  2.   (and (setq e (tblobjname "block" oldname))
  3.        (setq e (cdr (assoc 330 (entget e))))
  4.        (entmod (subst (cons 2 newname) (assoc 2 (entget e)) (entget e)))
  5.   )
  6. )
  7. (_rnbd "XXX-BLOCK.dwg" "1084-BLOCK.dwg")

Actually, the way we work it is that we xref the block in, so when the plans go from prelim to Right of Way to Final we simply open the xref and change the block and all sheets, often over 100 sheets, are changed.

So now all I'm looking for is a way to derive the project number as part of the "copying to the new folder" if possible. If not just getting it copied vie a button click is a step in the right direction.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Basic Lisp help copying a file to a new folder
« Reply #6 on: August 08, 2018, 04:02:36 PM »
I'd imagine that number is located somewhere in your file right? Post an example drawing.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

efernal

  • Bull Frog
  • Posts: 206
Re: Basic Lisp help copying a file to a new folder
« Reply #7 on: August 08, 2018, 05:56:20 PM »
Code - Auto/Visual Lisp: [Select]
  1. ;;      my suggestion
  2. ;;
  3. (DEFUN my_copy (home in out / dwg folder)
  4.   (IF (SETQ dwg (FINDFILE (STRCAT home in)))
  5.     (IF (SETQ folder (FINDFILE out))
  6.       (IF (NOT (FINDFILE (STRCAT folder in)))
  7.         (PROGN (VL-FILE-COPY dwg (STRCAT folder in))
  8.                (IF (FINDFILE (STRCAT folder in))
  9.                  (ACET-UI-MESSAGE "Success..." "Message title" 48)
  10.                  (ACET-UI-MESSAGE "Error:\n\n\tFile was not copyed..." "Message title" 16)
  11.                )
  12.         )
  13.       )
  14.       (ACET-UI-MESSAGE (STRCAT "No folder\n" folder) "Message title" 16)
  15.     )
  16.     (ACET-UI-MESSAGE (STRCAT home in "\nnot found...") "Message title" 16)
  17.   )
  18.   (PRINC)
  19. )
  20. ;; how to use:
  21. (my_copy "C:/"
  22.          "XXX-BLOCK.dwg"
  23.          "C:/Project Files/18-1084 EW1090, Bristle Rd, 31177, Calvin D3/CIV3D"
  24. )
  25. ;; please, correct english mistakes. Not my first language...
  26.  
e.fernal

efernal

  • Bull Frog
  • Posts: 206
Re: Basic Lisp help copying a file to a new folder
« Reply #8 on: August 08, 2018, 05:57:59 PM »
Code - Auto/Visual Lisp: [Select]
  1. ;;correction:
  2.  
  3. (VL-FILE-COPY dwg (STRCAT folder "/" in))
  4.  
e.fernal

BryanHerron

  • Guest
Re: Basic Lisp help copying a file to a new folder
« Reply #9 on: August 08, 2018, 06:27:06 PM »
I'd imagine that number is located somewhere in your file right? Post an example drawing.

Typically these CAD files are prefixed with the 4 digit job#. I can't speak for the consistency of the job# placement in the folder structure.

BryanHerron

  • Guest
Re: Basic Lisp help copying a file to a new folder
« Reply #10 on: August 08, 2018, 06:28:52 PM »
Efernal, I should get a chance to test your code in the morning.

Thank you guys a bunch

BryanHerron

  • Guest
Re: Basic Lisp help copying a file to a new folder
« Reply #11 on: August 08, 2018, 06:43:14 PM »
UPDATE SUMMARY

Found a typo - fixed issue #1. So now I can copy the file from the support path into the project folder BUT to do so I have to type in the path and the project#. The goal is to derive the project folder and the project #. Is therE some way to make this macro button read the sheet set manager like calling a field to derive the project folder and #?

efernal

  • Bull Frog
  • Posts: 206
Re: Basic Lisp help copying a file to a new folder
« Reply #12 on: August 09, 2018, 09:54:51 AM »
Code - Auto/Visual Lisp: [Select]
  1. you can list the folders and show them in a dialog
  2. see how:
  3.  
  4. (setq folders (vl-directory-files "C:\\" "*" -1))
  5. ("$AV_ASW" "$Recycle.Bin" "AeroCAD" "Arquivos de Programas" "Autodesk" "Cadastro" "CADian" "Cadian-Saep"
  6.   "Camtasia Studio 6" "Curso" "Documents and Settings" "E-Rural" "E-Rural-Pd" "EFernal_Dlls"
  7.   "Ef_Quant" "GetData" "Gr-Acad-2017" "Gr-Acad-BS" "Gr-Acad-C" "Gr-Acad_Loel" "Gr-Arqui-2017" "Gr-Pack-Usb"
  8.   "Gr12000" "Gr12000-Bck" "Hidra-2017" "Hidra2000" "Hidra2015" "Hidra2018" "Hidra_C" "lexmark" "Lixo"
  9.   "Memorial-2018" "MSOCache" "PerfLogs" "PowerLines" "Prec Tech Repositório" "Prec_Tech_Cadian"
  10.   "Program Files" "Program Files (x86)" "ProgramData" "Projetos VBasic 6" "PsPad" "Recovery" "RModel"
  11.   "SimCads" "System Volume Information" "Users" "ViaCabos-Cad" "Windows")
  12.  
  13. (setq folders (vl-directory-files "C:\\" "cad*" -1))
  14. ("Cadastro" "CADian" "Cadian-Saep")
  15. (setq folders (vl-directory-files "C:\\" "B*" -1))
  16. nil
  17. (setq folders (vl-directory-files "C:\\" "C*" -1))
  18. ("Cadastro" "CADian" "Cadian-Saep" "Camtasia Studio 6" "Curso")
  19. (setq folders (vl-directory-files "C:\\" "D*" -1))
  20. ("Documents and Settings")
  21. (setq folders (vl-directory-files "C:\\" "F*" -1))
  22. nil
  23. (setq folders (vl-directory-files "C:\\" "G*" -1))
  24. ("GetData" "Gr-Acad-2017" "Gr-Acad-BS" "Gr-Acad-C" "Gr-Acad_Loel" "Gr-Arqui-2017"
  25.  "Gr-Pack-Usb" "Gr12000" "Gr12000-Bck")
  26.  
e.fernal

BryanHerron

  • Guest
Re: Basic Lisp help copying a file to a new folder
« Reply #13 on: August 09, 2018, 11:44:32 AM »
Well, that's beyond my understanding. hehe

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Basic Lisp help copying a file to a new folder
« Reply #14 on: August 09, 2018, 12:33:10 PM »
I'd imagine that number is located somewhere in your file right? Post an example drawing.

Typically these CAD files are prefixed with the 4 digit job#. I can't speak for the consistency of the job# placement in the folder structure.
This will grab the first 4 digits of your drawing name: (substr (getvar 'dwgname) 1 4)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC