.NET

Reply
Distinguished Contributor
afirmation
Posts: 147
Registered: ‎04-19-2006
Message 1 of 16 (274 Views)

Problem with registering AutoCAD commands in .NET

274 Views, 15 Replies
04-27-2006 06:07 AM
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.
Valued Contributor
AlbertoTorres
Posts: 76
Registered: ‎10-18-2004
Message 2 of 16 (274 Views)

Re: Problem with registering AutoCAD commands in .NET

04-28-2006 02:01 AM in reply to: afirmation
Register DLL or ARX ini Autocad 2007.

***********************************************************
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\R17.0\ACAD-5001:40A\Applications\BloquesBD]
"LOADCTRLS"=dword:00000002
"DESCRIPTION"="Gestion de bloques a traves de BD"
"MANAGED"=dword:00000001
"LOADER"="C:\\DESARROLLO\\ARX2006\\BDAccess\\bin\\BDAccess.dll"

[HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\R17.0\ACAD-5001:40A\Applications\BloquesBD\Commands]
"bloquesbd"="bloquesbd"
**************************************

Loadctrls=2 'for load ini Autocad
Loader=[path] 'path of DLL or ARX
Commands 'Commands of application (not need)
Distinguished Contributor
afirmation
Posts: 147
Registered: ‎04-19-2006
Message 3 of 16 (274 Views)

Re: Problem with registering AutoCAD commands in .NET

04-28-2006 06:15 AM in reply to: afirmation
I registered the plugin - write in the registries; I have a nice toolbar with some buttons. But when I click a button I get this message that my command doesn't exist. (when I run the solution)

But if I open AutoCAD directly everything works. My command is know and executed.

I tried this:
"[HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\R17.0\ACAD-5001:40A\Applications\BloquesBD\Commands]
"bloquesbd"="bloquesbd" "

but this doesn't work either
Member
gduchesne
Posts: 5
Registered: ‎07-14-2005
Message 4 of 16 (274 Views)

Re: Problem with registering AutoCAD commands in .NET

04-28-2006 09:52 PM in reply to: afirmation
In your project properties, in the build options, set your output path to Autocad directory.

OR

In the build events options, add post-build event to copy debug files (.dll and .pdb) to Autocad directory.
Valued Contributor
AlbertoTorres
Posts: 76
Registered: ‎10-18-2004
Message 5 of 16 (274 Views)

Re: Problem with registering AutoCAD commands in .NET

05-02-2006 12:43 AM in reply to: afirmation
Register in the version correct.

View in register with command "regedit" the string "ACAD-500:40A" and chage
if need in file .reg

[HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\R17.0\ACAD-5001:40A\Applications\BloquesBD]
Distinguished Contributor
afirmation
Posts: 147
Registered: ‎04-19-2006
Message 6 of 16 (274 Views)

Re: Problem with registering AutoCAD commands in .NET

05-04-2006 05:27 AM in reply to: afirmation
it doesn't work. I have registered my plugin, and when AutoCAD2007 strats my toolbar appears. But when I click a button I get that the command isn't known.

So the pluggin registers and the commands don't. I register my commands like this, in the assembly file I write these lines:

[assembly: ExtensionApplication(typeof(MyNamespace.MyPluginApplication))]
[assembly: CommandClass(typeof(MyNamespace.MyPluginCommands))]
Distinguished Contributor
cgay
Posts: 125
Registered: ‎08-02-2005
Message 7 of 16 (274 Views)

Re: Problem with registering AutoCAD commands in .NET

05-04-2006 01:30 PM in reply to: afirmation
afirmation,

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)

Some Questions:
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:
http://discussion.autodesk.com/thread.jspa?messageID=5035412

I believe that we will need more info and a sample of your project to help here.

C
Distinguished Contributor
afirmation
Posts: 147
Registered: ‎04-19-2006
Message 8 of 16 (274 Views)

Re: Problem with registering AutoCAD commands in .NET

05-05-2006 01:22 AM in reply to: afirmation
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.
Distinguished Contributor
cgay
Posts: 125
Registered: ‎08-02-2005
Message 9 of 16 (274 Views)

Re: Problem with registering AutoCAD commands in .NET

05-06-2006 01:26 PM in reply to: afirmation
afirmation,

I have looked at your code. A few things:

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.

string cmd = Convert.ToChar(3) + Convert.ToChar(3) + Convert.ToChar(95) + "MYLOGIN" + Convert.ToChar(32);
Produces: "esc""esc"_MYLOGIN"crlf"
AcadToolbarItem item = toolbar.AddToolbarButton(toolbar.Count + 1, "Log In", "", cmd, Missing.Value);

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.

afirmation, let us know if you can get it working

C
Distinguished Contributor
afirmation
Posts: 147
Registered: ‎04-19-2006
Message 10 of 16 (274 Views)

Re: Problem with registering AutoCAD commands in .NET

05-08-2006 01:36 AM in reply to: afirmation
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.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

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 to get help installing your software.

Ask the Community