I'm trying to create a plugin for AutoCAD2007 in C# .NET 2.0.
But it seems I have a problem with registering my AutoCAD commands. When I run my .NET plugin-solution, AutoCAD2007 starts but my commands do not work. But, if I run AutoCAD2007 from the desktop Icon everything works great.
I can live with that but I can't do any debugging, and that I don't like.
Windows Registry Editor Version 5.00
"DESCRIPTION"="Gestion de bloques a traves de BD"
How are your command/function declarations written?
Are they static (shared for the VB Crowd)?
Does the compiler give any warnings/errors when you compile?
Perhaps a sample project with just the simple plumbing code, i.e.
1.)the class that implements IExtensionApplication
2.)the class that adds the toolbar and buttons
3.)the Class that defines your commands with just the function declarations (you can omit your unique code)
A.) Have you tried to use the samples autodesk provides as the 'plumbing' or 'base' for your projects or are you writing it from scratch?
B.) If you have looked at the samples, can you debug these?
C.) If so, what is different between the samples and your project(s)?
D.) Can you call your commands by typing the command in AutoCAD's command line?
You only need to add the registry info when you want autocad to autoload your dll, which I highly recommend for a finished project only due to the fact that you could potentially run into locked dll errors if you try to overwrite with AutoCAD running.
For an alternate debugging configuration see my reply post to this thread:
I believe that we will need more info and a sample of your project to help here.
I've created this simple project to show what's wrong.
My project tries to register a toolbar with 2 buttons: Login and Logout, that works fine. Each button has its corresponding command: MYLOGIN and MYLOGOUT. If I run the solution, AUTOCAD2007 runs but these commands don't work:
Command: _.MYLOGIN Unknown command "MYLOGIN". Press F1 for help.
Command: _.MYLOGOUT Unknown command "MYLOGOUT". Press F1 for help.
BUT if I run AutoCAD2007 from the desktop button, these commands work.
I've registered my plugin by hand (in my Application class I've specified what I have written in the registries).
I hope these is a little bit clear. Thank you a lot for helping me, I'm kind of stucked.
1.) Your commands don't work because of the macro string
Do this instead:
Note: I have never used "Convert.ToChar" in this way so you'll have to test it out. I could also recommend using the "Microsoft.VisualBasic.Strings.Chr()" function, but you need to import the library "Microsoft.VisualBasic", something C#'s seem reluctant to IMHO. I personally like the ability to use functions defined in all the .NET libraries at any time, so I leave it up to you to decide.
2.) Your debug configuration is ok. But when you start debugging, you need to Netload your dll to have access to your commands, and allow the debugger to attach to it. If you follow the link from my previous post, you can see my solution to this. It may not be the best, but it works, unless you like to netload of course. I would like to hear others' solutions to debugging as well.
3.) your use of the "ComRegisterFunctionAttribute" is the first I've seen in this configuration. It looks like this allows you to run regsvr32 to run this section of code to add the autoload info into the registry? In my opinion, you should only register your add-in to load from the registry when you are in the testing phase of development and not while still developing. Debugging may be difficult. It's my opinion that your installer should add they required keys to the registry when you deploy or again, if you want to test autoloading.
3.) Finally, this one is for all. I generally believe that putting anything in the AutoCAD directory is bad for business. In fact I remember reading something from AutoCAD stating that this is not recommended. I would like to hear everyone's opinion on this of course, both for and against, as I have not yet ruled it out in some situations.
It drives me crazy. Still doesn't work. The thing I don't understand is why the commands WORK if I run AutoCAD2007 from the desktop icon and do NOT WORK if I run AutoCAD as a external program from my solution.
If I run my solutin I click netload - the commands don't work;
If I run AUTOCAD from the desktop Icon and netload my dll - the commands work.
I can't figure it out. Why it workes fine when I start AutoCAD separately and doesn't work if I run AutoCAD from my solution.