TheSwamp

Code Red => .NET => Topic started by: T.Willey on June 12, 2007, 02:52:01 PM

Title: DeSelect current selectin set from Tool Palette
Post by: T.Willey on June 12, 2007, 02:52:01 PM
I have code that will make a tool palette, and fill it with combo boxes and put one button on it.  I use the current selection set to populate the tool palette (single block with attributes).  Everything works fine except that I can't figure out how to deselect the objects once the button is pushed.  Any help/comments are appreciated.

Thanks in advance.

Question in reference to here. (http://www.theswamp.org/index.php?topic=16861.0)  Posting new thread because this question may get lost in the other one.

I have seen this method posted on the Adesk Ng, but didn't work for me.
Code: [Select]
PromptSelectionResult psr = Doc.Editor.SelectImplied();
psr = null;
Title: Re: DeSelect current selectin set from Tool Palette
Post by: Paul Richardson on June 12, 2007, 03:07:38 PM
I have code that will make a tool palette, and fill it with combo boxes and put one button on it.  I use the current selection set to populate the tool palette (single block with attributes).  Everything works fine except that I can't figure out how to deselect the objects once the button is pushed.  Any help/comments are appreciated.

Thanks in advance.

Question in reference to here. (http://www.theswamp.org/index.php?topic=16861.0)  Posting new thread because this question may get lost in the other one.

I have seen this method posted on the Adesk Ng, but didn't work for me.
Code: [Select]
PromptSelectionResult psr = Doc.Editor.SelectImplied();
psr = null;

Tim - I think I'm the one who posted that code... Strange it does work for me. I just tried this on a block
with references and it works here. Maybe another way to do it?

Code: [Select]
Editor ed =
    Autodesk.AutoCAD.ApplicationServices.Application.
        DocumentManager.MdiActiveDocument.Editor;
PromptSelectionResult psr = ed.SelectImplied();
psr = null;

Title: Re: DeSelect current selectin set from Tool Palette
Post by: T.Willey on June 12, 2007, 03:19:43 PM
That didn't work either Paul.  I think the issue is trying to deselect from the tool palette.  Did you get it to work from a tool palette?
Title: Re: DeSelect current selectin set from Tool Palette
Post by: LE on June 12, 2007, 03:29:53 PM
Hey Tim;

How about using: SetImpliedSelection()

ed.SetImpliedSelection(new ObjectId[0]);
Title: Re: DeSelect current selectin set from Tool Palette
Post by: T.Willey on June 12, 2007, 03:37:55 PM
Hey Tim;

How about using: SetImpliedSelection()

ed.SetImpliedSelection(new ObjectId[0]);
Build error.
Quote
error CS1501: No overload for method 'SelectImplied' takes '1' arguments
c:\Program Files\Autodesk\Acade 2006\acmgd.dll: (Location of symbol related to previous error)
Code: [Select]
Doc.Editor.SelectImplied(new ObjectId[0]);

Man this is frustrating.

Edit:
Now using the correct code.  Man, still get build error.
Quote
error CS0117: 'Autodesk.AutoCAD.EditorInput.Editor' does not contain a definition for 'SetImpliedSelection'

On Acad '06
Title: Re: DeSelect current selectin set from Tool Palette
Post by: LE on June 12, 2007, 03:42:15 PM
Hey Tim;

How about using: SetImpliedSelection()

ed.SetImpliedSelection(new ObjectId[0]);
Build error.
Quote
error CS1501: No overload for method 'SelectImplied' takes '1' arguments
c:\Program Files\Autodesk\Acade 2006\acmgd.dll: (Location of symbol related to previous error)
Code: [Select]
Doc.Editor.SelectImplied(new ObjectId[0]);

Man this is frustrating.

Count to 10... 9 8 7 6 5 4 3 2 1 0...

I simple posted from memory, don't have my vs open....
Title: Re: DeSelect current selectin set from Tool Palette
Post by: LE on June 12, 2007, 03:57:30 PM
It is working here, as far as I see it...

Code: [Select]
       public static  void onDocBecameCurrent(object sender, DocumentCollectionEventArgs e)
        {
            Document doc = AcadApp.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            ed.SetImpliedSelection(new ObjectId[0]);//clear first any selection
            if (!ps.Visible) return;
            PromptSelectionResult psr = e.Document.Editor.SelectImplied() as PromptSelectionResult;
            //if (psr == null) return;
            SelectionSet ss = psr.Value as SelectionSet;
            if (ss != null && ss.Count > 0) FillInControl(ss.GetObjectIds());
            else if (ps.Count > 0) ps.Remove(0);
        }
Title: Re: DeSelect current selectin set from Tool Palette
Post by: Paul Richardson on June 12, 2007, 03:58:31 PM
That didn't work either Paul.  I think the issue is trying to deselect from the tool palette.  Did you get it to work from a tool palette?

I haven't tried...
Title: Re: DeSelect current selectin set from Tool Palette
Post by: T.Willey on June 12, 2007, 04:02:02 PM
It is working here, as far as I see it...

Code: [Select]
       public static  void onDocBecameCurrent(object sender, DocumentCollectionEventArgs e)
        {
            Document doc = AcadApp.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            ed.SetImpliedSelection(new ObjectId[0]);//clear first any selection
            if (!ps.Visible) return;
            PromptSelectionResult psr = e.Document.Editor.SelectImplied() as PromptSelectionResult;
            //if (psr == null) return;
            SelectionSet ss = psr.Value as SelectionSet;
            if (ss != null && ss.Count > 0) FillInControl(ss.GetObjectIds());
            else if (ps.Count > 0) ps.Remove(0);
        }
What version are you testing on?
Title: Re: DeSelect current selectin set from Tool Palette
Post by: LE on June 12, 2007, 04:03:01 PM
2007
Title: Re: DeSelect current selectin set from Tool Palette
Post by: T.Willey on June 12, 2007, 04:04:07 PM
2007
Must be new to 2007 because I get a build error when trying it with 2006.
Title: Re: DeSelect current selectin set from Tool Palette
Post by: LE on June 12, 2007, 04:09:58 PM
no idea Tim.

this is what I see on the object browser:
Title: Re: DeSelect current selectin set from Tool Palette
Post by: LE on June 12, 2007, 04:17:08 PM
In case is not there, do you know how to use P/Invoke? (because I do not)... that function is a wrapper from the ARX functions of:

acedSSSetFirst()
acedSSFree()
Title: Re: DeSelect current selectin set from Tool Palette
Post by: T.Willey on June 12, 2007, 05:00:07 PM
In case is not there, do you know how to use P/Invoke? (because I do not)... that function is a wrapper from the ARX functions of:

acedSSSetFirst()
acedSSFree()
If this is the only way in .Net (for '06), then I guess I better learn about P/Invoke.  Thanks for the heads up Luis.  I'll see what I can find.

Edit: Found this link. (http://through-the-interface.typepad.com/through_the_interface/2006/07/calling_objecta.html)  Reading it now.
Title: Re: DeSelect current selectin set from Tool Palette
Post by: Paul Richardson on June 12, 2007, 08:05:55 PM
In case is not there, do you know how to use P/Invoke? (because I do not)... that function is a wrapper from the ARX functions of:

acedSSSetFirst()
acedSSFree()
If this is the only way in .Net (for '06), then I guess I better learn about P/Invoke.  Thanks for the heads up Luis.  I'll see what I can find.

Edit: Found this link. (http://through-the-interface.typepad.com/through_the_interface/2006/07/calling_objecta.html)  Reading it now.

For now you could try this - until you master P/Invoke...:)

 object o = AcadApp.GetSystemVariable("Pickfirst");
 AcadApp.SetSystemVariable("Pickfirst", o);
Title: Re: DeSelect current selectin set from Tool Palette
Post by: Glenn R on June 13, 2007, 01:11:14 AM
Something like this perhaps:

Code: [Select]
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, EntryPoint = "acedSSSetFirst")]
private static extern int acedSSetFirst(long[] pset, long[] unused);


[CommandMethod("SetFirstTest", CommandFlags.UsePickSet | CommandFlags.Redraw | CommandFlags.Modal)]
static public void SetFirstTestCommand( ) {
Document doc = acadApp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;

try {

PromptSelectionResult prs = ed.SelectImplied();
if(prs.Status != PromptStatus.OK)
return;

SelectionSet ss = prs.Value;
ed.WriteMessage("\nNumber of selected objects: {0}", ss.Count);

acedSSetFirst(null, null);

} catch(System.Exception ex) {
ed.WriteMessage(ex.Message);
}
}


Completely untested of course :)

Cheers,
Glenn.
Title: Re: DeSelect current selectin set from Tool Palette
Post by: Paul Richardson on June 13, 2007, 08:34:52 AM
Something like this perhaps:

Code: [Select]
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, EntryPoint = "acedSSSetFirst")]
private static extern int acedSSetFirst(long[] pset, long[] unused);


[CommandMethod("SetFirstTest", CommandFlags.UsePickSet | CommandFlags.Redraw | CommandFlags.Modal)]
static public void SetFirstTestCommand( ) {
Document doc = acadApp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;

try {

PromptSelectionResult prs = ed.SelectImplied();
if(prs.Status != PromptStatus.OK)
return;

SelectionSet ss = prs.Value;
ed.WriteMessage("\nNumber of selected objects: {0}", ss.Count);

acedSSetFirst(null, null);

} catch(System.Exception ex) {
ed.WriteMessage(ex.Message);
}
}


Completely untested of course :)

Cheers,
Glenn.

Glenn, Do you know why most of the names are mangled but some not?
Thanks.
Title: Re: DeSelect current selectin set from Tool Palette
Post by: It's Alive! on June 13, 2007, 08:58:04 AM
I know you asked Glenn, but… :-P
The function was probably exported as a global function for ARX, but not yet wrapped for .NET
Title: Re: DeSelect current selectin set from Tool Palette
Post by: Glenn R on June 13, 2007, 09:07:58 AM
It has to do with the c++ compiler, function exports and name collisions wrt the vtable AFAIK.

Cheers,
Glenn.
Title: Re: DeSelect current selectin set from Tool Palette
Post by: Paul Richardson on June 13, 2007, 09:40:04 AM
I know you asked Glenn, but… :-P
The function was probably exported as a global function for ARX, but not yet wrapped for .NET


Well... I meant anyone with the answer...~) Thanks...
Title: Re: DeSelect current selectin set from Tool Palette
Post by: Paul Richardson on June 13, 2007, 09:41:33 AM
It has to do with the c++ compiler, function exports and name collisions wrt the vtable AFAIK.

Cheers,
Glenn.

Danka... Just curious.
Title: Re: DeSelect current selectin set from Tool Palette
Post by: T.Willey on June 13, 2007, 11:19:51 AM
For now you could try this - until you master P/Invoke...:)
This doesn't look like it will happen anytime soon.  :-)  I didn't understand the article on first read, so I have to reread it when I have more time to comprehend it.

object o = AcadApp.GetSystemVariable("Pickfirst");
 AcadApp.SetSystemVariable("Pickfirst", o);
This worked nicely.  I will post the full code in the other thread as that is where it is posted now.

Thanks Paul!
Title: Re: DeSelect current selectin set from Tool Palette
Post by: T.Willey on June 13, 2007, 11:33:47 AM
Something like this perhaps:

Code: [Select]
[DllImport("acad.exe", CallingConvention = CallingConvention.Cdecl, EntryPoint = "acedSSSetFirst")]
private static extern int acedSSetFirst(long[] pset, long[] unused);


[CommandMethod("SetFirstTest", CommandFlags.UsePickSet | CommandFlags.Redraw | CommandFlags.Modal)]
static public void SetFirstTestCommand( ) {
Document doc = acadApp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;

try {

PromptSelectionResult prs = ed.SelectImplied();
if(prs.Status != PromptStatus.OK)
return;

SelectionSet ss = prs.Value;
ed.WriteMessage("\nNumber of selected objects: {0}", ss.Count);

acedSSetFirst(null, null);

} catch(System.Exception ex) {
ed.WriteMessage(ex.Message);
}
}


Completely untested of course :)

Cheers,
Glenn.
Thanks for the example Glenn.  I will try and understand it when I have more time later today.

Edit: May take more time than I originally thought. =D  Need to study up on DllImport.
Title: Re: DeSelect current selectin set from Tool Palette
Post by: T.Willey on June 13, 2007, 06:56:31 PM
Thanks Glenn that worked with one small correction.  The function name is 'SSSetFirst', with three 's'.

I have the program 'depends', and I see the call to 'SSSetFirst' within there, but the entry point is a number.  How do I know which one to use (for future situations)?
Title: Re: DeSelect current selectin set from Tool Palette
Post by: Glenn R on June 13, 2007, 07:11:33 PM
Tim,

The function name was correct in my code (look at the entrypoint)...I just dropped an 'S' in my alias of it, which doesn't matter (you could it anything you want).

I use "Dumpbin /E" on the file and redirect it's output to a text file...that will give you all the names.

Glenn.
Title: Re: DeSelect current selectin set from Tool Palette
Post by: T.Willey on June 13, 2007, 07:22:38 PM
Tim,

The function name was correct in my code (look at the entrypoint)...I just dropped an 'S' in my alias of it, which doesn't matter (you could it anything you want).
I thought I looked there first.  Must have thought you named them all the same.  :wink:

I use "Dumpbin /E" on the file and redirect it's output to a text file...that will give you all the names.

Glenn.
I think that is how Kean said to do it on his blog (nope, but something like this method).  I was hoping there would be an easier way.

Thanks again.
Title: Re: DeSelect current selectin set from Tool Palette
Post by: Paul Richardson on June 13, 2007, 10:11:58 PM
Tim,

The function name was correct in my code (look at the entrypoint)...I just dropped an 'S' in my alias of it, which doesn't matter (you could it anything you want).
I thought I looked there first.  Must have thought you named them all the same.  :wink:

I use "Dumpbin /E" on the file and redirect it's output to a text file...that will give you all the names.

Glenn.
I think that is how Kean said to do it on his blog (nope, but something like this method).  I was hoping there would be an easier way.

Thanks again.
To use Fenton's method save the batch as findfile.bat (or whatever you like) to your acad root. Using VS comamnd prompt call as such - findfile.bat functionname If you want to write to a text file use the redirection operator as stated findfile.bat functionname > text.txt. This is slow so be patient...

Edit: Browse (cd) to the acad root in the command line tool before running.