Author Topic: Executing bat files in current drawing location  (Read 5481 times)

0 Members and 1 Guest are viewing this topic.

Grrr1337

  • Swamp Rat
  • Posts: 812
Re: Executing bat files in current drawing location
« Reply #15 on: October 26, 2017, 05:16:09 AM »
If left with no options, perhaps try to copy the file with fso and then run it with shell ?
BTW vlax-release-object.
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)
vevo.bg

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Executing bat files in current drawing location
« Reply #16 on: October 26, 2017, 09:13:22 AM »
Note: If you want to enclose the file name in double quotes you should modify ronjonp's code.
Code - Auto/Visual Lisp: [Select]
  1. ; (_run "C:\\Test Test\\sync.bat") => OK
  2. ; (_run "C:/Test Test/sync.bat") => OK
  3. (defun _run (file / ws)
  4.   (if (and (findfile file) (setq ws (vlax-get-or-create-object "wscript.shell")))
  5.     (progn (vlax-invoke-method ws 'run (strcat "\"" file "\"") 0) file)
  6.   )
  7. )
This works for me too. Updated my code HERE.

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Executing bat files in current drawing location
« Reply #17 on: October 26, 2017, 11:04:45 AM »
I don't see the difference between the two "sync.bat" scripts. Is this "robocopy" program your problem or is AutoLisp (...why would you use robocopy to begin with you may as well be using xcopy?)? I would suggest looking into Unison and simplifying a bit.

Also, wouldn't just setting up a "scheduled task" in windows be easier?

I see what you did there..LoL, nope didn't work.
Ok, one more:
Code: [Select]
(_run "\"C:/Test Test/sync.bat\"")

here is my sync.bat file
This works well together
Code: [Select]
(_run "c:\\Test\\mirsup.bat")
Code: [Select]
@pushd %~dp0
cls
robocopy "C:\Test" "C:\Test Test" /MIR /XF *.dwl /XF UpdateLog.txt /XF toolsversion.txt /R:10 /W:5 /ETA /TEE /LOG+:ToolsUpdateLog.txt
@popd

However if I change the sync.bat file to this.
Code: [Select]
robocopy "C:\Test" "C:\Test Test" /MIR /XF *.dwl /XF UpdateLog.txt /XF toolsversion.txt /R:10 /W:5 /ETA /TEE /LOG+:ToolsUpdateLog.txt
It won't work
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: Executing bat files in current drawing location
« Reply #18 on: October 26, 2017, 11:15:03 AM »
There's lot's of compelling reasons to use robocopy John.

Agree that task scheduling (or folder watching triggered events) may be a good strategy.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

dubb

  • Swamp Rat
  • Posts: 1105
Re: Executing bat files in current drawing location
« Reply #19 on: October 26, 2017, 11:16:20 AM »
Thanks! I really need to learn more about vlax functions. This worked perfectly. Thanks to all who helped.
Note: If you want to enclose the file name in double quotes you should modify ronjonp's code.
Code - Auto/Visual Lisp: [Select]
  1. ; (_run "C:\\Test Test\\sync.bat") => OK
  2. ; (_run "C:/Test Test/sync.bat") => OK
  3. (defun _run (file / ws)
  4.   (if (and (findfile file) (setq ws (vlax-get-or-create-object "wscript.shell")))
  5.     (progn (vlax-invoke-method ws 'run (strcat "\"" file "\"") 0) file)
  6.   )
  7. )

dubb

  • Swamp Rat
  • Posts: 1105
Re: Executing bat files in current drawing location
« Reply #20 on: October 26, 2017, 11:21:41 AM »
@John, I was kinda set with using Robocopy because I liked how easy it was to use. Though Ron's xcopy solution might work. If I find the time to tweak it a little to fit my needs. I will be giving it a try.

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Executing bat files in current drawing location
« Reply #21 on: October 26, 2017, 11:32:43 AM »
There's lot's of compelling reasons to use robocopy John.

Agree that task scheduling (or folder watching triggered events) may be a good strategy.

Ok. Would like to help but don't really know how; because it sounds like the problem, to me, is over complication or this robocopy program (arguments or something). I looked at the Wikipedia page for it and it seems like a pretty basic copy program. ...I mean the only reason I ask `why use robocopy' is because it sounds like the OP wants to preform a sync type operation and I just don't understand why you wouldn't want to use a sync type program (why make syncing more difficult then it already is). -i.e. something like Unison or Rsync will give you all of the features xcopy/robocopy will give you, in addition, better detection and better efficiently (both result in faster syncs) and you can create a simple script which can be called with scheduled tasks.

TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Executing bat files in current drawing location
« Reply #22 on: October 26, 2017, 11:36:07 AM »
@John, I was kinda set with using Robocopy because I liked how easy it was to use. Though Ron's xcopy solution might work. If I find the time to tweak it a little to fit my needs. I will be giving it a try.

That doesn't look simple at all!
"robocopy "C:\Test" "C:\Test Test" /MIR /XF *.dwl /XF UpdateLog.txt /XF toolsversion.txt /R:10 /W:5 /ETA /TEE /LOG+:ToolsUpdateLog.txt"

It's really no big deal to me what you use but personally I keep things simple as possible. I don't like strings like that because I forget what all of those switches mean and cannot fix problems later.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

dubb

  • Swamp Rat
  • Posts: 1105
Re: Executing bat files in current drawing location
« Reply #23 on: October 26, 2017, 11:47:27 AM »
I would love to use Rsync, I haven't used it for a while since I don't have my linux server. How I decided to use robocopy instead of xcopy; I searched how to synchronize files using dos and autolisp and robocopy seemed easy and had some of the features that seemed to fit my needs however, its not perfect and I am receiving feedback on how it performs. Though I would like to use Rsync or Unison, I also want to limit the amount of third party application distributed to other workstations. Not sure if I have to install Rsync or unison on each work station individually so I am hesitant to take the responsibility in ensuring every third party application is installed. I create several tools with autolisp for my office as a head designer for my office. To deploy these tools a new workstation would require an installation of autocad and the customized profile.

dubb

  • Swamp Rat
  • Posts: 1105
Re: Executing bat files in current drawing location
« Reply #24 on: October 26, 2017, 11:53:46 AM »
Thanks I value your input.

Quote

That doesn't look simple at all!
"robocopy "C:\Test" "C:\Test Test" /MIR /XF *.dwl /XF UpdateLog.txt /XF toolsversion.txt /R:10 /W:5 /ETA /TEE /LOG+:ToolsUpdateLog.txt"

It's really no big deal to me what you use but personally I keep things simple as possible. I don't like strings like that because I forget what all of those switches mean and cannot fix problems later.

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Executing bat files in current drawing location
« Reply #25 on: October 26, 2017, 12:08:15 PM »
Alright, humor me. Try Unison. Rsync will require you to get cygin dlls and stuff (too complicated for this post). I jotted down some steps for you to take/try out unison with. I really don't have a lot of time (I have a 90% going out in a few weeks and I need to do a lot of things before then) but these instructions should get you going.

Unison doesn't require an install; its just a binary that would need to be copied to everyone's hard drive (that would be a good job for xcopy or robocopy). You can create an installer for it if you wish but not really necessary.

Steps:
1. Get the windows binary.

[ https://www.irif.fr/~vouillon/unison/ ]

2. Unpack and place the binary somewhere.
3. Update your windows PATH enviorment variable to include where that binary is. (optional; hard-code paths in step 8 if no env variable)
4. Open text editor and create a file in the following directory:
 [ C:\Users\<username>\.unison\ ]
5. Name the file something usefull like: "sync_Documents-folder.prf"
6. Populate the file with the following (adjust per your needs):

Code: [Select]
# Unison preferences file
# This file will preform a sync on "my documents" folder to my USB stick
#
# Last Updated: 01.01.99

#---[ Root ]------------------------------------------------------------
root = C:/Users/<username>/
root = D:/

#---[ Paths ]-----------------------------------------------------------
# Paths to synchronize
path = Documents

#---[ Options ]---------------------------------------------------------
batch = true
# confirmbigdel = false

#---[ Ignore ]----------------------------------------------------------

ignore = Path */Temp

ignore = Name *.tmp
ignore = Name *.example
ignore = Name *.zip

7. Create another file somewhere on your desktop called "Sync Documents to USB.cmd"
8. Populate it with the following code:

Code: [Select]
@echo off
call <path>\<to>\<unison>\unison.exe sync_Documents-folder

pause

9. Plug in USB stick.
10. Double click the "Sync Documents to USB.cmd" on your desktop.
« Last Edit: October 26, 2017, 12:13:38 PM by John Kaul (Se7en) »
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

dubb

  • Swamp Rat
  • Posts: 1105
Re: Executing bat files in current drawing location
« Reply #26 on: October 26, 2017, 12:16:24 PM »
Got it, will report on this within the next few business days. Thanks!

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: Executing bat files in current drawing location
« Reply #27 on: October 26, 2017, 12:21:38 PM »
Sounds good. I'd recommend trying out different folders on your hard drive with different size files. -i.e. Try out a bunch of small files and see how long it takes to sync a few folders like that. You'll be surprised at how fast it is and how you can't really foul anything up. 

Good luck.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Executing bat files in current drawing location
« Reply #28 on: October 26, 2017, 04:20:28 PM »
... Though Ron's xcopy solution might work. If I find the time to tweak it a little to fit my needs. I will be giving it a try.
I added some code HERE to run RoboCopy out of AutoCAD .. give it a try! :) 

Use like so:
Code - Auto/Visual Lisp: [Select]
  1. (rjp-robocopy
  2.   "C:\\Test"
  3.   "C:\\Test Test"
  4.   nil
  5.   "/MIR /XF *.dwl /XF UpdateLog.txt /XF toolsversion.txt /R:10 /W:5 /ETA /TEE /LOG+:ToolsUpdateLog.txt"
  6. )
« Last Edit: October 26, 2017, 04:26:50 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

dubb

  • Swamp Rat
  • Posts: 1105
Re: Executing bat files in current drawing location
« Reply #29 on: October 26, 2017, 07:34:43 PM »
Sweet! Looks great! Thanks Ron.

... Though Ron's xcopy solution might work. If I find the time to tweak it a little to fit my needs. I will be giving it a try.
I added some code HERE to run RoboCopy out of AutoCAD .. give it a try! :) 

Use like so:
Code - Auto/Visual Lisp: [Select]
  1. (rjp-robocopy
  2.   "C:\\Test"
  3.   "C:\\Test Test"
  4.   nil
  5.   "/MIR /XF *.dwl /XF UpdateLog.txt /XF toolsversion.txt /R:10 /W:5 /ETA /TEE /LOG+:ToolsUpdateLog.txt"
  6. )