+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 16
  1. #1
    Full Member
    Using
    AutoCAD 2014
    Join Date
    Sep 2013
    Posts
    28

    Default Set UCS to world co-ordinates when closing drawing.

    Registered forum members do not see this ad.

    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.

  2. #2
    Luminous Being
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    9,748

    Default

    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

    Code:
    (command "Undefine" "CLOSE")
    (defun c:CLOSE ()
    (command "ucs" "w")
    (command "Zoom" "E")
    (command "._CLOSE")
    )
    Also http://www.afralisp.net/autolisp/tut...g-commands.php
    A man who never made mistakes never made anything

  3. #3
    Full Member
    Using
    AutoCAD 2014
    Join Date
    Sep 2013
    Posts
    28

    Default

    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.

  4. #4
    Senior Member
    Discipline
    Mechanical
    jdiala's Discipline Details
    Occupation
    Cad Manager
    Discipline
    Mechanical
    Using
    AutoCAD 2014
    Join Date
    Jul 2013
    Location
    Fairfax, VA
    Posts
    100

    Default

    Code:
    (command "Undefine" "CLOSE")
    (defun c:CLOSE ()
    (command "ucs" "w")
    (command "Zoom" "E")
    (command "._qsave")
    (command "._CLOSE")
    )
    Last edited by jdiala; 17th Oct 2013 at 04:55 am.

  5. #5
    Full Member
    Using
    AutoCAD 2014
    Join Date
    Sep 2013
    Posts
    28

    Default

    jdiala,

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

    Thanks!

  6. #6
    Senior Member
    Discipline
    Mechanical
    jdiala's Discipline Details
    Occupation
    Cad Manager
    Discipline
    Mechanical
    Using
    AutoCAD 2014
    Join Date
    Jul 2013
    Location
    Fairfax, VA
    Posts
    100

    Default

    Code:
    (command "undefine" "close")
    (defun C:close ()
    (if (= 1 (getvar 'dwgtitled))
        (command "_.ucs" "w" "_.zoom" "e" "_.qsave" "_.close")
        (command "_.close")
    )
    )
    Last edited by jdiala; 17th Oct 2013 at 04:54 am.

  7. #7
    Full Member
    Using
    AutoCAD 2014
    Join Date
    Sep 2013
    Posts
    28

    Default

    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.

  8. #8
    Senior Member
    Discipline
    Mechanical
    jdiala's Discipline Details
    Occupation
    Cad Manager
    Discipline
    Mechanical
    Using
    AutoCAD 2014
    Join Date
    Jul 2013
    Location
    Fairfax, VA
    Posts
    100

    Default

    Code:
    (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")
    )
    )

  9. #9
    Full Member
    Using
    AutoCAD 2014
    Join Date
    Sep 2013
    Posts
    28

    Default

    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/showth...S-command-call

  10. #10
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,322

    Default

    Registered forum members do not see this ad.

    Here is an example using a Drawing Reactor:

    Code:
    ;; UCS Reactor  -  Lee Mac
    ;; Sets the active UCS to a UCS equivalent to WCS when the drawing is saved.
    
    (defun c:ucsr-on ( )
        (if (= 'vlr-dwg-reactor (type ucsr:reactor))
            (if (vlr-added-p ucsr:reactor)
                (princ "\nUCS reactor already running.")
                (progn
                    (vlr-add ucsr:reactor)
                    (princ "\nUCS reactor enabled.")
                )
            )
            (progn
                (setq ucsr:reactor
                    (vlr-dwg-reactor "ucs-reactor"
                       '(
                            (:vlr-beginsave    . ucsr:beginsave)
                            (:vlr-savecomplete . ucsr:savecomplete)
                        )
                    )
                )
                (princ "\nUCS reactor enabled.")
            )
        )
        (princ)
    )
    
    (defun c:ucsr-off ( / cmd )
        (if (= 'vlr-dwg-reactor (type ucsr:reactor))
            (progn
                (vlr-remove ucsr:reactor)
                (setq ucsr:reactor nil)
                (setq cmd (getvar 'cmdecho))
                (setvar 'cmdecho 0)
                (command "_.ucs" "_w")
                (setvar 'cmdecho cmd)
                (if (tblsearch "ucs" "ucsr-ucs")
                    (vla-delete (vla-item (vla-get-usercoordinatesystems (ucsr:acdoc)) "ucsr-ucs"))
                )
                (princ "\nUCS reactor disabled.")
            )
            (princ "\nUCS reactor not running.")
        )
        (princ)
    )
    
    (defun ucsr:beginsave ( obj arg )
        (if (= "" (setq ucsr:prevucs (getvar 'ucsname)))
            (setq ucsr:prevucs (mapcar 'getvar '(ucsorg ucsxdir ucsydir)))
        )
        (vla-put-activeucs (ucsr:acdoc)
            (vlax-invoke (vla-get-usercoordinatesystems (ucsr:acdoc)) 'add
                '(0.0 0.0 0.0)
                '(1.0 0.0 0.0)
                '(0.0 1.0 0.0)
                "ucsr-ucs"
            )
        )
        (princ)
    )
    
    (defun ucsr:savecomplete ( obj arg )
        (cond
            (   (= 'str (type ucsr:prevucs))
                (if (tblsearch "ucs" ucsr:prevucs)
                    (vla-put-activeucs (ucsr:acdoc)
                        (vla-item (vla-get-usercoordinatesystems (ucsr:acdoc)) ucsr:prevucs)
                    )
                )
            )
            (   (= 'list (type ucsr:prevucs))
                (vla-put-activeucs (ucsr:acdoc)
                    (apply 'vlax-invoke
                         (append
                             (list (vla-get-usercoordinatesystems (ucsr:acdoc)) 'add)
                             ucsr:prevucs
                            '("ucsr-ucs")
                         )
                    )
                )
            )
        )
        (setq ucsr:prevucs nil)
        (princ)
    )
    
    (defun ucsr:acdoc nil
        (eval (list 'defun 'ucsr:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
        (ucsr:acdoc)
    )
    
    (vl-load-com) (princ)
    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
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

Similar Threads

  1. Closing Dynamic Blocks - Drawing Slow
    By JBullseye74 in forum AutoCAD Drawing Management & Output
    Replies: 5
    Last Post: 13th Oct 2011, 10:16 pm
  2. Fatal Error - DBX Cas 3 when saving and closing drawing
    By htan in forum .NET, ObjectARX & VBA
    Replies: 2
    Last Post: 17th May 2010, 01:52 pm
  3. How do I release the value of a setting upon closing a drawing?
    By avscorey in forum AutoLISP, Visual LISP & DCL
    Replies: 8
    Last Post: 11th Feb 2010, 02:29 pm
  4. Save option when closing a drawing
    By Siberian in forum AutoCAD Drawing Management & Output
    Replies: 2
    Last Post: 3rd Aug 2006, 02:20 pm
  5. covert drawing to c-ordinates
    By blowe in forum AutoCAD Beginners' Area
    Replies: 1
    Last Post: 19th Jan 2005, 10:08 am

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts