Author Topic: CommandMethod not working  (Read 5233 times)

0 Members and 1 Guest are viewing this topic.

Bryco

  • Water Moccasin
  • Posts: 1883
CommandMethod not working
« on: December 31, 2007, 02:03:42 PM »
I seem to find that sometimes a new CommandMethod will refuse to work in a class file (even though there are many working CommandMethods in that namespace), pasting it into another .cs  allows it to work.
Help is a little confusing
Quote
CommandMethodAttribute Class Marks an instance or static function as a command. Command methods may be defined only in a class that is marked with the CommandClass attribute.
If one CommandMethod works within a class within a namespace then hopefully I can assume that class is marked so why wouldn't the next on work?

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8737
  • AKA Daniel
Re: CommandMethod not working
« Reply #1 on: December 31, 2007, 02:21:51 PM »
I seem to find that sometimes a new CommandMethod will refuse to work in a class file (even though there are many working CommandMethods in that namespace), pasting it into another .cs  allows it to work.
Help is a little confusing
Quote
CommandMethodAttribute Class Marks an instance or static function as a command. Command methods may be defined only in a class that is marked with the CommandClass attribute.
If one CommandMethod works within a class within a namespace then hopefully I can assume that class is marked so why wouldn't the next on work?

I have had this happen to me before just add
[assembly: CommandClass(typeof(YourNameSpace.YourClassname))]
Before the namespace

Bryco

  • Water Moccasin
  • Posts: 1883
Re: CommandMethod not working
« Reply #2 on: December 31, 2007, 02:25:43 PM »
Daniel that indeed makes it work, but then all the commands in the other classes don't work.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: CommandMethod not working
« Reply #3 on: December 31, 2007, 02:30:44 PM »
Perhaps that helps explain the help topic  CommandClassAttribute Class
Quote
This custom attribute class is used to mark a type as the application's command class. An application may designate one, and only one, type as its command class. AutoCAD looks for an application's command methods on the type that bears this attribute.

I'm just wondering if I have to do all my command calls in one class?

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8737
  • AKA Daniel
Re: CommandMethod not working
« Reply #4 on: December 31, 2007, 02:35:06 PM »
Perhaps that helps explain the help topic  CommandClassAttribute Class
Quote
This custom attribute class is used to mark a type as the application's command class. An application may designate one, and only one, type as its command class. AutoCAD looks for an application's command methods on the type that bears this attribute.

I'm just wondering if I have to do all my command calls in one class?

No, I don’t think so, but Every class that has a commandmethod and/or lispfunction should also have this attribute.
Edit: hmmm maybe you will have to

sinc

  • Guest
Re: CommandMethod not working
« Reply #5 on: December 31, 2007, 02:51:02 PM »
Interesting...

I have an application with lots of classes, all of which use CommandMethods, but I have not had any issues.

I do not have that "[assembly: CommandClass()]" call in my code anywhere.  Can anyone explain exactly why I would want it?  What does it do?

If it forces me to put all my command methods into the same class, then I'm not sure I even want to mess with it.  Everything seems to be working fine without it.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: CommandMethod not working
« Reply #6 on: December 31, 2007, 02:58:54 PM »
Well it is confusing using the word class.
sinc I was happy as Larry not using CommandClass until new commands didn't work.
This is in the same namespace and it works.
[assembly: CommandClass(typeof(Test.Test))]
[assembly: CommandClass(typeof(Test.Whereisthecommand))]
As well as I've added them in other class files and they seem to all work in the same project.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: CommandMethod not working
« Reply #7 on: December 31, 2007, 03:16:50 PM »
Another namespace
[assembly: CommandClass(typeof(JigDrag.ArcJiggy))]
[assembly: CommandClass(typeof(JigDrag.CircleJiggy))]
[assembly: CommandClass(typeof(JigDrag.EllipseJiggy))]
[assembly: CommandClass(typeof(JigDrag.LineJiggy))]
[assembly: CommandClass(typeof(JigDrag.PlineJiggy.PolyArcJiggy))]

Looking at the last one, the command was in a class within a class.
Once you start, you have to do it throughout your project.