Author Topic: Trouble with Editor.Command()  (Read 7464 times)

0 Members and 2 Guests are viewing this topic.

BlackBox

  • King Gator
  • Posts: 3770
Trouble with Editor.Command()
« on: November 22, 2013, 06:30:04 PM »
I'm having trouble utilizing Tony's Editor.Command() Extension Method here.

Basically, I have a ContextMenuExtension who's RXClass is Curve, and the MenuItem.Clicked event is attempting to use the PopUp event's PromptSelectionResultResult.Value (a SelectionSet) which is stored to static field, following a call to Editor.SelectImplied() within the PopUp event handler. Then, within the MenuItem.Clicked event handler, I'm attempting to call Editor.Command()... The call is made, no exceptions are thrown, but the command is unsuccessful.

I was using Document.SendStringToExecute(), but I didn't want the history available if/when user hits up arrow. I want to supply a SelectionSet as REVCLOUD does not support implied, nor previous selection, and the last (_L) is parameter is not always correct, AFAIK.

I must be missing something, or simply not supplying the call to Editor.Command() the correct parameters... Please advise.

Example:

Code - C#: [Select]
  1.         private static void onMenuClick(object sender, EventArgs e)
  2.         {
  3.             Document doc = acDocs.MdiActiveDocument;
  4.             Editor ed = doc.Editor;
  5.  
  6.             try
  7.             {
  8.                 using (DocumentLock dl = doc.LockDocument())
  9.                 {
  10.                     ed.Command("._revcloud", "_o", ss, "_n");
  11.                 }
  12.             }
  13.             catch (Autodesk.AutoCAD.Runtime.Exception ex)
  14.             {
  15.                 ed.WriteMessage(
  16.                     "\n; error: Autodesk.AutoCAD.Runtime.Exception: {0}\n", ex.Message);
  17.             }
  18.         }
  19.  

Basically, I'm attempting to use Editor.Command() in lieu of this LISP:

Code - Auto/Visual Lisp: [Select]
  1. ;; where the implied selection is made during
  2. ;; PopUp event handler via Editor.SelectImplied()
  3. (if (setq ss (ssget "_i"))
  4.  
  5.      ;; and this would be evaluated in
  6.      ;; MenuItem.Click event handler
  7.      (command "._revcloud" "_o" ss "_n")
  8. )
  9.  

TIA
"How we think determines what we do, and what we do determines what we get."

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Trouble with Editor.Command()
« Reply #1 on: November 22, 2013, 10:28:21 PM »
Have not tested but you probably will have to pass an objectid instead of a selection set which would be normal for commands that expect a single entity.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: Trouble with Editor.Command()
« Reply #2 on: November 23, 2013, 11:15:12 AM »
BB, Jeff H is correct. This simple sample demonstrates this:
Code - C#: [Select]
  1.         [CommandMethod("revtest", CommandFlags.UsePickSet)]
  2.         public void revtest()
  3.         {
  4.             Document doc = Application.DocumentManager.MdiActiveDocument;
  5.             Editor ed = doc.Editor;
  6.             PromptSelectionResult ssres = ed.SelectImplied();
  7.             if (ssres.Status == PromptStatus.OK && ssres.Value.Count > 0)
  8.             {
  9.                 using (Transaction tr = doc.Database.TransactionManager.StartTransaction())
  10.                 {
  11.                     foreach (ObjectId id in ssres.Value.GetObjectIds())
  12.                     {
  13.                         ed.Command("._revcloud", "_o", id, "_n");
  14.                     }
  15.                     tr.Commit();
  16.                 }
  17.             }
  18.         }
  19.  

BlackBox

  • King Gator
  • Posts: 3770
Re: Trouble with Editor.Command()
« Reply #3 on: November 23, 2013, 05:56:41 PM »
Thanks for the replies, guys.  :-)

I could have sworn that I came across a post by Gile, where he demonstrated Tony's (or perhaps his own adaptation of) Editor.Command(), where a SelectionSet was passed explicitly. I cannot seem to recall where, what forum, etc... I'll see if I can find it.

In a quick search, I did come across this post by Tony, and was just curious to know if passing the ObjectId was successful here as a result of the single selection object ("_o") prompt for this specific command call, or what, as he explicitly states passing SelectionSets is viable. Meaning, just as if passing a multiple entity SelectionSet via LISP only one object is used by REVCLOUD (multiple calls needed in order for all to be converted, etc.), shouldn't I be able to pass a Selectionset in lieu of ObjectId?

You can call the Editor's RunCommand method which in addition to doing the messy stuff, also converts managed types to native types, including SelectionSets.

You can use this reflection-free wrapper to invoke RunCommand(), which is a little faster than calling it via Reflection:

<code removed by BB>


Cheers
"How we think determines what we do, and what we do determines what we get."

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Trouble with Editor.Command()
« Reply #4 on: November 23, 2013, 06:12:02 PM »
Hi,

The Editor.Command() does work with selection set.
Try:
Code - C#: [Select]
  1.         [CommandMethod("test", CommandFlags.UsePickSet)]
  2.         public void test()
  3.         {
  4.             Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
  5.             PromptSelectionResult psr = ed.GetSelection();
  6.             if (psr.Status == PromptStatus.OK)
  7.                 ed.Command("_move", psr.Value, "");
  8.         }

Maybe the issue is related to the _revcloud command...
« Last Edit: November 23, 2013, 06:38:43 PM by gile »
Speaking English as a French Frog

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Trouble with Editor.Command()
« Reply #5 on: November 23, 2013, 09:24:57 PM »
The command line version of REVCLOUD expects to have an entity selected, not a selection set.
I wouldn't expect a command invocation from .net would behave any differently.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

BlackBox

  • King Gator
  • Posts: 3770
Re: Trouble with Editor.Command()
« Reply #6 on: November 27, 2013, 01:32:26 PM »
The Editor.Command() does work with selection set.

...

Maybe the issue is related to the _revcloud command...

I can get SendStringToExecute() to work (using LISP string to account for the implied selection). CommandMethod Methods aren't an issue.

ObjectId, or SelectionSet, invoking Editor.Command() from a MenuItem.Click event handler still fails (with no exception)... I must not be accounting for some sort of '*Context'?

I 'spose I can simply call a custom CommandMethod Method from within the MenuItem.Click, but I'd rather not (add another new Command) if I don't have to.



The command line version of REVCLOUD expects to have an entity selected, not a selection set.
I wouldn't expect a command invocation from .net would behave any differently.

Even without code, REVCLOUD Command does not accept implied, nor previous selection parameters (only last, "_L")... Also, there does not seem to be a command line version (i.e., -REVCLOUD) according to the online help.

Cheers
"How we think determines what we do, and what we do determines what we get."

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Trouble with Editor.Command()
« Reply #7 on: November 27, 2013, 07:13:31 PM »
acedcmd only works in document context and menu item would be in application context.


WILL HATCH

  • Bull Frog
  • Posts: 450
Re: Trouble with Editor.Command()
« Reply #8 on: November 28, 2013, 04:08:59 PM »
I haven't used SendStringToExecute much, but I thought setting the echoCommand input to false would prevent it from being in the history. 

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Trouble with Editor.Command()
« Reply #9 on: November 28, 2013, 05:39:01 PM »

The command line version of REVCLOUD expects to have an entity selected, not a selection set.
I wouldn't expect a command invocation from .net would behave any differently.

Even without code, REVCLOUD Command does not accept implied, nor previous selection parameters (only last, "_L")... Also, there does not seem to be a command line version (i.e., -REVCLOUD) according to the online help.

Cheers


By 'COMMAND LINE' I meant manual or menu ie native out of the box  ... sorry you were confused.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.