<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: script end event in Visual LISP, AutoLISP and General Customization Forum</title>
    <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/script-end-event/m-p/6381418#M131561</link>
    <description>&lt;P&gt;Moshe,&lt;/P&gt;
&lt;P&gt;the autolisp code will be evalueted until the end, not stoping while the script command is running,&amp;nbsp;and the vla-sendcommand function, will send the text string to the current document, but only when it becomes the 'activedocument' (after the script command end) that text string will be evalueted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;'if&amp;nbsp;Mistakes file&amp;nbsp; is not gererated (which is more likely the case) (vla-sendCommand ....) is invoked anyway'&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, the command was sent when the autolisp code&amp;nbsp;was evalueted.&lt;/P&gt;
&lt;P&gt;Using sendcommand, we can call a sub-function to check &lt;EM&gt;Mistakes file &lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;i.e.&lt;/P&gt;
&lt;PRE&gt;(defun TheTest nil
   (if (not (findfile MistakesFile))
      (alert "The program have ran without errors... ")
      (startapp "notepad" MistakesFile)
   )
   (princ)
)&lt;/PRE&gt;
&lt;P&gt;and&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;(vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) "(TheTest)\r")&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps, &lt;BR /&gt;Henrique&lt;/P&gt;</description>
    <pubDate>Mon, 13 Jun 2016 22:59:02 GMT</pubDate>
    <dc:creator>hmsilva</dc:creator>
    <dc:date>2016-06-13T22:59:02Z</dc:date>
    <item>
      <title>script end event</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/script-end-event/m-p/6378939#M131556</link>
      <description>&lt;P&gt;Hi Guys,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;have a custom application that generates a script file, it's goal is to open a list of dwg files and runs a lisp command to modify each dwg and save and close&amp;nbsp;and at the end of generating the script i call it to run.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;my problem is how do i know when the script is done? so i can alert the user about mistakes during the script run&lt;/P&gt;
&lt;P&gt;it look like autolisp finishing running all the lisp code before it runs the script&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i even defined a lisp reactor&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(vlr-lisp-reactor nil '((:vlr-lispEnded . OnLispEnded)))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;to trap the end of script base on CMDACTIVE but it also invokes before the script&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;would appriciate any help&lt;/P&gt;
&lt;P&gt;Moshe&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Jun 2016 09:05:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/script-end-event/m-p/6378939#M131556</guid>
      <dc:creator>Moshe-A</dc:creator>
      <dc:date>2016-06-12T09:05:46Z</dc:date>
    </item>
    <item>
      <title>Re: script end event</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/script-end-event/m-p/6379372#M131557</link>
      <description>&lt;P&gt;Guys,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Found a solution to this and i happy to share it with you, cause i think it is unique. i also found a special behaviuor in running script that i was unaware of and i have been googling for some hours and could not found any reference to this, so if some one has an &lt;SPAN&gt;official &lt;/SPAN&gt;reference to this from Autodesk, i would like to know (please send me a link)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;what i did is creating a text file for &lt;EM&gt;Mistakes&lt;/EM&gt;&amp;nbsp;which occurs during script (instead of sending a message to the screen) but the problem still was how to display this contents file? and i did add a command at the end of the script to open it in notepad but autocad did not launch it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;here comes the special behaviour (or weird depends on how you look on it) it turns out that if you use the OPEN command in script (then do some draw/modification work) and CLOSE the file, the next command AutoCAD is expecting is OPEN another file (or finish the script) cause no other command is allowed between the last CLOSE and OPEN. if you do? the script is terminated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;so to solved this i add the NEW command to script and opened an empty drawing, called a special command to open &lt;EM&gt;Mistakes file&lt;/EM&gt; using (startapp)&lt;/P&gt;
&lt;P&gt;and CLOSE it and I got &lt;EM&gt;Mistakes file&lt;/EM&gt; opened in notpad right in front of user eyes&amp;nbsp;&lt;img id="smileyvery-happy" class="emoticon emoticon-smileyvery-happy" src="https://forums.autodesk.com/i/smilies/16x16_smiley-very-happy.png" alt="Smiley Very Happy" title="Smiley Very Happy" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Moshe&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Jun 2016 19:57:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/script-end-event/m-p/6379372#M131557</guid>
      <dc:creator>Moshe-A</dc:creator>
      <dc:date>2016-06-12T19:57:32Z</dc:date>
    </item>
    <item>
      <title>Re: script end event</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/script-end-event/m-p/6379979#M131558</link>
      <description>&lt;P&gt;Hello Moashe,&lt;/P&gt;
&lt;P&gt;thank you for sharing with us your solution!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What has occurred to me, if the current dwg remain open after run the script file, was to use 'vla-sendcommand' to call the 'startapp' function after the "_.script" command.&lt;/P&gt;
&lt;P&gt;In this case, the 'vla-sendcommand' function would be call when the script ends and the 'focus' would return to the 'original' dwg...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As a demo:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;;; Load Supporting Functions
;; Old Version of 'BrowseForFolder' by: Tony Tanzillo 
(defun BrowseForFolder (Message / sh folder parentfolder folderobject result)
   (vl-load-com)
   (setq sh (vla-getInterfaceObject (vlax-get-acad-object) "Shell.Application"))
   (setq folder (vlax-invoke-method sh 'BrowseForFolder 0 Message 0))
   (vlax-release-object sh)
   (if folder
      (progn
         (setq parentfolder (vlax-get-property folder 'ParentFolder))
         (setq FolderObject (vlax-invoke-method ParentFolder 'ParseName (vlax-get-property Folder 'Title)))
         (setq result (vlax-get-property FolderObject 'Path))
         (mapcar 'vlax-release-object
                 (list folder parentfolder folderobject)
         )
         (if (/= (substr result (strlen result)) "\\")
            (setq result (strcat result "\\"))
            result
         )
      )
   )
)


(defun c:demo (/ DirPath DwgFile DwgList Ofile );Scrfile
   (if (setq DirPath (BrowseForFolder "Select directory to scan drawings."))
      (progn
         (setq Scrfile (strcat DirPath "test.scr"))
         (setq ofile (open Scrfile "w"))
         (setq DwgList (vl-directory-files DirPath "*.dwg" 1))
         (foreach Dwg DwgList
            (setq DwgFile (strcat DirPath Dwg))
            (write-line (strcat "_.open\r" (chr 34) DwgFile (chr 34) "\r") Ofile)
            (write-line "_.zoom\r_e\r" Ofile)
            (write-line (strcat "_.saveas\r\r" (chr 34) DwgFile (chr 34) "\rYes\r") ofile)
            (write-line "_.close\r" Ofile)
         )
         (close Ofile)
         (command "_.script" Scrfile)
         (vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) "(startapp \"notepad\" Scrfile)\r")
      )
   )
   (princ)
)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps, &lt;BR /&gt;Henrique&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jun 2016 10:53:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/script-end-event/m-p/6379979#M131558</guid>
      <dc:creator>hmsilva</dc:creator>
      <dc:date>2016-06-13T10:53:30Z</dc:date>
    </item>
    <item>
      <title>Re: script end event</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/script-end-event/m-p/6380738#M131559</link>
      <description>&lt;P&gt;Henrique hey,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;yes you are right, it's working&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;have you got an explantion on how&amp;nbsp;autolisp is doing&amp;nbsp;this?&lt;/P&gt;
&lt;P&gt;how can i know&amp;nbsp;what i can or can not do with lisp combining script?&lt;/P&gt;
&lt;P&gt;it took me&amp;nbsp;long time to figure out the solution i have presented.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks,&lt;/P&gt;
&lt;P&gt;Moshe&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jun 2016 16:35:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/script-end-event/m-p/6380738#M131559</guid>
      <dc:creator>Moshe-A</dc:creator>
      <dc:date>2016-06-13T16:35:57Z</dc:date>
    </item>
    <item>
      <title>Re: script end event</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/script-end-event/m-p/6381179#M131560</link>
      <description>&lt;P&gt;Henrique,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;here is an update, it is not quite working&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if&amp;nbsp;&lt;EM&gt;Mistakes file&lt;/EM&gt;&amp;nbsp; is not gererated (which is more likely the case) (vla-sendCommand ....) is invoked anyway&lt;/P&gt;
&lt;P&gt;even if i check for the existence of the file (findfile) the result is notepad opens and complains,&amp;nbsp;file is not exist?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Moshe&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jun 2016 20:15:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/script-end-event/m-p/6381179#M131560</guid>
      <dc:creator>Moshe-A</dc:creator>
      <dc:date>2016-06-13T20:15:05Z</dc:date>
    </item>
    <item>
      <title>Re: script end event</title>
      <link>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/script-end-event/m-p/6381418#M131561</link>
      <description>&lt;P&gt;Moshe,&lt;/P&gt;
&lt;P&gt;the autolisp code will be evalueted until the end, not stoping while the script command is running,&amp;nbsp;and the vla-sendcommand function, will send the text string to the current document, but only when it becomes the 'activedocument' (after the script command end) that text string will be evalueted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;'if&amp;nbsp;Mistakes file&amp;nbsp; is not gererated (which is more likely the case) (vla-sendCommand ....) is invoked anyway'&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, the command was sent when the autolisp code&amp;nbsp;was evalueted.&lt;/P&gt;
&lt;P&gt;Using sendcommand, we can call a sub-function to check &lt;EM&gt;Mistakes file &lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;i.e.&lt;/P&gt;
&lt;PRE&gt;(defun TheTest nil
   (if (not (findfile MistakesFile))
      (alert "The program have ran without errors... ")
      (startapp "notepad" MistakesFile)
   )
   (princ)
)&lt;/PRE&gt;
&lt;P&gt;and&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;(vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) "(TheTest)\r")&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps, &lt;BR /&gt;Henrique&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jun 2016 22:59:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/script-end-event/m-p/6381418#M131561</guid>
      <dc:creator>hmsilva</dc:creator>
      <dc:date>2016-06-13T22:59:02Z</dc:date>
    </item>
  </channel>
</rss>

