As I understand it, Jeff... Only the first CommandClassAttribute is recognized, meaning that your CommandMethodAttribute definitions need to reside within the same Class/Type the CommandClassAttribute is targeting.
As I understand it, Jeff... Only the first CommandClassAttribute is recognized, meaning that your CommandMethodAttribute definitions need to reside within the same Class/Type the CommandClassAttribute is targeting.CommandClassAttribute is metadata at the assembly level and you can have many and add them anywhere in any class file, but placing them in AssemblyInfo file is probably a good practice AutoCAD .NET CommandClass and Some Clarifications (http://spiderinnet1.typepad.com/blog/2012/07/commandclass-and-some-clarifications.html)
What I just tested, and seems to be working with the one command I tested with, is to move the command call from the second project into it's own class in the main project. So this new class has nothing more than [CommandMethod()] and a method to call the actual method in the second project, for each of the 7 commands in that second project. Seems a bit convoluted but, as I said, it seems to be working.
CommandClassAttribute is metadata at the assembly level and you can have many and add them anywhere in any class file, but placing them in AssemblyInfo file is probably a good practice AutoCAD .NET CommandClass and Some Clarifications (http://spiderinnet1.typepad.com/blog/2012/07/commandclass-and-some-clarifications.html)
you will see that it is added to assembly Manifest if you look at it with IL Disassembler.
If you look at first if statement AutoCAD checks the assembly for CommandClassAttribute if at least one exists then it adds them.
If no CommandClassAttribute are found then it will start looking at metadata for the types in the assembly.
So if you add one CommandClassAttribute then you have to do it for all types that contain methods with CommandMethodAttribute
string dllName = "Secondproject.dll";
string dllPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + dllName;
System.Reflection.Assembly.LoadFrom(dllPath);
Will, instead of SendCommand I would use something like this code since both project's dll's will be in the same location:Not sure if that would work for us in this case because we would need the CommandMethods to be registered inside AutoCAD. If you try it let me know the result pleaseCode: [Select]string dllName = "Secondproject.dll";
string dllPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + dllName;
System.Reflection.Assembly.LoadFrom(dllPath);
I have a VS2010 Solution with multiple Projects, 2 of which contain multiple [CommandMethod()] definitions. The commands in the main project work fine. Those defined in the secondary project, which is referenced into the main project, are not recognized. Is there something I need to do (well, obviously there is...but what?) in order for these additional commands to be 'seen' by Autocad?
Thanks MickD,
Did this change when they added the AutoLoader Functionality?
Looking with reflector it is done through events AssemblyLoad and AssemblyResolve events.
I thought in the past it was not done through event handling and just whatever assembly where in registry or loaded via Netload.
Thanks MickD,
Did this change when they added the AutoLoader Functionality?
Looking with reflector it is done through events AssemblyLoad and AssemblyResolve events.
I thought in the past it was not done through event handling and just whatever assembly where in registry or loaded via Netload.
Not sure Jeff, I think that while an auto loader may load 'referenced' assemblies, the function being called is what triggers the auto load.
With commands, AutoCAD knows nothing about your commands until you load your assembly, that is it doesn't even know it has to resolve a reference as the callback (calling function) for the command doesn't even exist in the running process yet (it's not loaded or compiled into it).
I did see something on the board here from Dan that mentioned implementing a method that will be found to autoload .net dll's(?).
If this is the case it may be that when a command is called and the command is not registered it calls a default method which searches unloaded assemblies in the support path and if you have declared the function it will load the assembly, just thinking out load here though.
Either way you need to have a bit of code in the main process to call to make the process look for the method and resolve the reference, for plug ins in AutoCAD this is done using Netload and CommandMethod attributes to load the callbacks into the main process.
Basically what TonyT said a few posts ago :)