Message 1 of 4
cuiload from .NET dll

Not applicable
01-02-2010
08:29 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Can anybody explain the strange behavior of this peace of code.
This .dll is registered in order to load on startup.
{code}
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\Software\Autodesk\AutoCAD\R17.1\ACAD-6001:409\Applications\TestCAD2]
"DESCRIPTION"="Ognyans test app"
"LOADCTRLS"=dword:00000002
"MANAGED"=dword:00000001
"LOADER"="C:\\work\\LocalTestProjects\\acad_CUI\\acad_CUI\\bin\\Debug\\acad_CUI.dll"
{code}
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".
2. When I don`t comment out anything the program "brakes" in the initialize method in the line
doc.SendStringToExecute("_.cuiload " + cuiFile + " ", false, false, false); but Autocad continues to work without error prompt, but no CUI is loaded.
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.
c1 command is working fine when netload-ed by hand.
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.
If you place a message in the initialize method the message will appear before the last Acad default console messages.
Is there a way to tell the initialize method to wait until Acad is ready to receive?
{code}
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Customization;
namespace ClassLibrary1
{
public class Class1 : IExtensionApplication
{
public Class1()
{
//throw new System.Exception("The method or operation is not implemented.");
string cuiFile = "C:\\test.cui";
Document doc = Application.DocumentManager.MdiActiveDocument;
object oldCmdEcho = Application.GetSystemVariable("CMDECHO");
object oldFileDia = Application.GetSystemVariable("FILEDIA");
Application.SetSystemVariable("CMDECHO", 0);
Application.SetSystemVariable("FILEDIA", 0);
doc.SendStringToExecute("_.cuiload " + cuiFile + " ", false, false, false);
doc.SendStringToExecute("(setvar \"FILEDIA\" " + oldFileDia.ToString() + ")(princ) ", false, false, false);
doc.SendStringToExecute("(setvar \"CMDECHO\" " + oldCmdEcho.ToString() + ")(princ) ", false, false, false);
}
[CommandMethod("c1")]
public void c1()
{
string cuiFile = "C:\\test.cui";
Document doc = Application.DocumentManager.MdiActiveDocument;
object oldCmdEcho = Application.GetSystemVariable("CMDECHO");
object oldFileDia = Application.GetSystemVariable("FILEDIA");
Application.SetSystemVariable("CMDECHO", 0);
Application.SetSystemVariable("FILEDIA", 0);
doc.SendStringToExecute("_.cuiload " + cuiFile + " ", false, false, false);
doc.SendStringToExecute("(setvar \"FILEDIA\" " + oldFileDia.ToString() + ")(princ) ", false, false, false);
doc.SendStringToExecute("(setvar \"CMDECHO\" " + oldCmdEcho.ToString() + ")(princ) ", false, false, false);
}
[CommandMethod("c2")]
public void c2()
{
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Hello World!");
}
#region IExtensionApplication Members
void IExtensionApplication.Initialize()
{
//throw new System.Exception("The method or operation is not implemented.");
string cuiFile = "C:\\test.cui";
Document doc = Application.DocumentManager.MdiActiveDocument;
object oldCmdEcho = Application.GetSystemVariable("CMDECHO");
object oldFileDia = Application.GetSystemVariable("FILEDIA");
Application.SetSystemVariable("CMDECHO", 0);
Application.SetSystemVariable("FILEDIA", 0);
doc.SendStringToExecute("_.cuiload " + cuiFile + " ", false, false, false);
doc.SendStringToExecute("(setvar \"FILEDIA\" " + oldFileDia.ToString() + ")(princ) ", false, false, false);
doc.SendStringToExecute("(setvar \"CMDECHO\" " + oldCmdEcho.ToString() + ")(princ) ", false, false, false);
}
void IExtensionApplication.Terminate()
{
throw new System.Exception("The method or operation is not implemented.");
}
#endregion
}
}
{code}
Can anybody explain the strange behavior of this peace of code.
This .dll is registered in order to load on startup.
{code}
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\Software\Autodesk\AutoCAD\R17.1\ACAD-6001:409\Applications\TestCAD2]
"DESCRIPTION"="Ognyans test app"
"LOADCTRLS"=dword:00000002
"MANAGED"=dword:00000001
"LOADER"="C:\\work\\LocalTestProjects\\acad_CUI\\acad_CUI\\bin\\Debug\\acad_CUI.dll"
{code}
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".
2. When I don`t comment out anything the program "brakes" in the initialize method in the line
doc.SendStringToExecute("_.cuiload " + cuiFile + " ", false, false, false); but Autocad continues to work without error prompt, but no CUI is loaded.
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.
c1 command is working fine when netload-ed by hand.
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.
If you place a message in the initialize method the message will appear before the last Acad default console messages.
Is there a way to tell the initialize method to wait until Acad is ready to receive?
{code}
using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Customization;
namespace ClassLibrary1
{
public class Class1 : IExtensionApplication
{
public Class1()
{
//throw new System.Exception("The method or operation is not implemented.");
string cuiFile = "C:\\test.cui";
Document doc = Application.DocumentManager.MdiActiveDocument;
object oldCmdEcho = Application.GetSystemVariable("CMDECHO");
object oldFileDia = Application.GetSystemVariable("FILEDIA");
Application.SetSystemVariable("CMDECHO", 0);
Application.SetSystemVariable("FILEDIA", 0);
doc.SendStringToExecute("_.cuiload " + cuiFile + " ", false, false, false);
doc.SendStringToExecute("(setvar \"FILEDIA\" " + oldFileDia.ToString() + ")(princ) ", false, false, false);
doc.SendStringToExecute("(setvar \"CMDECHO\" " + oldCmdEcho.ToString() + ")(princ) ", false, false, false);
}
[CommandMethod("c1")]
public void c1()
{
string cuiFile = "C:\\test.cui";
Document doc = Application.DocumentManager.MdiActiveDocument;
object oldCmdEcho = Application.GetSystemVariable("CMDECHO");
object oldFileDia = Application.GetSystemVariable("FILEDIA");
Application.SetSystemVariable("CMDECHO", 0);
Application.SetSystemVariable("FILEDIA", 0);
doc.SendStringToExecute("_.cuiload " + cuiFile + " ", false, false, false);
doc.SendStringToExecute("(setvar \"FILEDIA\" " + oldFileDia.ToString() + ")(princ) ", false, false, false);
doc.SendStringToExecute("(setvar \"CMDECHO\" " + oldCmdEcho.ToString() + ")(princ) ", false, false, false);
}
[CommandMethod("c2")]
public void c2()
{
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Hello World!");
}
#region IExtensionApplication Members
void IExtensionApplication.Initialize()
{
//throw new System.Exception("The method or operation is not implemented.");
string cuiFile = "C:\\test.cui";
Document doc = Application.DocumentManager.MdiActiveDocument;
object oldCmdEcho = Application.GetSystemVariable("CMDECHO");
object oldFileDia = Application.GetSystemVariable("FILEDIA");
Application.SetSystemVariable("CMDECHO", 0);
Application.SetSystemVariable("FILEDIA", 0);
doc.SendStringToExecute("_.cuiload " + cuiFile + " ", false, false, false);
doc.SendStringToExecute("(setvar \"FILEDIA\" " + oldFileDia.ToString() + ")(princ) ", false, false, false);
doc.SendStringToExecute("(setvar \"CMDECHO\" " + oldCmdEcho.ToString() + ")(princ) ", false, false, false);
}
void IExtensionApplication.Terminate()
{
throw new System.Exception("The method or operation is not implemented.");
}
#endregion
}
}
{code}