<?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 : Question : How i can keep variable after quit the main function of the dll in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/question-how-i-can-keep-variable-after-quit-the-main-function-of/m-p/3779106#M51145</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If your Command is defined within a class (as it should be), any field of this class will be accessible for the Command method (or any other method of this class) each time the command is launched.&lt;/P&gt;&lt;P&gt;If you want the field(s) to be shared between different dranwings, you have to set them &lt;EM&gt;static&lt;/EM&gt; (&lt;EM&gt;Shared&lt;/EM&gt; in VB).&lt;/P&gt;</description>
    <pubDate>Wed, 13 Feb 2013 06:17:00 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2013-02-13T06:17:00Z</dc:date>
    <item>
      <title>Question : How i can keep variable after quit the main function of the dll</title>
      <link>https://forums.autodesk.com/t5/net-forum/question-how-i-can-keep-variable-after-quit-the-main-function-of/m-p/3778967#M51144</link>
      <description>&lt;P&gt;Hi .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to load my DLL, launch the function with a command. After i quit and lauch the same command. (The DLL is already in memory).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(using sessionflags.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is possible to keep the variable i have used in the the first launch for use in the second launch ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The main function is for adding block in a collection (the user select block). The programm quit, so the user can open a another dwg and run the main function for adding another&amp;nbsp; block. (i memorize name, handle, name of file etc..)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another question : it is possible to create a form in autocad but if the only active document is closed, the form is not closed and visible. ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All there question is for create a best solution for manage my collection of block.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Feb 2013 22:31:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/question-how-i-can-keep-variable-after-quit-the-main-function-of/m-p/3778967#M51144</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-02-12T22:31:33Z</dc:date>
    </item>
    <item>
      <title>Re : Question : How i can keep variable after quit the main function of the dll</title>
      <link>https://forums.autodesk.com/t5/net-forum/question-how-i-can-keep-variable-after-quit-the-main-function-of/m-p/3779106#M51145</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If your Command is defined within a class (as it should be), any field of this class will be accessible for the Command method (or any other method of this class) each time the command is launched.&lt;/P&gt;&lt;P&gt;If you want the field(s) to be shared between different dranwings, you have to set them &lt;EM&gt;static&lt;/EM&gt; (&lt;EM&gt;Shared&lt;/EM&gt; in VB).&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2013 06:17:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/question-how-i-can-keep-variable-after-quit-the-main-function-of/m-p/3779106#M51145</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2013-02-13T06:17:00Z</dc:date>
    </item>
    <item>
      <title>Re : Question : How i can keep variable after quit the main function of the dll</title>
      <link>https://forums.autodesk.com/t5/net-forum/question-how-i-can-keep-variable-after-quit-the-main-function-of/m-p/3780450#M51146</link>
      <description>&lt;P&gt;ok thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But how i can know if it is the first laucnh of the command or not ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I dont use&amp;nbsp; static variable so..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2013 12:18:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/question-how-i-can-keep-variable-after-quit-the-main-function-of/m-p/3780450#M51146</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-02-14T12:18:57Z</dc:date>
    </item>
    <item>
      <title>Re: Question : How i can keep variable after quit the main function of the dll</title>
      <link>https://forums.autodesk.com/t5/net-forum/question-how-i-can-keep-variable-after-quit-the-main-function-of/m-p/3780592#M51147</link>
      <description>&lt;P&gt;If you want data to persist between command calls within the same session of AutoCAD, you're gonna have to use static variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When describing your scenario, please be clear and differenciate program quitting (closing AutoCAD) from closing a document. You say "&lt;SPAN&gt;After i quit"; do you mean to say "After the command has ended"? There is no way to make data persist if you close the acad.exe other than external files and the clipboard.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;You also say "T&lt;SPAN&gt;he programm quit, so the user can open a another dwg and run the main function".&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;Do you mean to say "The user closes the current DWG and opens up another one where he uses the command again"&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;About your form question, you can register the event for when documents are closed within the document manager,&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;usually in the myPlugin file inside the initialize function.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;Application.DocumentManager.DocumentDestroyed += new DocumentDestroyedEventHandler(DocumentManager_DocumentDestroyed);

void DocumentManager_DocumentDestroyed(object sender, DocumentDestroyedEventArgs e)
{
  myFormClass newForm = new myFormClass();&lt;BR /&gt;  Application.ShowModalWindow(newForm);
}&lt;/PRE&gt;&lt;P&gt;The above event is for when the DWG has been completely closed, you don't have access to the document or its database anymore. The e argument only holds the name of the file destroyed. If you need to have access to the document and its database, you would need to use:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;Application.DocumentManager.DocumentToBeDestroyed += new DocumentCollectionEventHandler(DocumentManager_DocumentToBeDestroyed);

void DocumentManager_DocumentToBeDestroyed(object sender, DocumentCollectionEventArgs e)
{
  myFormClass newForm = new myFormClass();
  Application.ShowModalWindow(newForm);
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Here the sender object is the document manager, so you can cast it like this if you need to:&lt;BR /&gt;DocumentCollection newDC = sender as DocumentCollection;&lt;/P&gt;&lt;P&gt;The argument e is the document about to be destroyed. You can cast it the same way:&lt;/P&gt;&lt;P&gt;Document newDocument = e as Document;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2013 13:54:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/question-how-i-can-keep-variable-after-quit-the-main-function-of/m-p/3780592#M51147</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-02-14T13:54:26Z</dc:date>
    </item>
    <item>
      <title>Re : Question : How i can keep variable after quit the main function of the dll</title>
      <link>https://forums.autodesk.com/t5/net-forum/question-how-i-can-keep-variable-after-quit-the-main-function-of/m-p/3780999#M51149</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can try this little sample (may be self explanatory)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;

[assembly: CommandClass(typeof(PerDocumentOrSessionVariablesSample.CommandMethods))]

namespace PerDocumentOrSessionVariablesSample
{
    public class CommandMethods
    {
        private string perDocument = "perDocumentDefault";
        private static string perSession = "perSessionDefault";

        [CommandMethod("Test", CommandFlags.Session)]
        public void Test()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

            PromptStringOptions pso = new PromptStringOptions("\nEnter the per session value: ");
            pso.DefaultValue = perSession;
            pso.UseDefaultValue = true;
            PromptResult pr = ed.GetString(pso);
            if (pr.Status != PromptStatus.OK) return;
            perSession = pr.StringResult;

            pso.Message = "\nEnter the per document value: ";
            pso.DefaultValue = perDocument;
            pr = ed.GetString(pso);
            if (pr.Status != PromptStatus.OK) return;
            perDocument = pr.StringResult;

            ed.WriteMessage("\nPer session value: {0}, per document value: {1}", perSession, perDocument);
        }
    }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2013 18:08:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/question-how-i-can-keep-variable-after-quit-the-main-function-of/m-p/3780999#M51149</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2013-02-14T18:08:24Z</dc:date>
    </item>
    <item>
      <title>Re : Question : How i can keep variable after quit the main function of the dll</title>
      <link>https://forums.autodesk.com/t5/net-forum/question-how-i-can-keep-variable-after-quit-the-main-function-of/m-p/3781580#M51150</link>
      <description>&lt;P&gt;Thanks for the reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For me my app is the DLL i have loaded. Autocad is always running. I dont close Autocad.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to test all this for learn the best use of static variable.&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>Fri, 15 Feb 2013 12:01:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/question-how-i-can-keep-variable-after-quit-the-main-function-of/m-p/3781580#M51150</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-02-15T12:01:41Z</dc:date>
    </item>
  </channel>
</rss>

