I'm using AutoCADMechanical 2010, and I have a C# function called detailInsert. Using netload the addin works perfect. I'm unable to get it to load at startup.
I've copied the demand load code from this Autodesk blog: http://through-the-interface.typepad.com/through_the_interface/2010/03/creating-demand-loading-entri...
However, typing "detailInsert" still says "command not found".
Here is my command method line:
[CommandMethod("CompanyInitials", "DetailInsert", "DetailInsert", CommandFlags.Session)]
Here is where I call the register and unregister functions.
void IExtensionApplication.Initialize()
{
RegistryUpdate.RegisterForDemandLoading();
}
void IExtensionApplication.Terminate()
{
// Do plug-in application clean up here
RegistryUpdate.UnregisterForDemandLoading();
}
Does anyone have any ideas for how to make this work?
Solved! Go to Solution.
Solved by DiningPhilosopher. Go to Solution.
I should add that the registry entries are created properly. Even still, it says command not found when I enter "detailInsert"
@bsee1 wrote:I'm using AutoCADMechanical 2010, and I have a C# function called detailInsert. Using netload the addin works perfect. I'm unable to get it to load at startup.
Here is my command method line:
[CommandMethod("CompanyInitials", "DetailInsert", "DetailInsert", CommandFlags.Session)]
Does anyone have any ideas for how to make this work?
There are a few potential causes. Your [CommandMethod] attribute specifies a localized name and the code you're using to register it may be making an incorrect assumption that it's a resource identifier rather than the actual localized name (it makes no sense to specify a localized name if you're not supporting multiple languages).
The other possible causes include the method not being public, the class containing the method not being public, a command method that takes arguments, etc.
It could also be an error in the code that you're using to register the commands, and you can find out that by putting the call to it in a try{} block, and then showing a message in the catch{} block that follows it. That's something you should always do with IExtensionApplication.Initialize() because it catches any exceptions that your code doesn't catch, and doesn't bother to mention them.
Can't tell if its any of those cause you only show the attribute not the method and class.declaration
Per your suggestions, here are segments of the code I've updated. However, nothing has changed. It still only runs when I netload it and call it. For some reason, the demandload code isn't working. Again this doesn't make sense because the registry entry has been created.
//The code from namespace down to the function. It's all public, and I removed the localized entry from the commandmethod
namespace DetailFieldTool
{
public class MyCommands
{
[CommandMethod("CompanyName", "DetailInsert", CommandFlags.Session)]
public void detailInsert()
{
//The demand load code in a try catch...
try
{
RegistryUpdate.RegisterForDemandLoading();
}
catch(System.Exception ex)
{
MessageBox.Show("Exception raised: " + ex);
}
//The demand load code copied directly from Through The Interface.
namespace DemandLoading
{
public class RegistryUpdate
{
public static void RegisterForDemandLoading()
{
Given that my function runs properly when I netload it, what else could be the problem?
Anything else going on inside your IExtensionApplication.Initialize() method?
Also, you should make the command method static, otherwise the runtime will create an instance of your class for each document the command is used in. if making the command method static works, then the problem is most-likely in the constructor of your class, or some code call from there, because the runtime is creating an instance of the class in order to invoke the non-static command method.
Nothing else is happening in my IExtensionApplication.Initialize() method and the command is now static. It still won't demand load, it still does create the registry entries, it will still work if I netload it.
Any other ideas?
Something's failing when your assembly is loaded at startup. It could be a static constructor or a reference to a type in another assembly that is either missing or is the wrong version. Regardless, AutoCAD's managed runtime will catch any exceptions that happen during the loading of your assembly and will not show you any error, and unfortunately, you can't wrap all code that runs at startup in a try/catch block.
I would try removing the CommandFlags.Session, and eliminating the group name and/or localized command name from the CommandMethod attribute and just declare it with the command name only, and see if that fixes it. You might also try running AutoCAD in the debugger with it set to break on any exceptions, and see what happens (you can use Debug->Step Into rather than "Run" to make the debugger stop on the very first line of code in your assembly, and then step through it from there).
Removing commandflags.session fixed it. I'm not sure why, but everythign works as expected now. Thank you.