Keywords and GetSelection

Keywords and GetSelection

Anonymous
Not applicable
6,067 Views
16 Replies
Message 1 of 17

Keywords and GetSelection

Anonymous
Not applicable
Isn't it possible to use Keywords with GetSelection.

I tried following code but could not see the keywords.

Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

PromptSelectionOptions BlockOptionPick = new PromptSelectionOptions();

BlockOptionPick.Keywords.Add("Name");

BlockOptionPick.Keywords.Add("Liste");

BlockOptionPick.Keywords.Default = "Name";

BlockOptionPick.SingleOnly = true;

BlockOptionPick.MessageForAdding = "Referenzblock zeigen";

TypedValue[] filList = new TypedValue[1];

filList[0] = new TypedValue((int)DxfCode.Start, "INSERT");

SelectionFilter filter = new SelectionFilter(filList);

PromptSelectionResult BlockResultPick = null;


BlockResultPick = ed.GetSelection(BlockOptionPick, filter);


--
Roland Feletic
0 Likes
6,068 Views
16 Replies
Replies (16)
Message 2 of 17

Anonymous
Not applicable
I'm having the same trouble. Anyone know what's going on?
0 Likes
Message 3 of 17

Sinc
Advisor
Advisor
Has anyone been able to get keywords to work with GetSelection? Is it broken?
Sinc
0 Likes
Message 4 of 17

Anonymous
Not applicable
Post your code that isn't working.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5499514@discussion.autodesk.com...
Has anyone been able to get keywords to work with GetSelection? Is it broken?
0 Likes
Message 5 of 17

Sinc
Advisor
Advisor
Are you saying that you've successfully gotten Keywords to work with the PromptSelectionObjects method?

There is already code posted in this thread that is not substantially different than what I've tried. I've also tried using the SetKeywords method, also with no effect. But if you can point out what's wrong with the code that's already posted, that would answer the question.

I can use Keywords with every other kind of prompt, just not the "Select Objects" prompt.
Sinc
0 Likes
Message 6 of 17

Anonymous
Not applicable
See the KeywordInput event of the
PromptSelectionOptions class.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5500918@discussion.autodesk.com...
Are you saying that you've successfully gotten Keywords to work with the PromptSelectionObjects method?

There is already code posted in this thread that is not substantially different than what I've tried. I've also tried using the SetKeywords method, also with no effect. But if you can point out what's wrong with the code that's already posted, that would answer the question.

I can use Keywords with every other kind of prompt, just not the "Select Objects" prompt.
0 Likes
Message 7 of 17

Anonymous
Not applicable
Usually it takes a little bit of poking around in
the related classes using the object browser, to
find the missing pieces of the puzzle.

Keywords work differently with multiple object
selection, where they are not returned in the
XxxxxResult classes, or by calling a managed
equivalent of the acedGetInput() function.

Instead, they are exposed through an event or
callback mechanism (just as they are in native
ObjectARX .... hint... hint... ).

[code]

// using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;
// using Autodesk.AutoCAD.ApplicationServices;
// using Autodesk.AutoCAD.Runtime;
// using Autodesk.AutoCAD.EditorInput;

public class GetSelectionKeywordSample
{
[CommandMethod( "SSKWORD" )]
public static void SSKWord()
{
Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
PromptSelectionOptions ops = new PromptSelectionOptions();
ops.Keywords.Add( "FOO" );
ops.Keywords.Add( "BAR" );
ops.KeywordInput +=
new SelectionTextInputEventHandler( OnKeywordInput );
PromptSelectionResult res = ed.GetSelection( ops );
}

static void OnKeywordInput( object sender,
SelectionTextInputEventArgs e )
{
Prompt( "\nLOOK ---> Keyord input: {0}", e.Input );
}

private static void Prompt( string fmt, params object args )
{
AcadApp.DocumentManager.MdiActiveDocument.Editor.WriteMessage(
string.Format( fmt, args ) );
}
}

[/code]

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5500918@discussion.autodesk.com...
Are you saying that you've successfully gotten Keywords to work with the PromptSelectionObjects method?

There is already code posted in this thread that is not substantially different than what I've tried. I've also tried using the SetKeywords method, also with no effect. But if you can point out what's wrong with the code that's already posted, that would answer the question.

I can use Keywords with every other kind of prompt, just not the "Select Objects" prompt.
Message 8 of 17

Sinc
Advisor
Advisor
Great, thanks!

This is an excellent example of a place where sample code would make the documentation much clearer.
Sinc
0 Likes
Message 9 of 17

Anonymous
Not applicable
Hi,
I try the code which was posted by Tony but it doesnt work. No Keyword are shown in the Commandline.
Her is the code. Its looks like Tony's

string hPrompt = "\n" + hMenu1 + ": " + hHBOptions.MissingPlaceHeight.ToString() + " mm";
ed.WriteMessage(hPrompt);

hSelectionOptions = new PromptSelectionOptions();
hSelectionOptions.Keywords.Add(hMenu1);
hSelectionOptions.Keywords.Add(hMenuDefault);
// hSelectionOptions.Keywords.Default = hMenuDefault;
hSelectionOptions.KeywordInput += new SelectionTextInputEventHandler( OnMPMakeKeywordInput );

PromptSelectionResult hResult = ed.GetSelection(hSelectionOptions);

The Commandline:
Höhe: 0 mm
Objekte wählen: (You see no keyword are shown)

It would by nice when anybody out there has any tip.

Thanks.
Regards Juergen
0 Likes
Message 10 of 17

Anonymous
Not applicable
GetSelection() doesn't show keywords.

If you want to see the keywords, you have to show them
yourself (I think the property is 'MessageForAdding').

--
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:6389936@discussion.autodesk.com...
Hi,
I try the code which was posted by Tony but it doesnt work. No Keyword are shown
in the Commandline.
Her is the code. Its looks like Tony's

string hPrompt = "\n" + hMenu1 + ": " + hHBOptions.MissingPlaceHeight.ToString()
+ " mm";
ed.WriteMessage(hPrompt);

hSelectionOptions = new PromptSelectionOptions();
hSelectionOptions.Keywords.Add(hMenu1);
hSelectionOptions.Keywords.Add(hMenuDefault);
// hSelectionOptions.Keywords.Default = hMenuDefault;
hSelectionOptions.KeywordInput += new SelectionTextInputEventHandler(
OnMPMakeKeywordInput );

PromptSelectionResult hResult = ed.GetSelection(hSelectionOptions);

The Commandline:
Höhe: 0 mm
Objekte wählen: (You see no keyword are shown)

It would by nice when anybody out there has any tip.

Thanks.
Regards Juergen
0 Likes
Message 11 of 17

Anonymous
Not applicable
Hi Tony,
thanks for your reply but I'm sorry your suggestion doesnt work.

I inserted following code:
hSelectionOptions.MessageForAdding = hPrompt + "[" + hMenu1 + "/" + hMenuDefault + "]";

The Commandline shows this:
Höhe: 0 mm
Fehlstellen wählen:[Höhe/Alle wählen]: h
Fehlstellen wählen:[Höhe/Alle wählen]: a
Fehlstellen wählen:[Höhe/Alle wählen]: H
Fehlstellen wählen:[Höhe/Alle wählen]:

The GetSelection-Method doesnt respond. The breakpoint after the GetSelection-MEthod doesnt reached.



Regards Jürgen
0 Likes
Message 12 of 17

Anonymous
Not applicable
You have to handle the keywords with the event.

--
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:6391300@discussion.autodesk.com...
Hi Tony,
thanks for your reply but I'm sorry your suggestion doesnt work.

I inserted following code:
hSelectionOptions.MessageForAdding = hPrompt + "[" + hMenu1 + "/" + hMenuDefault
+ "]";

The Commandline shows this:
Höhe: 0 mm
Fehlstellen wählen:[Höhe/Alle wählen]: h
Fehlstellen wählen:[Höhe/Alle wählen]: a
Fehlstellen wählen:[Höhe/Alle wählen]: H
Fehlstellen wählen:[Höhe/Alle wählen]:

The GetSelection-Method doesnt respond. The breakpoint after the
GetSelection-MEthod doesnt reached.



Regards Jürgen
0 Likes
Message 13 of 17

Anonymous
Not applicable
Hi Tony,

as you see in the following code I used ths event.

hSelectionOptions = new PromptSelectionOptions();
hSelectionOptions.MessageForAdding = hPrompt + "[" + hMenu1 + "/" + hMenuDefault + "]";
hSelectionOptions.AllowDuplicates = false;
hSelectionOptions.Keywords.Add(hMenu1);
hSelectionOptions.Keywords.Add(hMenuDefault);
hSelectionOptions.Keywords.Default = hMenuDefault;

hSelectionOptions.KeywordInput += new SelectionTextInputEventHandler( OnMPMakeKeywordInput );

PromptSelectionResult hResult = ed.GetSelection(hSelectionOptions);



Regards Jürgen
0 Likes
Message 14 of 17

Anonymous
Not applicable
The code I have that uses keywords with GetSelection()
works. When I type a keyword, the event handler is called.

You're also assuming that a default keyword is supported
by GetSelection(), which is not the case.

--
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:6391777@discussion.autodesk.com...
Hi Tony,

as you see in the following code I used ths event.

hSelectionOptions = new PromptSelectionOptions();
hSelectionOptions.MessageForAdding = hPrompt + "[" + hMenu1 + "/" + hMenuDefault
+ "]";
hSelectionOptions.AllowDuplicates = false;
hSelectionOptions.Keywords.Add(hMenu1);
hSelectionOptions.Keywords.Add(hMenuDefault);
hSelectionOptions.Keywords.Default = hMenuDefault;

hSelectionOptions.KeywordInput += new SelectionTextInputEventHandler(
OnMPMakeKeywordInput );

PromptSelectionResult hResult = ed.GetSelection(hSelectionOptions);



Regards Jürgen
0 Likes
Message 15 of 17

Anonymous
Not applicable
Hi Tony,

thanks for your reply.

Now I knew what happens.
I must not use the normal objectselection keywords like CROSS or WINDOWS. When I use different ones it works.

Many thanks to you. Your help was very usefull.

Regards jürgen
0 Likes
Message 16 of 17

Anonymous
Not applicable

Sorry to have to reinvoke this thread but I am having some trouble with the new keywords being noticed as keywords and thus firing the '.KeywordInput event'. It's also worth noting that the '.KeywordInput' event fires when ONLY the useDefault keyword is entered, all other keywords fire the '.UnkownInput' event. How do I add the keywords so that they are considered keywords and thus fire the correct event?

 

I just noticed some odd behaviour, only the keywords with the following format are recognised (where x = don't care) "xxxxxxxxx_default". Why?

 

Code is as follows.

 

''' <summary>
''' Dimension Encapsulation styles.
''' </summary>
<CommandMethod("TD1")>
Public Shared Sub dimEncapsulation()

    Dim useDefault As String = "USe_default"
    Dim fromLibrary As String = "from_LIbrary"
    Dim manage As String = "MAnage"

    Dim acDoc As Document
    acDoc = Core.Application.DocumentManager.MdiActiveDocument
    Dim ed As Editor = acDoc.Editor
    Dim db As Database = acDoc.Database

    'Retrieve the default encapsulation
    Dim dimEncapsulationSelected As nDimEncapsulation.ciDimEncapsulationStyle = nDimEncapsulation.cDocumentIO.getDefaultPrefix()
    useDefault += " " + dimEncapsulationSelected.prefix.text + "<>" + dimEncapsulationSelected.suffix.text

    Dim promptSelOpt As New PromptSelectionOptions()
    With promptSelOpt
        .Keywords.Add(useDefault)
        .Keywords.Add(fromLibrary)
        .Keywords.Add(manage)
        .Keywords.Default = useDefault
        Dim kws As String = .Keywords.GetDisplayString(False)
        .MessageForAdding = vbNewLine + "Add objects to selection or " + kws
        .MessageForRemoval = vbNewLine + "Remove objects from selection or " + kws

        AddHandler .KeywordInput, AddressOf keywordEntered
        AddHandler .UnknownInput, AddressOf keywordInputNull
    End With

    Dim promptSelRes As PromptSelectionResult = ed.GetSelection(promptSelOpt)

    'Handle the result
    If promptSelRes.Status = PromptStatus.OK Then
        'Start the transaction
        Dim tr As Transaction = db.TransactionManager.StartTransaction
        Using tr

            For Each i As SelectedObject In promptSelRes.Value
                Dim dimension As Dimension = DirectCast(tr.GetObject(i.ObjectId, OpenMode.ForWrite), Dimension)

                dimension.Prefix = dimEncapsulationSelected.prefix.text
                dimension.Suffix = dimEncapsulationSelected.suffix.text
            Next

            'Don't forget to commit the changes to the database
            tr.Commit()
        End Using
    End If

End Sub

 

 

0 Likes
Message 17 of 17

vucic_tamara
Enthusiast
Enthusiast

If someone else is struggling with keywords, here is a part of AutoCAD .NET API documentation where it is stated that underscore can't be part of a keyword when using Editor.GetKeyword method. Maybe the same works for Editor.GetSelection with keywords. 

 

Also one more important thing is to avoid conflict with AutoCAD default PromptSelectionOptions keywords which are listed here.

 

Greetings.

0 Likes