Jump to content
cgv

Set UCS to world co-ordinates when closing drawing.

Recommended Posts

cgv

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.

Share this post


Link to post
Share on other sites
BIGAL

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

Share this post


Link to post
Share on other sites
cgv

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.

Share this post


Link to post
Share on other sites
jdiala
(command "Undefine" "CLOSE")
(defun c:CLOSE ()
(command "ucs" "w")
(command "Zoom" "E")
[color="red"](command "._qsave")[/color]
(command "._CLOSE")
)

Edited by jdiala

Share this post


Link to post
Share on other sites
cgv

jdiala,

 

Is there a way to have the drawing ask whether to save or not? Otherwise, it just saves the drawings automatically.

 

Thanks!

Share this post


Link to post
Share on other sites
jdiala
(command "undefine" "close")
(defun C:close ()
(if (= 1 (getvar 'dwgtitled))
   (command "_.ucs" "w" "_.zoom" "e" "_.qsave" "_.close")
   (command "_.close")
)
)

Edited by jdiala

Share this post


Link to post
Share on other sites
cgv

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.

Share this post


Link to post
Share on other sites
jdiala
(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")
)
)

Share this post


Link to post
Share on other sites
Lee Mac

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

Share this post


Link to post
Share on other sites
cgv

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.

Share this post


Link to post
Share on other sites
Lee Mac
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! :thumbsup:

 

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.

Share this post


Link to post
Share on other sites
cgv

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.

Share this post


Link to post
Share on other sites
Lee Mac
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.

Share this post


Link to post
Share on other sites
cgv

Ah well. Should do me fine. Thanks Lee.

Share this post


Link to post
Share on other sites
Lee Mac

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.

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...