::Close

Discussion in 'AutoCAD' started by Rick Keller, Nov 1, 2004.

  1. Rick Keller

    Rick Keller Guest

    I am familar with the s::startup function but didnt there used to be a
    s::close function?

    Where can I find this in the help files?

    Where would be the best place to define it... In the acaddoc.lsp?


    Rick
     
    Rick Keller, Nov 1, 2004
    #1
  2. Rick Keller

    Jürg Menzi Guest

    Hi Rick

    No way with s::Close...
    Use a reactor instead. You may find a hint in my homepage -> Free Stuff ->
    AcadDoc.lsp

    Cheers
     
    Jürg Menzi, Nov 1, 2004
    #2
  3. Rick Keller

    Rick Keller Guest

    Thanks I'll have a look...
    I have been wanting to look into reactors for awhile now.

    But there was a s::close wasn't there?

    Rick
     
    Rick Keller, Nov 1, 2004
    #3
  4. Rick Keller

    Tom Smith Guest

    Never heard of one in plain Acad.
     
    Tom Smith, Nov 1, 2004
    #4
  5. Rick Keller

    Ian A. White Guest

    There was some discussion on this and I believe it was in a beta release
    many versions ago. At one stage there was talk of s::quit, and s::save
    so that user routines could carry out tasks to update things like
    external databases etc, however it never made it into a production
    release.
     
    Ian A. White, Nov 1, 2004
    #5
  6. Rick Keller

    Rick Keller Guest

    Right... It was something like that. I think it was about ver 10 - 12.

    I never needed it before, but now on exit I want to copy the temporary .sv$
    file to another name
    so I have it.

    Rick
     
    Rick Keller, Nov 1, 2004
    #6
  7. Rick Keller

    Ian A. White Guest

    You will need to use a reactor that is triggered when the drawing is
    about to close, then move the file and carry on with the close. One
    limitation of a reactor is that you cannot use the (command) function.
    You can get around this by using the (vla-sendcommand) function feeding
    it the parameters you want.
     
    Ian A. White, Nov 2, 2004
    #7
  8. Rick Keller

    Jürg Menzi Guest

    Hi Rick

    You may have a look to this (untested) code:
    Code:
    
    ; -- AcadDoc.lsp
    ; Sets a DocManager Reactor to copy the temporary .sv$ at the end of a AutoCAD
    ; session.
    ; Copyright:
    ;   ©2004 MENZI ENGINEERING GmbH, Switzerland
    ; Notes:
    ;   - Not tested
    ;
    ; - Initialize ActiveX support
    (vl-load-com)
    
    ; - If not set, initialize DocManager-Reactor
    (or
    Me:ReaDma
    (setq Me:ReaDma (VLR-DocManager-Reactor
    nil
    '(
    (:VLR-documentToBeDestroyed . MeDocToBeDestroyedCallbacks)
    )
    )
    )
    )
    
    ; - DocToBeDestroyed notifications
    (defun MeDocToBeDestroyedCallbacks (Rea Arg)
    (MeCopyTempFile)
    (MeDoCloseStuff)
    (princ)
    )
    
    ; - Reactor cleanup function
    (defun MeDoCloseStuff ( / VarLst)
    (setq VarLst (MeGetReaVars))
    (mapcar 'VLR-remove (mapcar 'eval VarLst))
    (mapcar '(lambda (l) (set l nil)) VarLst)
    (princ)
    )
    
    ; - Collect global reactor variables
    (defun MeGetReaVars ( / RetVal)
    (foreach memb (atoms-family 1)
    (if (wcmatch (strcase memb) "ME:REA*")
    (setq RetVal (cons memb RetVal))
    )
    )
    (mapcar 'read RetVal)
    )
    
    ; - Copies the temporary file to another name
    (defun MeCopyTempFile ( / DwgNme SrcNme TarNme)
    (setq DwgNme (vla-get-FullName
    (vla-get-ActiveDocument (vlax-get-acad-object))
    )
    )
    (if (not (eq DwgNme "")) ;saved
    (progn
    (setq SrcNme (strcat (vl-filename-base DwgNme) ".sv$")
    TarNme "TheFileNameYouWant"
    )
    (if (findfile SrcNme) (MeCopyFiles SrcNme TarNme))
    )
    )
    (princ)
    )
    
    ; - Copies the specified file(s).
    (defun MeCopyFiles (Src Tar / ErrObj FilSys RetVal)
    (setq FilSys (vlax-create-object "Scripting.FileSystemObject")
    ErrObj (vl-catch-all-apply
    'vlax-invoke-method
    (list FilSys 'CopyFile Src Tar :vlax-true)
    )
    RetVal (not (vl-catch-all-error-p ErrObj))
    )
    (vlax-release-object FilSys)
    RetVal
    )
    
    (princ)
    ;
    ; -- End AcadDoc.lsp
    
    Cheers
     
    Jürg Menzi, Nov 2, 2004
    #8
  9. Rick Keller

    Rick Keller Guest

    Well it'll be my first reactor Jurg had something on his website and I am
    checking out the stuff at the afralisp site about reactors.

    Here is a rough draft of what I am wanting to put into it.

    (setq tmpname (getvar "savefile"))
    (setq lengthofstring (strlen tmpname))
    (setq shortname (substr tmpname 1 (- lengthofstring 4)))
    (setq newsavename (strcat shortname ".rgk"))
    (vl-file-delete newsavename)
    (vl-file-copy tmpname newsavename)

    Rick
     
    Rick Keller, Nov 2, 2004
    #9
  10. Rick Keller

    Rick Keller Guest

    Thanks Jürg,

    It didnt seem to copy the sv$ file but I changed some of the code and it
    seems to do what I want.
    Here is the changed code.

    I didn't cause any unseen problems did I?

    Thanks Again,

    Rick


    ; -- AcadDoc.lsp
    ; Sets a DocManager Reactor to copy the temporary .sv$ at the end of a
    AutoCAD
    ; session.
    ; Copyright:
    ; ©2004 MENZI ENGINEERING GmbH, Switzerland
    ; Notes:
    ; - Not tested
    ;
    ; - Initialize ActiveX support
    (vl-load-com)

    ; - If not set, initialize DocManager-Reactor
    (or
    Me:ReaDma
    (setq Me:ReaDma (VLR-DocManager-Reactor
    nil
    '(
    :)VLR-documentToBeDestroyed .
    MeDocToBeDestroyedCallbacks)
    )
    )
    )
    )

    ; - DocToBeDestroyed notifications
    (defun MeDocToBeDestroyedCallbacks (Rea Arg)
    (MeCopyTempFile)
    (MeDoCloseStuff)
    (princ)
    )

    ; - Reactor cleanup function
    (defun MeDoCloseStuff ( / VarLst)
    (setq VarLst (MeGetReaVars))
    (mapcar 'VLR-remove (mapcar 'eval VarLst))
    (mapcar '(lambda (l) (set l nil)) VarLst)
    (princ)
    )

    ; - Collect global reactor variables
    (defun MeGetReaVars ( / RetVal)
    (foreach memb (atoms-family 1)
    (if (wcmatch (strcase memb) "ME:REA*")
    (setq RetVal (cons memb RetVal))
    )
    )
    (mapcar 'read RetVal)
    )

    ; - Copies the temporary file to another name
    (defun MeCopyTempFile ( / tmpname lengthofstring shortname newsavename)


    (setq tmpname (getvar "savefile"))
    lengthofstring (strlen tmpname)
    shortname (substr tmpname 1 (- lengthofstring 4)))
    newsavename (strcat shortname ".rgk"))

    (vl-file-delete newsavename)
    (vl-file-copy tmpname newsavename)
    (princ)
    )
    ;
    ; -- End AcadDoc.lsp








     
    Rick Keller, Nov 2, 2004
    #10
  11. Rick Keller

    Rick Keller Guest

    Thanks Jürg,

    It didnt seem to copy the sv$ file but I changed some of the code and it
    seems to do what I want. But only if I answer no to the save file exit box.

    I would like it to save it no matter what.

    Here is the changed code.

    I didn't cause any unseen problems did I?

    Thanks Again,

    Rick


    ; -- AcadDoc.lsp
    ; Sets a DocManager Reactor to copy the temporary .sv$ at the end of a
    AutoCAD
    ; session.
    ; Copyright:
    ; ©2004 MENZI ENGINEERING GmbH, Switzerland
    ; Notes:
    ; - Not tested
    ;
    ; - Initialize ActiveX support
    (vl-load-com)

    ; - If not set, initialize DocManager-Reactor
    (or
    Me:ReaDma
    (setq Me:ReaDma (VLR-DocManager-Reactor
    nil
    '(
    :)VLR-documentToBeDestroyed .
    MeDocToBeDestroyedCallbacks)
    )
    )
    )
    )

    ; - DocToBeDestroyed notifications
    (defun MeDocToBeDestroyedCallbacks (Rea Arg)
    (MeCopyTempFile)
    (MeDoCloseStuff)
    (princ)
    )

    ; - Reactor cleanup function
    (defun MeDoCloseStuff ( / VarLst)
    (setq VarLst (MeGetReaVars))
    (mapcar 'VLR-remove (mapcar 'eval VarLst))
    (mapcar '(lambda (l) (set l nil)) VarLst)
    (princ)
    )

    ; - Collect global reactor variables
    (defun MeGetReaVars ( / RetVal)
    (foreach memb (atoms-family 1)
    (if (wcmatch (strcase memb) "ME:REA*")
    (setq RetVal (cons memb RetVal))
    )
    )
    (mapcar 'read RetVal)
    )

    ; - Copies the temporary file to another name
    (defun MeCopyTempFile ( / tmpname lengthofstring shortname newsavename)


    (setq tmpname (getvar "savefile")
    lengthofstring (strlen tmpname)
    shortname (substr tmpname 1 (- lengthofstring 4))
    newsavename (strcat shortname ".rgk")
    )

    (vl-file-copy tmpname newsavename)
    (princ)
    )
    ;
    ; -- End AcadDoc.lsp
     
    Rick Keller, Nov 2, 2004
    #11
  12. Rick Keller

    Jürg Menzi Guest

    Hi Rick

    Welcome...¦-)
    Hmmmm... the VLR-documentToBeDestroyed reactor fires on closing the document,
    independent from save or exit...

    And a suggestion for this function:
    Code:
    ; - Copies the temporary file to another name
    (defun MeCopyTempFile ( / tmpname newsavename)
    (setq tmpname (getvar "savefile"))
    (if (not (eq tmpname) "")
    (progn
    (setq newsavename (strcat
    (vl-filename-directory tmpname) "\\"
    (vl-filename-base tmpname) ".rgk"
    )
    )
    (vl-file-copy tmpname newsavename)
    )
    )
    (princ)
    )
    
    Cheers
     
    Jürg Menzi, Nov 2, 2004
    #12
  13. Rick Keller

    Rick Keller Guest

    I'll try the suggestion...
    I guess I really don't need it when "yes" is selected.
    One of my biggest peeves with acad is it deletes the autosave file when acad
    exits without error.
    There have been a few times I have closed drawings quickly and answered "no"
    to the question and lost what I have done.
    I know it is very stupid but... Now I have found a way around the problem.
    I'll tell you one thing you only do it a couple of times before you are very
    careful before pressing the buttons.

    Thanks again,
    Rick


     
    Rick Keller, Nov 2, 2004
    #13
  14. Rick Keller

    Rick Keller Guest

    Ok... for anyone following along...
    The line:
    (if (not (eq tmpname) "")

    in the last function should be...

    (if (not (eq tmpname ""))

    Rick

     
    Rick Keller, Nov 2, 2004
    #14
  15. Rick Keller

    Rick Keller Guest

    It also doesn't fire if you save your drawing and then exit.

    Rick



     
    Rick Keller, Nov 2, 2004
    #15
  16. Rick Keller

    Jürg Menzi Guest

    Hi Rick
    Sorry, I hadn't the time to check things I've written.

    Cheers
     
    Jürg Menzi, Nov 2, 2004
    #16
  17. Rick Keller

    Jürg Menzi Guest

    Hi Rick
    The reactor fires but because the save command reset 'savefile' to "" nothing
    will be copied.

    Cheers
     
    Jürg Menzi, Nov 2, 2004
    #17
  18. Rick Keller

    Rick Keller Guest

    Its ok that was an easy one to fix.
    The code you supplied is working great.

    I started wondering why it wasn't working at all & figured it out.

    I'm trying to play with reactors now... I havent figured anything out yet
    but I will.

    Rick
     
    Rick Keller, Nov 2, 2004
    #18
  19. Rick Keller

    Jürg Menzi Guest

    Hi Rick

    Glad to help you...:cool:
    The 'garden path' tutorial can be very helpful for reactor beginners.

    Cheers
     
    Jürg Menzi, Nov 3, 2004
    #19
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.