<?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: cuiload from .NET dll in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/cuiload-from-net-dll/m-p/2609953#M67748</link>
    <description>Thanks to both of you!&lt;BR /&gt;
Your hints are most helpful!&lt;BR /&gt;
I did not know that Acad instantiates the class for every single document. You are right that all the methods should be static.&lt;BR /&gt;
The final goal achieved is a program that is installed just with xcopy that reconstructs its Cui when it detects the update of the dll holding the command methods. Making it that way saves a lot of maintenance work of the installations on multiple computers in one office.</description>
    <pubDate>Mon, 04 Jan 2010 07:43:12 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2010-01-04T07:43:12Z</dc:date>
    <item>
      <title>cuiload from .NET dll</title>
      <link>https://forums.autodesk.com/t5/net-forum/cuiload-from-net-dll/m-p/2609950#M67745</link>
      <description>Hi, &lt;BR /&gt;
Can anybody explain the strange behavior  of this peace of code.&lt;BR /&gt;
This .dll is registered in order to load on startup.&lt;BR /&gt;
{code}&lt;BR /&gt;
Windows Registry Editor Version 5.00&lt;BR /&gt;
[HKEY_LOCAL_MACHINE\Software\Autodesk\AutoCAD\R17.1\ACAD-6001:409\Applications\TestCAD2]&lt;BR /&gt;
"DESCRIPTION"="Ognyans test app"&lt;BR /&gt;
"LOADCTRLS"=dword:00000002&lt;BR /&gt;
"MANAGED"=dword:00000001&lt;BR /&gt;
"LOADER"="C:\\work\\LocalTestProjects\\acad_CUI\\acad_CUI\\bin\\Debug\\acad_CUI.dll"&lt;BR /&gt;
{code}&lt;BR /&gt;
&lt;BR /&gt;
1. When I comment out the "initialize" method the module is starting but the class constructor (Class1) is not starting until I invoke "c1" or "c2".&lt;BR /&gt;
2. When I don`t comment out anything the program "brakes" in the initialize method in the line &lt;BR /&gt;
doc.SendStringToExecute("_.cuiload " + cuiFile + " ", false, false, false); but Autocad continues to work without error prompt, but no CUI is loaded.&lt;BR /&gt;
3. After deleting the registry info and when I netload the .dll without commenting out any code the initialize method the .dll is loaded and the cui is loaded - everything is fine.&lt;BR /&gt;
c1 command is working fine when netload-ed by hand.&lt;BR /&gt;
&lt;BR /&gt;
Why is that? To me it looks like that Acad cant receive the command for loading the cui before it loads some other stuff after. &lt;BR /&gt;
If you place a message in the initialize method the message will appear before the last Acad default console messages.&lt;BR /&gt;
Is there a way to tell the initialize method to wait until Acad is ready to receive?&lt;BR /&gt;
&lt;BR /&gt;
{code}&lt;BR /&gt;
using System;&lt;BR /&gt;
using System.Collections.Generic;&lt;BR /&gt;
using System.Text;&lt;BR /&gt;
using Autodesk.AutoCAD.ApplicationServices;&lt;BR /&gt;
using Autodesk.AutoCAD.DatabaseServices;&lt;BR /&gt;
using Autodesk.AutoCAD.EditorInput;&lt;BR /&gt;
using Autodesk.AutoCAD.Runtime;&lt;BR /&gt;
using Autodesk.AutoCAD.Customization;&lt;BR /&gt;
&lt;BR /&gt;
namespace ClassLibrary1&lt;BR /&gt;
{&lt;BR /&gt;
    public class Class1 : IExtensionApplication&lt;BR /&gt;
    {       &lt;BR /&gt;
        public Class1()&lt;BR /&gt;
        {                    &lt;BR /&gt;
            //throw new System.Exception("The method or operation is not implemented.");&lt;BR /&gt;
            string cuiFile = "C:\\test.cui";&lt;BR /&gt;
            Document doc = Application.DocumentManager.MdiActiveDocument;&lt;BR /&gt;
            object oldCmdEcho = Application.GetSystemVariable("CMDECHO");&lt;BR /&gt;
            object oldFileDia = Application.GetSystemVariable("FILEDIA");&lt;BR /&gt;
            Application.SetSystemVariable("CMDECHO", 0);&lt;BR /&gt;
            Application.SetSystemVariable("FILEDIA", 0);&lt;BR /&gt;
            doc.SendStringToExecute("_.cuiload " + cuiFile + " ", false, false, false);&lt;BR /&gt;
            doc.SendStringToExecute("(setvar \"FILEDIA\" " + oldFileDia.ToString() + ")(princ) ", false, false, false);&lt;BR /&gt;
            doc.SendStringToExecute("(setvar \"CMDECHO\" " + oldCmdEcho.ToString() + ")(princ) ", false, false, false);        &lt;BR /&gt;
        }      &lt;BR /&gt;
        [CommandMethod("c1")]&lt;BR /&gt;
        public void c1()&lt;BR /&gt;
        {&lt;BR /&gt;
            string cuiFile = "C:\\test.cui";&lt;BR /&gt;
            Document doc = Application.DocumentManager.MdiActiveDocument;&lt;BR /&gt;
            object oldCmdEcho = Application.GetSystemVariable("CMDECHO");&lt;BR /&gt;
            object oldFileDia = Application.GetSystemVariable("FILEDIA");&lt;BR /&gt;
            Application.SetSystemVariable("CMDECHO", 0);&lt;BR /&gt;
            Application.SetSystemVariable("FILEDIA", 0);&lt;BR /&gt;
            doc.SendStringToExecute("_.cuiload " + cuiFile + " ", false, false, false);&lt;BR /&gt;
            doc.SendStringToExecute("(setvar \"FILEDIA\" " + oldFileDia.ToString() + ")(princ) ", false, false, false);&lt;BR /&gt;
            doc.SendStringToExecute("(setvar \"CMDECHO\" " + oldCmdEcho.ToString() + ")(princ) ", false, false, false);&lt;BR /&gt;
        }&lt;BR /&gt;
&lt;BR /&gt;
        [CommandMethod("c2")]&lt;BR /&gt;
        public void c2()&lt;BR /&gt;
        {&lt;BR /&gt;
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Hello World!");&lt;BR /&gt;
        }&lt;BR /&gt;
&lt;BR /&gt;
        #region IExtensionApplication Members&lt;BR /&gt;
        void IExtensionApplication.Initialize()&lt;BR /&gt;
        {&lt;BR /&gt;
            //throw new System.Exception("The method or operation is not implemented.");&lt;BR /&gt;
            string cuiFile = "C:\\test.cui";&lt;BR /&gt;
            Document doc = Application.DocumentManager.MdiActiveDocument;&lt;BR /&gt;
            object oldCmdEcho = Application.GetSystemVariable("CMDECHO");&lt;BR /&gt;
            object oldFileDia = Application.GetSystemVariable("FILEDIA");&lt;BR /&gt;
            Application.SetSystemVariable("CMDECHO", 0);&lt;BR /&gt;
            Application.SetSystemVariable("FILEDIA", 0);&lt;BR /&gt;
            doc.SendStringToExecute("_.cuiload " + cuiFile + " ", false, false, false);&lt;BR /&gt;
            doc.SendStringToExecute("(setvar \"FILEDIA\" " + oldFileDia.ToString() + ")(princ) ", false, false, false);&lt;BR /&gt;
            doc.SendStringToExecute("(setvar \"CMDECHO\" " + oldCmdEcho.ToString() + ")(princ) ", false, false, false);&lt;BR /&gt;
        }&lt;BR /&gt;
        void IExtensionApplication.Terminate()&lt;BR /&gt;
        {&lt;BR /&gt;
            throw new System.Exception("The method or operation is not implemented.");&lt;BR /&gt;
        }&lt;BR /&gt;
        #endregion&lt;BR /&gt;
    }&lt;BR /&gt;
}&lt;BR /&gt;
{code}</description>
      <pubDate>Sat, 02 Jan 2010 16:29:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/cuiload-from-net-dll/m-p/2609950#M67745</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-01-02T16:29:11Z</dc:date>
    </item>
    <item>
      <title>Re: cuiload from .NET dll</title>
      <link>https://forums.autodesk.com/t5/net-forum/cuiload-from-net-dll/m-p/2609951#M67746</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I suppose you can't invoke SendStringToExecute before the the document initialization is completed.&lt;BR /&gt;
&lt;BR /&gt;
You can make a CuiLoad method using COM interop.&lt;BR /&gt;
&lt;BR /&gt;
Here's an example:&lt;BR /&gt;
{code}&lt;BR /&gt;
private void CuiLoad(string filename, string menuGroup)&lt;BR /&gt;
{&lt;BR /&gt;
    AcadApplication acadApp = (AcadApplication)Application.AcadApplication;&lt;BR /&gt;
    AcadMenuGroups menus = acadApp.MenuGroups;&lt;BR /&gt;
    try&lt;BR /&gt;
    {&lt;BR /&gt;
        menus.Item(menuGroup);&lt;BR /&gt;
    }&lt;BR /&gt;
    catch&lt;BR /&gt;
    {&lt;BR /&gt;
        menus.Load(filename, false);&lt;BR /&gt;
    }&lt;BR /&gt;
}{code}&lt;BR /&gt;
using:&lt;BR /&gt;
CuiLoad("C:\\test.cui", "TEST");&lt;BR /&gt;
&lt;BR /&gt;
Or, if you want to add a popup menu to the end of the the menu bar:&lt;BR /&gt;
{code}&lt;BR /&gt;
private void CuiLoad(string filename, string menuGroup, string menuName)&lt;BR /&gt;
{&lt;BR /&gt;
    AcadApplication acadApp = (AcadApplication)Application.AcadApplication;&lt;BR /&gt;
    AcadMenuGroups menus = acadApp.MenuGroups;&lt;BR /&gt;
    try&lt;BR /&gt;
    {&lt;BR /&gt;
        menus.Item(menuGroup);&lt;BR /&gt;
    }&lt;BR /&gt;
    catch&lt;BR /&gt;
    {&lt;BR /&gt;
        menus.Load(filename, false);&lt;BR /&gt;
        AcadMenuBar mnuBar = acadApp.MenuBar;&lt;BR /&gt;
        menus.Item(menuGroup).Menus.Item(menuName).InsertInMenuBar(mnuBar.Count);&lt;BR /&gt;
    }&lt;BR /&gt;
}{code}&lt;BR /&gt;
&lt;BR /&gt;
using:&lt;BR /&gt;
CuiLoad("C:\\test.cui", "TEST", "&amp;amp;Test")

Edited by: _gile on Jan 2, 2010 7:48 PM</description>
      <pubDate>Sat, 02 Jan 2010 18:24:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/cuiload-from-net-dll/m-p/2609951#M67746</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2010-01-02T18:24:03Z</dc:date>
    </item>
    <item>
      <title>Re: cuiload from .NET dll</title>
      <link>https://forums.autodesk.com/t5/net-forum/cuiload-from-net-dll/m-p/2609952#M67747</link>
      <description>When you apply the CommandMethod attribute to a non-static method, AutoCAD's &lt;BR /&gt;
managed runtime will create multiple instances of your class, one for each &lt;BR /&gt;
document that you invoke the command in.  Those instances are not created until &lt;BR /&gt;
you invoke the command.&lt;BR /&gt;
&lt;BR /&gt;
The problem you have is that AutoCAD's managed runtime also creates an instance &lt;BR /&gt;
of the class with the IExtensionApplication attribute on it as well, so multiple &lt;BR /&gt;
instances of your class are getting created, which obviously wasn't your &lt;BR /&gt;
intention.&lt;BR /&gt;
&lt;BR /&gt;
For one thing, it's not wise to implement commands in the same class that &lt;BR /&gt;
implements IExtensionApplication, but if you really wanted to do that, you could &lt;BR /&gt;
if you make the command handler methods static. If you're not sure about the &lt;BR /&gt;
difference between static and non-static (or 'instance') methods, get a hold of &lt;BR /&gt;
some basic C# learning materials, and try to become more familar with the basic &lt;BR /&gt;
concepts that underly the tools you're working with.&lt;BR /&gt;
&lt;BR /&gt;
To solve your immediate probelm, just create another class for the commands, and &lt;BR /&gt;
unless you want AutoCAD to create multiple, per-document instances of the class, &lt;BR /&gt;
declare the methods that have the CommandMethod attribute as static methods.&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2010&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");&lt;BR /&gt;
&lt;BR /&gt;
&lt;OGNYANDIM&gt; wrote in message news:6311255@discussion.autodesk.com...&lt;BR /&gt;
Hi,&lt;BR /&gt;
Can anybody explain the strange behavior  of this peace of code.&lt;BR /&gt;
This .dll is registered in order to load on startup.&lt;BR /&gt;
{code}&lt;BR /&gt;
Windows Registry Editor Version 5.00&lt;BR /&gt;
[HKEY_LOCAL_MACHINE\Software\Autodesk\AutoCAD\R17.1\ACAD-6001:409\Applications\TestCAD2]&lt;BR /&gt;
"DESCRIPTION"="Ognyans test app"&lt;BR /&gt;
"LOADCTRLS"=dword:00000002&lt;BR /&gt;
"MANAGED"=dword:00000001&lt;BR /&gt;
"LOADER"="C:\\work\\LocalTestProjects\\acad_CUI\\acad_CUI\\bin\\Debug\\acad_CUI.dll"&lt;BR /&gt;
{code}&lt;BR /&gt;
&lt;BR /&gt;
1. When I comment out the "initialize" method the module is starting but the &lt;BR /&gt;
class constructor (Class1) is not starting until I invoke "c1" or "c2".&lt;BR /&gt;
2. When I don`t comment out anything the program "brakes" in the initialize &lt;BR /&gt;
method in the line&lt;BR /&gt;
doc.SendStringToExecute("_.cuiload " + cuiFile + " ", false, false, false); but &lt;BR /&gt;
Autocad continues to work without error prompt, but no CUI is loaded.&lt;BR /&gt;
3. After deleting the registry info and when I netload the .dll without &lt;BR /&gt;
commenting out any code the initialize method the .dll is loaded and the cui is &lt;BR /&gt;
loaded - everything is fine.&lt;BR /&gt;
c1 command is working fine when netload-ed by hand.&lt;BR /&gt;
&lt;BR /&gt;
Why is that? To me it looks like that Acad cant receive the command for loading &lt;BR /&gt;
the cui before it loads some other stuff after.&lt;BR /&gt;
If you place a message in the initialize method the message will appear before &lt;BR /&gt;
the last Acad default console messages.&lt;BR /&gt;
Is there a way to tell the initialize method to wait until Acad is ready to &lt;BR /&gt;
receive?&lt;BR /&gt;
&lt;BR /&gt;
{code}&lt;BR /&gt;
using System;&lt;BR /&gt;
using System.Collections.Generic;&lt;BR /&gt;
using System.Text;&lt;BR /&gt;
using Autodesk.AutoCAD.ApplicationServices;&lt;BR /&gt;
using Autodesk.AutoCAD.DatabaseServices;&lt;BR /&gt;
using Autodesk.AutoCAD.EditorInput;&lt;BR /&gt;
using Autodesk.AutoCAD.Runtime;&lt;BR /&gt;
using Autodesk.AutoCAD.Customization;&lt;BR /&gt;
&lt;BR /&gt;
namespace ClassLibrary1&lt;BR /&gt;
{&lt;BR /&gt;
    public class Class1 : IExtensionApplication&lt;BR /&gt;
    {&lt;BR /&gt;
        public Class1()&lt;BR /&gt;
        {&lt;BR /&gt;
            //throw new System.Exception("The method or operation is not &lt;BR /&gt;
implemented.");&lt;BR /&gt;
            string cuiFile = "C:\\test.cui";&lt;BR /&gt;
            Document doc = Application.DocumentManager.MdiActiveDocument;&lt;BR /&gt;
            object oldCmdEcho = Application.GetSystemVariable("CMDECHO");&lt;BR /&gt;
            object oldFileDia = Application.GetSystemVariable("FILEDIA");&lt;BR /&gt;
            Application.SetSystemVariable("CMDECHO", 0);&lt;BR /&gt;
            Application.SetSystemVariable("FILEDIA", 0);&lt;BR /&gt;
            doc.SendStringToExecute("_.cuiload " + cuiFile + " ", false, false, &lt;BR /&gt;
false);&lt;BR /&gt;
            doc.SendStringToExecute("(setvar \"FILEDIA\" " + &lt;BR /&gt;
oldFileDia.ToString() + ")(princ) ", false, false, false);&lt;BR /&gt;
            doc.SendStringToExecute("(setvar \"CMDECHO\" " + &lt;BR /&gt;
oldCmdEcho.ToString() + ")(princ) ", false, false, false);&lt;BR /&gt;
        }&lt;BR /&gt;
        [CommandMethod("c1")]&lt;BR /&gt;
        public void c1()&lt;BR /&gt;
        {&lt;BR /&gt;
            string cuiFile = "C:\\test.cui";&lt;BR /&gt;
            Document doc = Application.DocumentManager.MdiActiveDocument;&lt;BR /&gt;
            object oldCmdEcho = Application.GetSystemVariable("CMDECHO");&lt;BR /&gt;
            object oldFileDia = Application.GetSystemVariable("FILEDIA");&lt;BR /&gt;
            Application.SetSystemVariable("CMDECHO", 0);&lt;BR /&gt;
            Application.SetSystemVariable("FILEDIA", 0);&lt;BR /&gt;
            doc.SendStringToExecute("_.cuiload " + cuiFile + " ", false, false, &lt;BR /&gt;
false);&lt;BR /&gt;
            doc.SendStringToExecute("(setvar \"FILEDIA\" " + &lt;BR /&gt;
oldFileDia.ToString() + ")(princ) ", false, false, false);&lt;BR /&gt;
            doc.SendStringToExecute("(setvar \"CMDECHO\" " + &lt;BR /&gt;
oldCmdEcho.ToString() + ")(princ) ", false, false, false);&lt;BR /&gt;
        }&lt;BR /&gt;
&lt;BR /&gt;
        [CommandMethod("c2")]&lt;BR /&gt;
        public void c2()&lt;BR /&gt;
        {&lt;BR /&gt;
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Hello &lt;BR /&gt;
World!");&lt;BR /&gt;
        }&lt;BR /&gt;
&lt;BR /&gt;
        #region IExtensionApplication Members&lt;BR /&gt;
        void IExtensionApplication.Initialize()&lt;BR /&gt;
        {&lt;BR /&gt;
            //throw new System.Exception("The method or operation is not &lt;BR /&gt;
implemented.");&lt;BR /&gt;
            string cuiFile = "C:\\test.cui";&lt;BR /&gt;
            Document doc = Application.DocumentManager.MdiActiveDocument;&lt;BR /&gt;
            object oldCmdEcho = Application.GetSystemVariable("CMDECHO");&lt;BR /&gt;
            object oldFileDia = Application.GetSystemVariable("FILEDIA");&lt;BR /&gt;
            Application.SetSystemVariable("CMDECHO", 0);&lt;BR /&gt;
            Application.SetSystemVariable("FILEDIA", 0);&lt;BR /&gt;
            doc.SendStringToExecute("_.cuiload " + cuiFile + " ", false, false, &lt;BR /&gt;
false);&lt;BR /&gt;
            doc.SendStringToExecute("(setvar \"FILEDIA\" " + &lt;BR /&gt;
oldFileDia.ToString() + ")(princ) ", false, false, false);&lt;BR /&gt;
            doc.SendStringToExecute("(setvar \"CMDECHO\" " + &lt;BR /&gt;
oldCmdEcho.ToString() + ")(princ) ", false, false, false);&lt;BR /&gt;
        }&lt;BR /&gt;
        void IExtensionApplication.Terminate()&lt;BR /&gt;
        {&lt;BR /&gt;
            throw new System.Exception("The method or operation is not &lt;BR /&gt;
implemented.");&lt;BR /&gt;
        }&lt;BR /&gt;
        #endregion&lt;BR /&gt;
    }&lt;BR /&gt;
}&lt;BR /&gt;
{code}&lt;/OGNYANDIM&gt;</description>
      <pubDate>Sat, 02 Jan 2010 22:17:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/cuiload-from-net-dll/m-p/2609952#M67747</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-01-02T22:17:52Z</dc:date>
    </item>
    <item>
      <title>Re: cuiload from .NET dll</title>
      <link>https://forums.autodesk.com/t5/net-forum/cuiload-from-net-dll/m-p/2609953#M67748</link>
      <description>Thanks to both of you!&lt;BR /&gt;
Your hints are most helpful!&lt;BR /&gt;
I did not know that Acad instantiates the class for every single document. You are right that all the methods should be static.&lt;BR /&gt;
The final goal achieved is a program that is installed just with xcopy that reconstructs its Cui when it detects the update of the dll holding the command methods. Making it that way saves a lot of maintenance work of the installations on multiple computers in one office.</description>
      <pubDate>Mon, 04 Jan 2010 07:43:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/cuiload-from-net-dll/m-p/2609953#M67748</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2010-01-04T07:43:12Z</dc:date>
    </item>
  </channel>
</rss>

