.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem with registering AutoCAD commands in .NET

15 REPLIES 15
Reply
Message 1 of 16
afirmation
1025 Views, 15 Replies

Problem with registering AutoCAD commands in .NET

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.
15 REPLIES 15
Message 2 of 16
AlbertoTorres
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)
Message 3 of 16
afirmation
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
Message 4 of 16
gduchesne
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.
Message 5 of 16
AlbertoTorres
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]
Message 6 of 16
afirmation
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))]
Message 7 of 16
cgay
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
Message 8 of 16
afirmation
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.
Message 9 of 16
cgay
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
Message 10 of 16
afirmation
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.
Message 11 of 16
cgay
in reply to: afirmation

afirmation,

So did you try some of the things I had suggested?

Also, why is AutoCAD on your E: drive? I am assuming that Windows is on your C: drive, you may be having a problem of .NET and/or AutoCAD can't 'see' each other. On my PC I have an entry in the path of 'c:\program files\common files\autodesk shared\;'. You could also try and install AutoCAD on your C: drive.

Hmmm......also, try to remove all references to AutoCAD: Interop, Managed, etc and re-add them.

And finally, are you able to run and/or debug AutoCADs examples? Are you having the same problem with those as well? You really need to try and run those to see if they work. Granted, most of them don't add command buttons, but you can netload and type in the command names to see if you can run/debug.

Samples and Documentation:
http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=773180

ObjectARX:
http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=785550

Developer Center (provides a link to 'AutoCAD .NET Labs' zip file):
http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=1911627
Message 12 of 16
cgay
in reply to: afirmation

afirmation,

Ok try the attached project.

I did find for some reason that when I loaded your test project that the library stole was from ver 1.1 of the framework.

Basically, I rebuilt your project from scratch. Try to build/debug it on your end.

Let us know how it works

C
Message 13 of 16
afirmation
in reply to: afirmation

It WORKKKKKSSSS, you can see how happy I am.

1). First I built your sample which worked great. So I tried to make a project of my own from zero. Of course it didn't work; I copied all your classes still didn't work. Hmm ... I tried the project settings, they were the same, so that wasn't the problem., but something was still wrong.

So, I thought about the DLLs. I removed and added the DLL's for AutoCAD: acdbmgd, acmgd, Autodesk.AutoCAD.Interop and Autodesk.AutoCAD.Interop.Common and set their "Copy Local" property to false. Now it WORKED.

I tried to figure out why the commands did not work if the AutoCAD DLL's where local copied, but I didn't have any success. What I realized is that not all the dll's are the problem, but only the "acmgd.dll" which must not be local copied.

If you know why, please explain me cause I'm very curious.

2). What is the problem with debugging I don't really understand. For me it works fine. I run the solution in debug mode and set some breakpoints. In AutoCAD I netload my dll and my breakpoints fire. So, it's okay for me.

3). Why shouldn't I put my plugin dlls in the ..\Program Files\AutoCAD 2007\ .. directory?

Thanks a lot, now I can move on to other problems 🙂
Message 14 of 16
pnikoletich
in reply to: afirmation

I ran into the same problem. Thefix taht worked for me was to set the startup directory for debugging to your AutoCAD folder and then set AutoCAD as your start up application. Should fix it for future people that come across this post.
Message 15 of 16
LOGIN
in reply to: afirmation

COD REGISTERY AUTOCAD 2007
Message 16 of 16
diordonez
in reply to: afirmation

Thank you. I had the same problem but "setting the startup directory" worked very well.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost