Author Topic: Save As to a diferent folder? - VBA or Lisp???  (Read 8607 times)

0 Members and 1 Guest are viewing this topic.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Save As to a diferent folder? - VBA or Lisp???
« on: April 05, 2006, 12:19:59 PM »
Here I go.  I am jumping UP (very blindly might I add) to the next level of my programming, visual lisp.  But first I have two questions.

One; I can not find a VL function to change folders.  I assume there is on somewhere but I be dam if I can find either in the Swamp, ACAD’s help (which frustrates the hell out of my by the way) and Afrialisp.com.  Is there such a function?  How do I strip on level of the path?

Two, after reviewing some VBA threads in Swamp, it got me to thinking that maybe VBA is the way to go. 

Unfortunately, I have very little programming experience with VLisp and none with VBA.  I could use help in pointing me in the best direction.

Here is what I want to do.
We are constantly sending progress files to our engineering consultants as the project develops.  I have a simple auto lisp that basically in a nutshell performs a save as and prefixes the file name with current date.  It works great except for one inconvenience.  It dumps the new files in the same folder as the orginal file.  I need it to dump in another folder that is adjacent to the drawings folder.  I currently manual move the new file using Windows Explorer.  I would like to kick my simple routine up a notch by having it do this for me.

All these folders are in a root directory of the project folder and of course that changes with each project.  Sample directory tree as follows.
Code: [Select]
M:\2006 Design Projects\project-abc\Drawings\**.dwgs
M:\2006 Design Projects\ project-abc\Transfer – Outgoing\ “currentdate_name.dwg”

This is were I would need VL function jump up and over into the transfer folder.

I would like to this routine to be even more useful by allowing the user to input the name of a sub-folder with the consultant’s name as follows

Code: [Select]
M:\2006 Design Projects\ project\Transfer – Outgoing\XYZ-mep\“currentdate_name.dwg”
M:\2006 Design Projects\ project\Transfer – Outgoing\acme-structural\“currentdate_name.dwg”

I would like kick thing up another notch.  I want the routine to remember consultant’s names because we typical use the same consultants 90% of the time.  However I would need an “input other” consultant for example when we have an out of state project.  So therefore (correct me if I am wrong) I will need a dialogue box and list file that can be updated in the future as new consultants come on board. 

So do I attack this with VBA that I know nothing about?  Or do I use visual lisp that never really had a call to us before now?  Oh by the way I know nothing about DCL files either though i am reading up on.  My routine already saves a bunch of time and I would like to save even more.  I know I am bitting off more that I can chew but what the hell, I have gotten this far without knowing anything.  But any improvement would be great.

Any ideals?
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

joseguia

  • Guest
Re: Save As to a diferent folder? - VBA or Lisp???
« Reply #1 on: April 05, 2006, 12:57:13 PM »
I got exactly what you need done up in VBA.

but if you dont know VBA it can be tough to customize it to get it to do what you want.

you want it?

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: Save As to a diferent folder? - VBA or Lisp???
« Reply #2 on: April 05, 2006, 01:17:56 PM »
For the first part, changing directories try something like this.

Code: [Select]
;; use the dwgprefix to get the current path of the working dwg
(setq path (getvar "dwgprefix"))

;; might return this
;; "M:\\2006 Design Projects\\project-abc\\Drawings\\"

;; now substitute 'Drawings' with 'Transfer - Outgoing'
(vl-string-subst "\\Transfer - Outgoing\\" "\\Drawings\\" path)

;; might return this
;; "M:\\2006 Design Projects\\project-abc\\Transfer - Outgoing\\"

TheSwamp.org  (serving the CAD community since 2003)

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Save As to a diferent folder? - VBA or Lisp???
« Reply #3 on: April 05, 2006, 01:38:32 PM »
Adding to what Mark suggested, there is an undocumeted lisp function to create a directory:
(vl-mkdir "fullpathofdirectory2create")
You can use it to create the folder without worrying about checking if it is already there, as the function just returns T if it gets created or nil if it isn't.


LE

  • Guest
Re: Save As to a diferent folder? - VBA or Lisp???
« Reply #4 on: April 05, 2006, 01:50:36 PM »
it is now, at least here in the vlisp help of 2005


I just checked, it is also available on autocad 2004.... my goodness
« Last Edit: April 05, 2006, 01:55:07 PM by LE »

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Save As to a diferent folder? - VBA or Lisp???
« Reply #5 on: April 05, 2006, 02:23:03 PM »
OK, let me rephrase that.....there is a previously undocumented function.....  :-P But it's counterpart, (vl-rmdir) to remove a directory, is still undocumented....at least in the R2006 files I have.  :roll:

LE

  • Guest
Re: Save As to a diferent folder? - VBA or Lisp???
« Reply #6 on: April 05, 2006, 02:35:17 PM »
OK, let me rephrase that.....there is a previously undocumented function.....  :-P But it's counterpart, (vl-rmdir) to remove a directory, is still undocumented....at least in the R2006 files I have.  :roll:

he he.... I was just mentioned about that... being in the help... it can only be found if you do a search... I just found it... the vl-rmdir... never heard of that before... and it is not available here in my acad 2005

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Save As to a diferent folder? - VBA or Lisp???
« Reply #7 on: April 05, 2006, 02:43:33 PM »
Sure it is Luis......I've been using it in R2002 for some time and it still works in 2006. But it is not documented, nor does it even highlight as an available function in the VLIDE....but observe:
Code: [Select]
_$ (findfile "c:\\temp\\test")
(vl-mkdir "c:\\temp\\test")
(findfile "c:\\temp\\test")
(vl-rmdir "c:\\temp\\test")
(findfile "c:\\temp\\test")
nil
T
"C:\\temp\\test"
0
nil
_$

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Save As to a diferent folder? - VBA or Lisp???
« Reply #8 on: April 05, 2006, 02:52:21 PM »
In ACAD2000 vl-mkdir shows up as a good command but not in the help.
vl-rmdir is not recognized as a command

Code: [Select]
_$ (findfile "c:\\temp\\test")
(vl-mkdir "c:\\temp\\test")
(findfile "c:\\temp\\test")
(vl-rmdir "c:\\temp\\test")
(findfile "c:\\temp\\test")
nil
T
"C:\\temp\\test"
; error: no function definition: VL-RMDIR
_1$
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.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Save As to a diferent folder? - VBA or Lisp???
« Reply #9 on: April 05, 2006, 02:56:38 PM »
Doesn't work in A2k4 either.
Quote from:  Acad command line
Command: (vl-mkdir "c:/temp/test")
T

Command: (vl-rmdir "c:/temp/test")
; error: no function definition: VL-RMDIR

Command: (findfile "c:/temp/test")
"C:\\temp\\test"

Command: (vl-rmdir "c:/temp/test")
; error: no function definition: VL-RMDIR
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Save As to a diferent folder? - VBA or Lisp???
« Reply #10 on: April 05, 2006, 03:02:31 PM »
OK, OK.........egads my memory is going down the toilet......
<*looks around to see if anyone is looking*>
<*tries to slip the following into everyone's startup lisp*>
Code: [Select]
;;remove directory...will remove whether it contains files or not
(defun vl-rmdir (path / fso)
  (setq fso (vla-getinterfaceobject (vlax-get-acad-object) "Scripting.FileSystemObject"))
  (vlax-invoke fso 'deletefolder path 0)
  (vlax-release-object fso)
  )
* Jeff_M realizes, much too late, that this was a function I put together since Vlisp didn't include it......

* Jeff_M goes back to his sandbox whiistling like nuthin' ever happened

Oh, and I apologize for the minor thread hijacking.....
« Last Edit: April 05, 2006, 03:12:53 PM by Jeff_M »

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Save As to a diferent folder? - VBA or Lisp???
« Reply #11 on: April 05, 2006, 03:51:03 PM »
LMAO Tim,
No problem on the Hijacking because it kept you guys busy while it gave me time to revise my routine to get it to save to the transfer folder.  And it works great, thanks to all of you guys.  It started out as a simple “save to older version” routine and has long since evolved.  I am going to evolve it even further once I do a bunch of reading on DCL files.  Below is the code. Comments on how to improve is always appreciated.

I had the great fortune of working with an 83 year old engineer with his masters from MIT.  The man brilliant to say the least.  He had saying, “Your job everyday is to learn one thing that you didn’t already know.  If you learn that one thing you get to go home for the day.” 

See you tomorrow Guys 8-)
Thanks again.

Code: [Select]
;; TED KRUSH 9/23/02

;;; Routine that was created @ Southern Maine Technical College.
;;; Saves Drawing an eariler version and then resaves as
;;; orginal version to maitain defualt save.

;; UPDATED 02/02/03 Added Date Sub-Routine
;; UPDATED 03/11/05 Revise version save 2002/R14 to 2004/2000 per upgrade to Autocad 2005 version
;; UPDATED 04/05/06 Adde StrPath Sub-Rountine, so as new file can be saved to folder.

;;;;  *** Now We go to to Commerical Break for the Typical Legal Mumbo Jumbo ***
;;;;  Permission to use, copy, modify, and distribute this software
;;;;  for any purpose and without fee is hereby granted.
;;;;   
;;;;  I PROVIDE THIS PROGRAM "AS IS" AND WITH ALL FAULTS. I SPECIFICALLY DISCLAIM ANY
;;;;  IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  I DO NOT
;;;;  WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE UNINTERRUPTED OR ERROR FREE.

(defun c:scon ()

  ;;Error Trap utilizing the TedError Function
  (command ".undo" "m")
  (setq old_error *error*)
  (setq *error* tederror)


  ;;Start of Date defun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  (defun TODAY (/ d yr mo day) ;define the function and declare all variabled local

    (setq d   (rtos (getvar "CDATE") 2 6)
;get the date and time and convert to text

  yr  (substr d 3 2) ;extract the year
  mo  (substr d 5 2) ;extract the month
  day (substr d 7 2) ;extract the day

    )

    (setq dates (strcat mo "-" day "-" yr "_")) ;string 'em together
    (princ)
  )
  ;;End of Date defun

  ;;Start of StrPath defun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  (defun StrPath ()
    (setq OldName (getvar "dwgname"))
    ;; Extracts the Drawing File Name
    (setq OldPath (getvar "dwgprefix"))
    ;; Extracts the Drawing Location
    (setq NewPath (vl-string-subst
    "\\Transfer-Outgoing\\"
    "\\Drawings\\"
    OldPath
  )
    )

    (setq OldFile (strcat OldPath OldName))
; Text String for Old File
    (setq NewFile (strcat NewPath dates Oldname))
; Text String for New File
    (princ)
  )
  ;;End of StrPath defun

  ;; Main Rountine
  (today)
  (StrPath)

  (vl-mkdir NewPath)

  (setvar "expert" 4)
  (command "saveas" "2004" NewFile) ;New file with date Prefix
  (command "saveas" "2004" OldFile) ;Saves back to the Orginal File.
  (setvar "expert" 0)
  (setq *error* old_error)
  (princ)
)
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Save As to a diferent folder? - VBA or Lisp???
« Reply #12 on: April 05, 2006, 04:14:16 PM »
Jeff, we got a good function out of ya. :-D
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.

LE

  • Guest
Re: Save As to a diferent folder? - VBA or Lisp???
« Reply #13 on: April 06, 2006, 11:25:35 AM »
In ACAD2000 vl-mkdir shows up as a good command but not in the help.
vl-rmdir is not recognized as a command

[you might know this already]
Load Jeff's function and have a look on the color for the function name [in the vlisp editor]

Code: [Select]
(pragma '((unprotect-assign vl-rmdir)))
(defun vl-rmdir (path / fso)
  (setq fso (vla-getinterfaceobject
      (vlax-get-acad-object)
      "Scripting.FileSystemObject"))
  (vlax-invoke fso 'deletefolder path 0)
  (vlax-release-object fso))
(pragma '((protect-assign vl-rmdir)))

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Save As to a diferent folder? - VBA or Lisp???
« Reply #14 on: April 06, 2006, 12:43:00 PM »
I wrote a VBA function a while back (R14) that would allow the user to specify 2 specific locations tt save a file to. Whenever the user saved a file, it would save the file to the default location (file path) then save it to the alternate location. Limited error checking was included though ... I'll see if I can round it up ... not sure I still have it ...
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Save As to a diferent folder? - VBA or Lisp???
« Reply #15 on: April 07, 2006, 12:10:56 AM »
VBA or Lisp???

even that VBA is more easier....
Definately...LISP !

Why ?

Because VBA have different version depending MICROSOFT OFFICE....
so when time is come to update MSoffice...this is pain off....
because it change all needed AutoCAD VBA dll file...

need to re-install AutoCAD each time.

secondo....
Diffrent DLL needed for English and french release...
so if you make a program running under VBA english and try to give your program
to someone who using VBA french....

good luck !

For my own....i had very bad experience with all AutoCAD routine made with VBA.

But if you prefer VBA...be careful.

Sorry for VBA programmer....this is my opinion based on my experience. :kewl:
Keep smile...