Sam Pawar Posted June 21, 2011 Share Posted June 21, 2011 Hi All, I am working on a project were we have about 70-100 drawings were all object are required to move closer to origin (0.00,0.00). The reason for this is apparently that 3D Studio Max does not support the large coordinates we are using and the drawings are needed to make a visual presentation. Example of fixed coordinates: 571410.00 to 0.00 6565240.00 to 0.00 I do not know much about LISP, but I know just enough to be able to make the following command for respectively meter and millimeter coordinates: (defun c:mao () (command "_move" "all" "" "571410,6565240,0" "0,0,0") (command "_zoom" "e") ) (defun c:mmao () (command "_move" "all" "" "571410000,6565240000,0" "0,0,0") (command "_zoom" "e") ) ...which saves me some time and most importing avoiding typing errors. Still, due to the amount of drawings and the amount of objects within each drawing it is still quite time consuming. So my question is, does anyone know of LISP or other function to do this more automatically? Any ideas? All responses are appreciated, Sam:) Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 21, 2011 Share Posted June 21, 2011 I would change it to: (defun c:mao ( ) (command "_.move" "_all" "" "_non" "571410,6565240,0" "_non" "0,0,0") (command "_.zoom" "_e") (princ) ) (defun c:mmao ( ) (command "_.move" "_all" "" "_non" "571410000,6565240000,0" "_non" "0,0,0") (command "_.zoom" "_e") (princ) ) Then use a Script to open/Run LISP/save/close the drawings. Quote Link to comment Share on other sites More sharing options...
Sam Pawar Posted June 21, 2011 Author Share Posted June 21, 2011 Thanks Lee, However, I am not very good at these things. Is the script something like *.bat file? Sam Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 21, 2011 Share Posted June 21, 2011 However, I am not very good at these things. Is the script something like *.bat file? Not quite - a script is just a list of AutoCAD commands separated by spaces or a new-line. I wrote a short tutorial on Script Writing here, and a Script Writer program here. Alternatively there is ScriptPro. Quote Link to comment Share on other sites More sharing options...
Sam Pawar Posted June 21, 2011 Author Share Posted June 21, 2011 (edited) I searched the forums and found your scriptwriter. Would this be a type of script? _.open *file* _.move _all _non 571410,6565240,0 _non 0,0,0 _.saveas *file* _.close Sam EDIT: Maybe without the ""? Edited June 21, 2011 by Sam Pawar Editing the code/script Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 21, 2011 Share Posted June 21, 2011 Would this be a type of script? That should work with my program, yes. Just remember that a space or newline equals the user pressing 'Enter' and you can't really go wrong EDIT: Just noticed, you will need a double space after _all and a _Y to accept the saveas overwrite prompt: _.open *file* _.move _all _non 571410,6565240,0 _non 0,0,0 _.saveas *file* _Y _.close Quote Link to comment Share on other sites More sharing options...
Sam Pawar Posted June 21, 2011 Author Share Posted June 21, 2011 Thanks Lee:D Will this script open all the drawings in a specified folder? Also, do you know how I can make the code choose the type of coordinates based on the insunits value? Instead of having to separate the function by two commands like I did ("mao" and "mmao")... Sam Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 21, 2011 Share Posted June 21, 2011 You're welcome Sam Will this script open all the drawings in a specified folder? To remove any confusion, note that the line using the *file* token is not a script in itself, but just for use with my program. My program will then substitute the *file* token for the filename of every drawing in your directory when constructing the script - you can see the result by pressing 'save' on the dialog. But to answer your question, yes, the created script will open//save/close all drawings in a directory (and sub-directories). - Try it on copies of drawings first. Also, do you know how I can make the code choose the type of coordinates based on the insunits value? Instead of having to separate the function by two commands like I did ("mao" and "mmao")... At this point it might be worth running the LISP from the Script, i.e.: _.open *file* (c:mao) _.saveas *file* _Y _.close Assuming the LISP is loaded on startup, or: _.open *file* (if (null c:mao) (load "mao.lsp")) (c:mao) _.saveas *file* _Y _.close To attempt to load it, (assuming the filename is 'mao.lsp'). This way the script would be more robust since all operations are performed by the LISP, and using the LISP to do the operations gives you a lot more power and flexibility. Quote Link to comment Share on other sites More sharing options...
Sam Pawar Posted June 21, 2011 Author Share Posted June 21, 2011 You rock Lee!! I'm trying to do an IF function, but don't really know how it works. The coordinates are just for test purpose, will replace them when I get the LISP right. (defun c:mao ( ) (if (= getvar "INSUNITS" 6) (command "_.move" "_all" "" "_non" "5,5,0" "_non" "0,0,0")) (if (= getvar "INSUNITS" 4) (command "_.move" "_all" "" "_non" "5,5,0" "_non" "10,10,0")) (command "_.zoom" "_e") (princ) ) Any suggestions? Sam Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 21, 2011 Share Posted June 21, 2011 Without checking the INSUNITS reference: (defun c:mao ( ) (cond ( (= (getvar "INSUNITS") 6) (command "_.move" "_all" "" "_non" "5,5,0" "_non" "0,0,0") ) ( (= (getvar "INSUNITS") 4) (command "_.move" "_all" "" "_non" "5,5,0" "_non" "10,10,0") ) ) (command "_.zoom" "_e") (princ) ) Or: (defun c:mao ( ) (if (= (getvar "INSUNITS") 6) (command "_.move" "_all" "" "_non" "5,5,0" "_non" "0,0,0") (command "_.move" "_all" "" "_non" "5,5,0" "_non" "10,10,0") ) (command "_.zoom" "_e") (princ) ) Depending on the behaviour you are looking for. Quote Link to comment Share on other sites More sharing options...
Sam Pawar Posted June 21, 2011 Author Share Posted June 21, 2011 Thanks Lee, again it works perfect! I have just encountered another problem, some drawings asks for RECOVERY before opening, this stops the script unfortunately. Do you or anyone else have any solution for this? Sam Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 21, 2011 Share Posted June 21, 2011 Thanks Lee, again it works perfect! You're welcome Sam I have just encountered another problem, some drawings asks for RECOVERY before opening, this stops the script unfortunately. Do you or anyone else have any solution for this? I'm afraid I've never come across this problem, perhaps other members have a solution for you. Quote Link to comment Share on other sites More sharing options...
rkent Posted June 21, 2011 Share Posted June 21, 2011 You may encounter drawings with frozen layers, locked layers, layers turned off. You will need to add to your script or lisp file to account for that possiblilty. Quote Link to comment Share on other sites More sharing options...
Sam Pawar Posted June 21, 2011 Author Share Posted June 21, 2011 (edited) Lee, where does your program search for the LISP? I am having trouble loading it... Edit: error message: Command: (if (null c:mao) (load mao.lsp)) ; error: bad argument type: stringp nil Edit2: Found the Error "" was missing around the "mao.lsp" Sam Edited June 21, 2011 by Sam Pawar Found the Error Quote Link to comment Share on other sites More sharing options...
Sam Pawar Posted June 21, 2011 Author Share Posted June 21, 2011 You may encounter drawings with frozen layers, locked layers, layers turned off. You will need to add to your script or lisp file to account for that possiblilty. I have still much to learn! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted June 21, 2011 Share Posted June 21, 2011 Lee, where does your program search for the LISP? I am having trouble loading it... Note that my program doesn't search for it, the 'load' function will search the AutoCAD Support Paths Quote Link to comment Share on other sites More sharing options...
BIGAL Posted June 22, 2011 Share Posted June 22, 2011 Just a suggestion rather than picking a fixed co-ordinate as base point do the following zoom e get extmin then move extmin to 0,0 then zoom e this way if your object is say a 1000m away form base point it will still end up at 0,0 A similar example (PROMPT ".....now moving dwgs....") (setq doc (vla-get-activedocument (vlax-get-acad-object))) (vlax-for lay (vla-get-Layouts doc) (setq plotabs (cons (vla-get-name lay) plotabs)) ) (setq plottablist (acad_strlsort plotabs)) (setq len (length plottablist)) (setvar "osmode" 0) (setq K 0) (repeat len (setq name (nth K plottablist)) (princ name) (if (/= name "Model") (progn (setvar "ctab" name) (command "zoom" "E") (setq minxy (getvar "extmin")) (setq maxxy (getvar "extmax")) (SETQ X (car minxy)) (SETQ y (cadr minxy)) (SETQ Xx (car maxxy)) (SETQ yx (cadr maxxy)) (setq ang (angle minxy maxxy)) (setq dist (/ (distance minxy maxxy) 2.0)) (setq pt1 (polar minxy dist ang)) (Command "zoom" "C" pt1 1000.0) (setq x (+ x 20.0)) (setq y (+ y 20.0)) (setq xy (list x y)) (command "move" "w" minxy maxxy "" xy "0,0") (command "zoom" "E") ) ;end progn ) ; end if (setq K (+ K 1)) ) ; end repeat (princ) Just create a script open dwg1 (load "zoomextents") close "Y" open dwg2 (load "zoomextents") close "Y" and so on Take advice above about frozen layers etc though they will be left behind. Quote Link to comment Share on other sites More sharing options...
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.