Author Topic: Moving and copying a file  (Read 6074 times)

0 Members and 1 Guest are viewing this topic.

hudster

  • Gator
  • Posts: 2848
Moving and copying a file
« on: September 21, 2005, 06:05:47 AM »
I need to write a lisp that allows me to do two things.

1. When asking it to modify a drawing, ask for the new revision, save the open drawing to a new directory with the new revison replacing the old revision, as a suffix to the filename, update the titleblock, then delete the old version from the working folder.

2. When asking it to issue the drawing, extract the revision from the title block attributes, create a folder with that revision, save a copy of the drawing to the issued folder, and also save a copy back into the working folder, before deleting the version in the mods folder.

I can get it to copy the drawing and change the filename, but how can I delete the old files?
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Moving and copying a file
« Reply #1 on: September 21, 2005, 06:11:44 AM »
Have a look at (vl-file-delete filename)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Moving and copying a file
« Reply #2 on: September 21, 2005, 06:18:52 AM »
.. though, you may be able to kill 2 birds with (vl-file-rename ....
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

hudster

  • Gator
  • Posts: 2848
Re: Moving and copying a file
« Reply #3 on: September 21, 2005, 06:22:19 AM »
I think I'll go with vl-file-rename, seems to what I need it to without the danger of deleting files.

Cheers
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

hudster

  • Gator
  • Posts: 2848
Re: Moving and copying a file
« Reply #4 on: September 21, 2005, 07:23:46 AM »
hit a problem, I can't rename the file when i'm in it.

So how can I close the current drawing file and open the new one using lisp?
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Moving and copying a file
« Reply #5 on: September 21, 2005, 08:03:30 AM »
Save,
Save,as
Rename the saved,

perhaps
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Amsterdammed

  • Guest
Re: Moving and copying a file
« Reply #6 on: September 21, 2005, 08:06:01 AM »
You might write a scritpfile with lisp first and than execute it with lisp.

Bernd

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Moving and copying a file
« Reply #7 on: September 21, 2005, 08:23:46 AM »
You might write a scritpfile with lisp first and than execute it with lisp.

Bernd

A man after my own heart.

:-)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

hudster

  • Gator
  • Posts: 2848
Re: Moving and copying a file
« Reply #8 on: September 21, 2005, 08:53:45 AM »
You might write a scritpfile with lisp first and than execute it with lisp.

Can you give me an example as I can't figure out how this woudl be done?
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

hudster

  • Gator
  • Posts: 2848
Re: Moving and copying a file
« Reply #9 on: September 21, 2005, 10:34:26 AM »
Here is what I have so far, I can make the folder, copy the file, make the script file.

But it won't open the new drawing.  Any ideas?

Code: [Select]
(defun c:mod ()
  ;;Check if mods folder exists, if not create mods folder
  (if (not (member "mods" (vl-directory-files (getvar "dwgprefix") nil -1)))
(vl-mkdir (strcat (getvar "dwgprefix") "Mods")))
  ;;Get old dwg filename & directory name
  (setq oldfname (getvar "dwgname")
olddirname (getvar "dwgprefix"))
  (setq origfile (strcat olddirname oldfname))
  ;;check if new file exists, if not create a new filename
  (setq newfile (strcat (getvar "dwgprefix") "Mods\\" (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 4)) ".dwg"))
(if (findfile newfile)
(alert (strcat "File " newfile  " already exists In Mods Folder! "))
(progn
(princ (strcat "\nSaving: " Newfile "\n"))
(command "._save" newfile)
);progn
);if
  ;;Make a script file to close original file and open the new one
  ;;create file name
  (setq modtxt (strcat (getvar "dwgprefix") "Mods\\" (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 4)) ".scr"))
  ;;;write the file
  (setq txtfile (open modtxt "w"))
  (write-line "close" txtfile)
  ;;(write-line origfile txtfile)
  (write-line "n" txtfile)
  (write-line "open"  txtfile)
  (write-line newfile  txtfile)
  (write-line ";" txtfile)
  (close txtfile)
  ;;run the scriptfile
  (command "script" modtxt)
(princ)
);defun

***edit***

I think the problem lies with this piece of code   (write-line newfile  txtfile), I need to enclose newfile in quotation marks, but if I do, it adds newfile to the text file rather than the value it represents, any ideas on how to get this in quotation marks?
« Last Edit: September 21, 2005, 11:06:12 AM by Hudster »
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Moving and copying a file
« Reply #10 on: September 23, 2005, 04:22:30 PM »
I need to write a lisp that allows me to do two things.
 :?


1) ask for the new revision,
2) save the open drawing to a
3)new directory with the new revison
4)replacing the old revision, as a suffix to the filename,
5)update the titleblock,
6)then delete the old version from the working folder.

Keep smile...

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Moving and copying a file
« Reply #11 on: September 23, 2005, 04:41:23 PM »
If you start now you should be done by supper.

:)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Moving and copying a file
« Reply #12 on: September 26, 2005, 02:41:27 PM »
Hudster,
Could you do a 'Save As' to the new file name in the new directory?
Then rename to old file in the old directory?
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

hendie

  • Guest
Re: Moving and copying a file
« Reply #13 on: September 28, 2005, 07:24:14 AM »
dunno if this will help or not but this may give you some ideas or at least something to work with

hudster

  • Gator
  • Posts: 2848
Re: Moving and copying a file
« Reply #14 on: September 28, 2005, 07:52:39 AM »
I came up with this, it aint too pretty but it gets the job done.

Code: [Select]
;;;
;;; TITLE:moddwg.lsp
;;;
;;; Copyright (C) 2005 by Andy Hudson
;;;
;;; Permission to use, copy, modify, and distribute this
;;; software and its documentation for any purpose and without
;;; fee is hereby granted
;;;
;;; THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR
;;; IMPLIED WARRANTY. ALL IMPLIED WARRANTIES OF FITNESS FOR ANY
;;; PARTICULAR PURPOSE AND OF MERCHANTABILITY ARE HEREBY
;;; DISCLAIMED.
;;;
;;; Andy Hudson
;;; April 2005
;;;
;;;-------------------------------------------------------------
;;; Description:
;;;
;;; Routine to make modifying a drawing comply with company
;;; Standards the routine Moves the file to a Mods folder to
;;; ensure only current drawings remain in the current folder
;;;
;;;
;;;-------------------------------------------------------------
;;; COMMAND
;;; moddwg
;;;-------------------------------------------------------------
;;;
;;error checker from www.afralisp.com
;;;
(LOAD "x:/aids/blocks/blocks/lisps/ERROR.LSP")
;;
(defun c:moddwg (/ oldname olddir oldrev newrev newname newdir origfile combined)
 ;;change filename to show new revision
  (setq oldname (getvar "dwgname")
olddir (getvar "dwgprefix")
oldrev (getstring "\nEnter current revision: ")
newrev (Getstring "\nEnter New Revision: ")
newname (vl-string-subst newrev oldrev oldname)
newdir (strcat olddir "Mods\\")
origfile (STRCAT olddir oldname))
  ;;;COMBINE INFORMATION
  (SETQ combined (STRCAT newdir newname))
  ;;MAKE MODS FOLDER
  (if (not (member "Mods" (vl-directory-files (getvar "dwgprefix") nil -1)))
    (vl-mkdir (strcat (getvar "dwgprefix") "Mods")))
  ;;check if file exists
  (if (findfile combined)
    (alert (strcat "File " combined  " already exists In Mods Folder! "))
    (progn);progn
    );if
  ;;SAVE DRAWING
  (COMMAND "_.SAVEAS" "" combined)
  ;;DELETE THE OLD FILE
  (VL-FILE-DELETE ORIGFILE)
  (princ)
  )
(prompt "\nModify Drawing Lisp Loaded, enter moddwg to run.")
(princ)
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

hudster

  • Gator
  • Posts: 2848
Re: Moving and copying a file
« Reply #15 on: September 28, 2005, 07:58:51 AM »
I came up with this one for when a modified drawing is issued.

Code: [Select]
;;;
;;; TITLE:issdwg.lsp
;;;
;;; Copyright (C) 2005 by Andy Hudson
;;;
;;; Permission to use, copy, modify, and distribute this
;;; software and its documentation for any purpose and without
;;; fee is hereby granted
;;;
;;; THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR
;;; IMPLIED WARRANTY. ALL IMPLIED WARRANTIES OF FITNESS FOR ANY
;;; PARTICULAR PURPOSE AND OF MERCHANTABILITY ARE HEREBY
;;; DISCLAIMED.
;;;
;;; Andy Hudson
;;; April 2005
;;;
;;;-------------------------------------------------------------
;;; Description:
;;;
;;; Routine to make Issuing a drawing comply with company Standards
;;; The routine Moves the file to the current folder to ensure only
;;; current drawings remain in the current folder, with a copy
;;; made and bound in the issued folder.
;;;
;;;-------------------------------------------------------------
;;; COMMAND
;;; issdwg
;;;-------------------------------------------------------------
;;;
;;error checker from www.afralisp.com
;;;
(LOAD "x:/aids/blocks/rybka_blocks/lisps/ERROR.LSP")
;;
(DEFUN C:issdwg (/ dirname newdirname filename origfile oldfiledia newfile issname issdir issfile)
  ;;GET DIRECTORY INFORMATION
  (SETQ dirname (GETVAR "DWGPREFIX")
newdirname (VL-STRING-TRIM "\\Mods" dirname)
filename (getvar "dwgname")
origfile (strcat dirname filename))
  ;;save the drawing
  (setq oldfiledia (getvar "filedia"))
  (setvar "filedia" 0)
  (setq newfile (strcat newdirname "\\" filename))
(if (findfile newfile)
(alert (strcat "File " newfile  " already exists In Folder! "))
(progn
(princ (strcat "\nSaving: " Newfile "\n" ))
  (command "._saveas" "" newfile)
);progn
);if
  (setvar "filedia" oldfiledia)
  ;;Save to issued folder
  ;;Create Directory & File Information
  (setq issname (vl-string-trim "current" newdirname))
  ;;create Issued folder
  (setq issdir (strcat issname "Issued"))
  (vl-mkdir issdir)
  ;;create issue file
  (Setq issdir (vl-string-subst "Issued" "current\\Mods" dirname))
  (setq issfile (strcat issdir filename))
  ;;save the file
  (command "._saveas" "" issfile)
  (command "-xref" "bind" "*")
  (command "-purge" "all" "*" "n")
  (command "-purge" "all" "*" "n")
  (command "-purge" "all" "*" "n")
  (command "-purge" "all" "*" "n")
  (command "-purge" "all" "*" "n")
  (command "qsave")
  ;;delete the old file
  (vl-file-delete origfile)
  (princ)
  )
  (PROMPT "\n Issue Drawing Lisp loaded, enter issdwg to run.")
  (princ)
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue