.NET

Reply
Mentor
bsee1
Posts: 211
Registered: ‎11-14-2011
Message 1 of 8 (622 Views)
Accepted Solution

AutoCAD 2010 demand load not working

622 Views, 7 Replies
10-30-2012 11:48 AM

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?

*****************************
Win7 x64 - 16gb ram
i7 3610qm
FirePro M4000

Inventor 2013
ETO 6.1

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).

Mentor
bsee1
Posts: 211
Registered: ‎11-14-2011
Message 2 of 8 (619 Views)

Re: AutoCAD 2010 demand load not working

10-30-2012 11:53 AM in reply to: bsee1

I should add that the registry entries are created properly.  Even still, it says command not found when I enter "detailInsert"

*****************************
Win7 x64 - 16gb ram
i7 3610qm
FirePro M4000

Inventor 2013
ETO 6.1
Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 3 of 8 (603 Views)

Re: AutoCAD 2010 demand load not working

10-30-2012 06:36 PM in reply to: bsee1

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

 

Mentor
bsee1
Posts: 211
Registered: ‎11-14-2011
Message 4 of 8 (582 Views)

Re: AutoCAD 2010 demand load not working

10-31-2012 08:59 AM in reply to: DiningPhilosopher

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?

*****************************
Win7 x64 - 16gb ram
i7 3610qm
FirePro M4000

Inventor 2013
ETO 6.1
Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 5 of 8 (575 Views)

Re: AutoCAD 2010 demand load not working

10-31-2012 01:47 PM in reply to: bsee1

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.

Mentor
bsee1
Posts: 211
Registered: ‎11-14-2011
Message 6 of 8 (517 Views)

Re: AutoCAD 2010 demand load not working

11-05-2012 10:25 AM in reply to: DiningPhilosopher

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?

*****************************
Win7 x64 - 16gb ram
i7 3610qm
FirePro M4000

Inventor 2013
ETO 6.1
Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 7 of 8 (508 Views)

Re: AutoCAD 2010 demand load not working

11-05-2012 07:02 PM in reply to: bsee1

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).

Mentor
bsee1
Posts: 211
Registered: ‎11-14-2011
Message 8 of 8 (481 Views)

Re: AutoCAD 2010 demand load not working

11-07-2012 10:10 AM in reply to: DiningPhilosopher

Removing commandflags.session fixed it.  I'm not sure why, but everythign works as expected now.  Thank you.

*****************************
Win7 x64 - 16gb ram
i7 3610qm
FirePro M4000

Inventor 2013
ETO 6.1
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.