.NET

Reply
Valued Contributor
tonofsteel
Posts: 93
Registered: ‎12-04-2009
Message 1 of 8 (765 Views)

2010 dotNET Wizards

765 Views, 7 Replies
12-07-2009 01:49 PM
When you use the wizard to create a project you end up with myCommands.cs and myPlugin.cs. I can empty all the existing code out of myPlugin.cs and program in a custom class, however if you build and try to run the code AutoCAD says that it cannot find a function by the name I called it.

If I move this function into myCommands.cs then it will work fine. I thought you can have as many cs files as you want and they end up getting linked all into the same dll? Why can I not access commands written in the myPlugin.cs file?
*Expert Elite*
arcticad
Posts: 1,285
Registered: ‎06-21-2004
Message 2 of 8 (765 Views)

Re: 2010 dotNET Wizards

12-07-2009 03:17 PM in reply to: tonofsteel
Did you make a new instance of your class in the other file?
---------------------------



(defun botsbuildbots() (botsbuildbots))
*Tony Tanzillo
Message 3 of 8 (765 Views)

Re: 2010 dotNET Wizards

12-07-2009 07:46 PM in reply to: tonofsteel
I don't use the wizards and advise others to not use them,
mainly because Visual Studio project and item templates
are just as easy to use and can be easily customized to
include commonly-used items.

Anyway, the problem you have is the CommandClass
attribute.

When you use this attribute with any class in an assembly,
the managed runtime assumes that only classes which the
attribute is used with expose command methods. So, to
add commands to another class, you must also use the
CommandClass attribute just as it's used with the wizard-
generated class.

[assembly: CommandClass( typeof( MyCommandClass ) )]

where 'MyCommandClass' is the class that exposes one
or more command methods. You can repeat this attribute
for every class that exposes command methods, and you
generally do that at the top of the code file containing the
class.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6300742@discussion.autodesk.com...
When you use the wizard to create a project you end up with myCommands.cs
and myPlugin.cs. I can empty all the existing code out of myPlugin.cs and
program in a custom class, however if you build and try to run the code
AutoCAD says that it cannot find a function by the name I called it.

If I move this function into myCommands.cs then it will work fine. I
thought you can have as many cs files as you want and they end up getting
linked all into the same dll? Why can I not access commands written in the
myPlugin.cs file?
Valued Contributor
tonofsteel
Posts: 93
Registered: ‎12-04-2009
Message 4 of 8 (765 Views)

Re: 2010 dotNET Wizards

12-08-2009 09:01 AM in reply to: tonofsteel
Thank you for clearing that up for me. I guess where my confusion comes from is that the line that you refer to has the comment that the line is not mandatory, but improves loading performance. It seems that if you remove that line then your commands are not available in AutoCAD, why would that comment be in the wizard generated file?
*Tony Tanzillo
Message 5 of 8 (765 Views)

Re: 2010 dotNET Wizards

12-08-2009 10:22 PM in reply to: tonofsteel
The CommandClass attribute is optional, but on an assembly-
wide basis. IOW, you either do not use it at all, or you must use
it on every class that exposes commands. Using it on some
classes that expose commands but not on all of same defeats
the purpose of the attribute, which is to eliminate the need for
the runtime to search every class to find command methods.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6301195@discussion.autodesk.com...
Thank you for clearing that up for me. I guess where my confusion comes
from is that the line that you refer to has the comment that the line is not
mandatory, but improves loading performance. It seems that if you remove
that line then your commands are not available in AutoCAD, why would that
comment be in the wizard generated file?
Valued Contributor
tonofsteel
Posts: 93
Registered: ‎12-04-2009
Message 6 of 8 (765 Views)

Re: 2010 dotNET Wizards

04-29-2010 07:30 PM in reply to: tonofsteel
I am continuing to have problems with the whole CommandClass setup. I have 2 cs files in my project, and each of them have a different namespace. If i use the CommandClass attribute in both of these I get an error when trying to load in AutoCAD 2011 that states there is an error eDuplicateKey and it cannot load the assembly, however I can run the command in one of the .cs files but not the other, so it must stop loading after the first file. If I get rid of these attributes then this error goes away but the command that ran does not run anymore and now the one in the other file runs.

Is there a limit of only being able to put CommandMethods in one .cs file only? I cannot get two .cs files with different commands and namespaces to work.

I have checked and double checked and I cannot see ANY duplication in any namespaces, command names, function names, class names etc. so why is this eDuplicateKey error being thrown when there is nothing duplicated in any file?
*Tony Tanzillo
Message 7 of 8 (765 Views)

Re: 2010 dotNET Wizards

04-30-2010 11:31 AM in reply to: tonofsteel
eDuplicateKey means that you're defining a command
with the same name more than once.

Namespaces are irrelevant, it's the name of the command
that must be unique (or you must use a different groupname
for one of them).

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2011

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6383332@discussion.autodesk.com...
I am continuing to have problems with the whole CommandClass setup. I have 2 cs
files in my project, and each of them have a different namespace. If i use the
CommandClass attribute in both of these I get an error when trying to load in
AutoCAD 2011 that states there is an error eDuplicateKey and it cannot load the
assembly, however I can run the command in one of the .cs files but not the
other, so it must stop loading after the first file. If I get rid of these
attributes then this error goes away but the command that ran does not run
anymore and now the one in the other file runs.

Is there a limit of only being able to put CommandMethods in one .cs file only?
I cannot get two .cs files with different commands and namespaces to work.

I have checked and double checked and I cannot see ANY duplication in any
namespaces, command names, function names, class names etc. so why is this
eDuplicateKey error being thrown when there is nothing duplicated in any file?
Valued Contributor
tonofsteel
Posts: 93
Registered: ‎12-04-2009
Message 8 of 8 (765 Views)

Re: 2010 dotNET Wizards

04-30-2010 03:10 PM in reply to: tonofsteel
You were right, I had a duplicate command buried in my code that had nothing in it, I must have copied it to another file to work on and did not erase the original command method.

Thanks!

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