Jump to content

Recommended Posts

Posted

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.

Posted

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.

Posted (edited)
(command "Undefine" "CLOSE")
(defun c:CLOSE ()
(command "ucs" "w")
(command "Zoom" "E")
[color="red"](command "._qsave")[/color]
(command "._CLOSE")
)

Edited by jdiala
Posted

jdiala,

 

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

 

Thanks!

Posted (edited)
(command "undefine" "close")
(defun C:close ()
(if (= 1 (getvar 'dwgtitled))
   (command "_.ucs" "w" "_.zoom" "e" "_.qsave" "_.close")
   (command "_.close")
)
)

Edited by jdiala
Posted

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.

Posted
(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")
)
)

Posted

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

Posted

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.

Posted
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.

Posted

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.

Posted
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.

Posted

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.

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...