Drwo Posted May 20, 2010 Posted May 20, 2010 I am trying to make a backup of the autoCAD workspace in order to safely change some ACAD settings. While doing this I'm encountering a slight problem. If there is an existing workspace with that name than I need to set up a positive answer to overwrite it and nothing if there isn't any such workspace. A wrong choice stops the script from executing further. I found a solution to this in the form of this code posted by VVA (defun C:SW () ;;;Save WorkSpace (command "_.WorkSpace" "_Save" "[color=red]MyWorkSpace[/color]" [b];;;_ Type this your workspace name[/b] ) (while (> (getvar "CMDACTIVE") 0)(command "_Y")) (princ) ) I tried converting it to a part of the script but it always hangs at the end. I can't seem to find a way to end the code without ending the script execution. I also tried making it a separate *.lsp file and loading it from the script (load "G:\\...\\install.lsp") [size=4][color=red]sw[/color][/size] (vl-load-com) (vla-put-enterprisemenufile (vla-get-files (vla-get-preferences(vlax-get-acad-object)))"G:/.../Standard_001.cui") (command "*_TOOLPALETTEPATH" "G:/.../PALETTE SYSTEM") (command "workspace" "c" "tmp") (command "-toolbar" "STANDARD BLOCKS" "SHOW") (command "quit" "y") But the script alway stays entangled in the lisp code... If I try to execute it directly in the command line it works perfectly... So the solution is quite ungraspable to me Quote
alanjt Posted May 20, 2010 Posted May 20, 2010 Works fine on my end. eg. (defun c:Test (/) (command "_.workspace" "_sa" "ALAN") (while (> (getvar "cmdactive") 0) (command "_Y")) (command "_.line") (princ) ) Quote
Drwo Posted May 20, 2010 Author Posted May 20, 2010 Works fine on my end. That part of the code works fine for me as well. I'm having problems combining it with the script file. This is what happens if the workspace file already exists Command: (load "G:\\Isme\\STS\\DRAFTING\\AUTOCAD_TOOLS\\Library\\Blocks_2010\\Installation\\ins tall.lsp") C:TEST Command: test _.workspace Enter workspace option [setCurrent/SAveas/Edit/Rename/Delete/SEttings/?] <setCurrent>: _sa Save Workspace as <TMP>: tmp "tmp" already exists. Do you wish to replace it? [Yes/No]? <N> _Y Command: _Y Unknown command "Y". Press F1 for help. Command: _.line Specify first point: Specify first point: *Cancel* This is what happens if the workspace doesn't exist Command: ((load "G:\\Isme\\STS\\DRAFTING\\AUTOCAD_TOOLS\\Library\\Blocks_2010\\Installation\\ins tall.lsp") (_> test (_> (vl-load-com) (_> (vla-put-enterprisemenufile (vla-get-files (vla-get-preferences(vlax-get-acad-object)))"G:/Isme/STS/DRAFTING/AUTOCAD_TOOLS/ Library/Blocks_2010/Installation/Standard_001.cui") (_> (command "*_TOOLPALETTEPATH" "G:/Isme/STS/DRAFTING/AUTOCAD_TOOLS/Library/Blocks_2010/PALETTE SYSTEM") (_> (command "workspace" "c" "tmp") (_> (command "-toolbar" "STANDARD BLOCKS" "SHOW") (_> (command "quit" "y") (_> *Cancel* ; error: Function cancelled I had to manually cancel the commands in both cases. And if I place an additional enter or space at the end of the code it doesn't help. Quote
alanjt Posted May 20, 2010 Posted May 20, 2010 Try it this way... (defun c:Test (/) (command "_.workspace" "_sa" "ALAN") (while (eq (logand 1 (getvar 'cmdactive)) 1) (command "_Y")) (command "_.line") (princ) ) Quote
Drwo Posted May 20, 2010 Author Posted May 20, 2010 Sorry my workhours just ended right after the post... I'll check it out tomorrow morning and let you know Quote
Drwo Posted May 21, 2010 Author Posted May 21, 2010 I removed the line of code for drawing a line and it works now.. Thanks Quote
alanjt Posted May 21, 2010 Posted May 21, 2010 I removed the line of code for drawing a line and it works now.. Thanks Yeah, that was just for demonstration purposes. Glad it works. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.