cgv Posted October 16, 2013 Share Posted October 16, 2013 Hi, Just wondering if anyone knows if there is some kind of routine that will set the UCS of a drawing back to world when the drawing is closed? Is this possible? Thanks. Quote Link to comment Share on other sites More sharing options...
BIGAL Posted October 17, 2013 Share Posted October 17, 2013 You can redefine a command so that it runs a series of commands. Its been a while something like this needs to be saved as part of your Autoload lisps area (command "Undefine" "CLOSE") (defun c:CLOSE () (command "ucs" "w") (command "Zoom" "E") (command "._CLOSE") ) Also http://www.afralisp.net/autolisp/tutorials/redefining-commands.php Quote Link to comment Share on other sites More sharing options...
cgv Posted October 17, 2013 Author Share Posted October 17, 2013 Al, I've loaded that LISP into the startup, but it doesn't seem to be setting my UCS to world co-ordinates on close. Quote Link to comment Share on other sites More sharing options...
jdiala Posted October 17, 2013 Share Posted October 17, 2013 (edited) (command "Undefine" "CLOSE") (defun c:CLOSE () (command "ucs" "w") (command "Zoom" "E") [color="red"](command "._qsave")[/color] (command "._CLOSE") ) Edited October 17, 2013 by jdiala Quote Link to comment Share on other sites More sharing options...
cgv Posted October 17, 2013 Author Share Posted October 17, 2013 jdiala, Is there a way to have the drawing ask whether to save or not? Otherwise, it just saves the drawings automatically. Thanks! Quote Link to comment Share on other sites More sharing options...
jdiala Posted October 17, 2013 Share Posted October 17, 2013 (edited) (command "undefine" "close") (defun C:close () (if (= 1 (getvar 'dwgtitled)) (command "_.ucs" "w" "_.zoom" "e" "_.qsave" "_.close") (command "_.close") ) ) Edited October 17, 2013 by jdiala Quote Link to comment Share on other sites More sharing options...
cgv Posted October 17, 2013 Author Share Posted October 17, 2013 jdiala, The routine still doesn't seem to be asking whether or not to save the drawing. It is still saving automatically on close. Thanks again. Quote Link to comment Share on other sites More sharing options...
jdiala Posted October 17, 2013 Share Posted October 17, 2013 (command "undefine" "close") (defun C:close () (initget 7 "Yes No") (setq a (getkword "\nDo you want to save the drawing? (Yes / No) ")) (if (= a "Yes") (if (= 1 (getvar 'dwgtitled)) (command "_.ucs" "w" "_.zoom" "e" "_.qsave" "_.close") (progn (command "_.ucs" "w" "_.zoom" "e") (initdia) (command "_.save" "_.close") ) ) (command "_.close" "n") ) ) Quote Link to comment Share on other sites More sharing options...
cgv Posted October 17, 2013 Author Share Posted October 17, 2013 Thanks jdiala, but it seems to disagree with closing my drawings sometimes. I guess there is no way around that. I have read something about using a command in a 'reactor', but I don't know how these work. http://www.cadtutor.net/forum/showthread.php?46761-UCS-WORLD-without-the-UCS-command-call Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 17, 2013 Share Posted October 17, 2013 Here is an example using a Drawing Reactor: [color=GREEN];; UCS Reactor - Lee Mac[/color] [color=GREEN];; Sets the active UCS to a UCS equivalent to WCS when the drawing is saved.[/color] ([color=BLUE]defun[/color] c:ucsr-on ( ) ([color=BLUE]if[/color] ([color=BLUE]=[/color] '[color=BLUE]vlr-dwg-reactor[/color] ([color=BLUE]type[/color] ucsr:reactor)) ([color=BLUE]if[/color] ([color=BLUE]vlr-added-p[/color] ucsr:reactor) ([color=BLUE]princ[/color] [color=MAROON]"\nUCS reactor already running."[/color]) ([color=BLUE]progn[/color] ([color=BLUE]vlr-add[/color] ucsr:reactor) ([color=BLUE]princ[/color] [color=MAROON]"\nUCS reactor enabled."[/color]) ) ) ([color=BLUE]progn[/color] ([color=BLUE]setq[/color] ucsr:reactor ([color=BLUE]vlr-dwg-reactor[/color] [color=MAROON]"ucs-reactor"[/color] '( ([color=BLUE]:vlr-beginsave[/color] . ucsr:beginsave) ([color=BLUE]:vlr-savecomplete[/color] . ucsr:savecomplete) ) ) ) ([color=BLUE]princ[/color] [color=MAROON]"\nUCS reactor enabled."[/color]) ) ) ([color=BLUE]princ[/color]) ) ([color=BLUE]defun[/color] c:ucsr-off ( [color=BLUE]/[/color] cmd ) ([color=BLUE]if[/color] ([color=BLUE]=[/color] '[color=BLUE]vlr-dwg-reactor[/color] ([color=BLUE]type[/color] ucsr:reactor)) ([color=BLUE]progn[/color] ([color=BLUE]vlr-remove[/color] ucsr:reactor) ([color=BLUE]setq[/color] ucsr:reactor [color=BLUE]nil[/color]) ([color=BLUE]setq[/color] cmd ([color=BLUE]getvar[/color] 'cmdecho)) ([color=BLUE]setvar[/color] 'cmdecho 0) ([color=BLUE]command[/color] [color=MAROON]"_.ucs"[/color] [color=MAROON]"_w"[/color]) ([color=BLUE]setvar[/color] 'cmdecho cmd) ([color=BLUE]if[/color] ([color=BLUE]tblsearch[/color] [color=MAROON]"ucs"[/color] [color=MAROON]"ucsr-ucs"[/color]) ([color=BLUE]vla-delete[/color] ([color=BLUE]vla-item[/color] ([color=BLUE]vla-get-usercoordinatesystems[/color] (ucsr:acdoc)) [color=MAROON]"ucsr-ucs"[/color])) ) ([color=BLUE]princ[/color] [color=MAROON]"\nUCS reactor disabled."[/color]) ) ([color=BLUE]princ[/color] [color=MAROON]"\nUCS reactor not running."[/color]) ) ([color=BLUE]princ[/color]) ) ([color=BLUE]defun[/color] ucsr:beginsave ( obj arg ) ([color=BLUE]if[/color] ([color=BLUE]=[/color] [color=MAROON]""[/color] ([color=BLUE]setq[/color] ucsr:prevucs ([color=BLUE]getvar[/color] 'ucsname))) ([color=BLUE]setq[/color] ucsr:prevucs ([color=BLUE]mapcar[/color] '[color=BLUE]getvar[/color] '(ucsorg ucsxdir ucsydir))) ) ([color=BLUE]vla-put-activeucs[/color] (ucsr:acdoc) ([color=BLUE]vlax-invoke[/color] ([color=BLUE]vla-get-usercoordinatesystems[/color] (ucsr:acdoc)) 'add '(0.0 0.0 0.0) '(1.0 0.0 0.0) '(0.0 1.0 0.0) [color=MAROON]"ucsr-ucs"[/color] ) ) ([color=BLUE]princ[/color]) ) ([color=BLUE]defun[/color] ucsr:savecomplete ( obj arg ) ([color=BLUE]cond[/color] ( ([color=BLUE]=[/color] 'str ([color=BLUE]type[/color] ucsr:prevucs)) ([color=BLUE]if[/color] ([color=BLUE]tblsearch[/color] [color=MAROON]"ucs"[/color] ucsr:prevucs) ([color=BLUE]vla-put-activeucs[/color] (ucsr:acdoc) ([color=BLUE]vla-item[/color] ([color=BLUE]vla-get-usercoordinatesystems[/color] (ucsr:acdoc)) ucsr:prevucs) ) ) ) ( ([color=BLUE]=[/color] '[color=BLUE]list[/color] ([color=BLUE]type[/color] ucsr:prevucs)) ([color=BLUE]vla-put-activeucs[/color] (ucsr:acdoc) ([color=BLUE]apply[/color] '[color=BLUE]vlax-invoke[/color] ([color=BLUE]append[/color] ([color=BLUE]list[/color] ([color=BLUE]vla-get-usercoordinatesystems[/color] (ucsr:acdoc)) 'add) ucsr:prevucs '([color=MAROON]"ucsr-ucs"[/color]) ) ) ) ) ) ([color=BLUE]setq[/color] ucsr:prevucs [color=BLUE]nil[/color]) ([color=BLUE]princ[/color]) ) ([color=BLUE]defun[/color] ucsr:acdoc [color=BLUE]nil[/color] ([color=BLUE]eval[/color] ([color=BLUE]list[/color] '[color=BLUE]defun[/color] 'ucsr:acdoc '[color=BLUE]nil[/color] ([color=BLUE]vla-get-activedocument[/color] ([color=BLUE]vlax-get-acad-object[/color])))) (ucsr:acdoc) ) ([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color]) Type ucsr-on to activate the reactor which will then run silently in the background to be triggered when the drawing is saved. When saved, the reactor callback function will set the UCS to a WCS equivalent, and will then restore the previous UCS when the save operation is complete. You can disable the reactor at any time using the ucsr-off command. However, note that since one cannot evaluated command calls from within reactor callback functions, and furthermore it is not possible (to my knowledge) to set the UCS to WCS using Visual LISP, the above program will set the UCS to a Named UCS equivalent to WCS. Lee Quote Link to comment Share on other sites More sharing options...
cgv Posted October 17, 2013 Author Share Posted October 17, 2013 Lee Mac, That is exactly what I want. What a guy. The only thing is that it doesn't seem to work when your UCS is set to 'view'. Additionally, would there be a way to have this reactor always on when CAD is started up? Thanks heaps. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 18, 2013 Share Posted October 18, 2013 Lee Mac, That is exactly what I want. What a guy. The only thing is that it doesn't seem to work when your UCS is set to 'view'. Additionally, would there be a way to have this reactor always on when CAD is started up? Thanks heaps. You're welcome! I've tested the application and I see no problem when the UCS is set to View - the drawing is saved with the UCS set to WCS and the previous UCS is successfully restored - what problem do you encounter? Regarding loading the program on start-up, follow the procedure I describe here with regards to creating an acaddoc.lsp and add (c:ucsr-on) on a new line at the end of the program. Quote Link to comment Share on other sites More sharing options...
cgv Posted October 20, 2013 Author Share Posted October 20, 2013 Lee, The problem I'm encountering is when I set the UCS to 'view'. I've just realised that the first time I save, while the UCS is at 'view', it does not revert back to WCS. Hitting save a second time though reverts the UCS to world. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 21, 2013 Share Posted October 21, 2013 The problem I'm encountering is when I set the UCS to 'view'. I've just realised that the first time I save, while the UCS is at 'view', it does not revert back to WCS. Hitting save a second time though reverts the UCS to world. Please note that the program cannot set the UCS to WCS, but will set the UCS to a Named UCS which is equivalent to the WCS, for the reasons noted in my earlier post: However, note that since one cannot evaluate command calls from within reactor callback functions, and furthermore it is not possible (to my knowledge) to set the UCS to WCS using Visual LISP, the above program will set the UCS to a Named UCS equivalent to WCS. This might be the behaviour that you are observing. Quote Link to comment Share on other sites More sharing options...
cgv Posted October 22, 2013 Author Share Posted October 22, 2013 Ah well. Should do me fine. Thanks Lee. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted October 22, 2013 Share Posted October 22, 2013 No worries cgv I'd gladly be proven wrong and for someone to find a method of setting the UCS to WCS via Visual LISP, but in my experience it seems that this is a limitation of ActiveX. 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.