.NET

Reply
Mentor
matus.brlit
Posts: 244
Registered: ‎03-11-2008
Message 1 of 11 (442 Views)
Accepted Solution

GetString with Keywords FATAL ERROR

442 Views, 10 Replies
03-16-2012 02:43 AM

Hi,

i encountered a problem, when I try to use GetString with Keywords

 

Dim optString As New PromptStringOptions("Zadaj nazov: ")
optString.Keywords.Add("Vypisat")

Dim resPrompt As PromptResult = ed.GetString(optString)

 

AutoCAD crashes with FATAL ERROR on the last line.

Valued Contributor
Paulio
Posts: 82
Registered: ‎06-26-2008
Message 2 of 11 (434 Views)

Re: GetString with Keywords FATAL ERROR

03-16-2012 03:50 AM in reply to: matus.brlit

You need to use PromptKeywordOptions like this:

 

            Dim optstring As New PromptKeywordOptions("Zadaj nazov: ")
            optstring.Keywords.Add("Vypisat")
            Dim resPrompt As PromptResult = ed.GetKeywords(optstring)

 Hope that helps.

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 3 of 11 (432 Views)

Re: GetString with Keywords FATAL ERROR

03-16-2012 03:52 AM in reply to: matus.brlit

You can't add keywords to Getstring method

But you might be want to use DefaultValue property

to get possibility for empty input

And also you always use Try.. Catch statement to

save your working time :smileyhappy:

See sample:

        Public Sub testkwords()
            Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
            Dim db As Database = doc.Database
            Dim ed As Editor = doc.Editor
            Try
                Dim optString As New PromptStringOptions("Zadaj nazov: ")
                optString.UseDefaultValue = True
                optString.AppendKeywordsToMessage = True
                optString.DefaultValue = "Vypisat"
                Dim resPrompt As PromptResult = ed.GetString(optString)
                If resPrompt.Status <> PromptStatus.OK Then
                    Return
                End If
                Dim strRes As String = resPrompt.StringResult
                MsgBox(strRes)
            Catch ex As System.Exception
                MsgBox(ex.Message + vbCrLf + ex.StackTrace)
            Finally

            End Try
        End Sub

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Mentor
matus.brlit
Posts: 244
Registered: ‎03-11-2008
Message 4 of 11 (420 Views)

Re: GetString with Keywords FATAL ERROR

03-16-2012 04:10 AM in reply to: matus.brlit

to Paulio: keyword prompt only allows to enter keyword, i want an user inputed string, or a keyword

 

to Hallex: Thanks for the workaround. That's strange, that PromptStringOptions has a Property Keywords and then throws an exception saying Keywords are not allowed.

I think that I will have to stick with this, but it's strange to have a Keyword in <> instead of [], very odd behavior. Whay if I wanted to have more than one keyword?

 

 

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 5 of 11 (405 Views)

Re: GetString with Keywords FATAL ERROR

03-16-2012 07:36 AM in reply to: matus.brlit

If you need to add more than one keyword

you have to use ed.getkword method, see examples,

hope you will be undrerstand how to use this functions,

feel free to adopt them to your needs:

        Function PromptKeyWords(ByVal PromptStr As String, ByVal kwords As String(), ByVal deflt As String) As Boolean
            Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor

            Dim prOpt As PromptKeywordOptions = New PromptKeywordOptions(PromptStr)
            Dim prRes As PromptResult = Nothing
            prOpt.AppendKeywordsToMessage = True
            For Each wd As String In kwords
                prOpt.Keywords.Add(wd)
            Next
            prOpt.Keywords.Default = deflt
            prOpt.SetMessageAndKeywords(PromptStr, "[Yes/No]")
            prOpt.Keywords.Add("[")

            prOpt.Keywords.Add("[")

            prOpt.AppendKeywordsToMessage = True

            prRes = ed.GetKeywords(prOpt)

            If prRes.Status = PromptStatus.Cancel Then
                MsgBox("Error: user cancelled")
                Return False
            Else
                MsgBox(prRes.StringResult)
                Return True
            End If

        End Function


        Public Shared Function GetKwordOut(ByVal ed As Editor, ByVal msg As String, ByVal kwords As String()) As String
            Dim pko As New PromptKeywordOptions(vbLf + msg)
            pko.AllowNone = True

            For Each itm As String In kwords
                pko.Keywords.Add(itm)
            Next
            pko.Keywords.Default = kwords.GetValue(kwords.Length - 1).ToString()
            Dim pkr As PromptResult = ed.GetKeywords(pko)
            If pkr.Status <> PromptStatus.OK Then
                Return String.Empty
            Else
                Return pkr.StringResult
            End If
        End Function

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Mentor
matus.brlit
Posts: 244
Registered: ‎03-11-2008
Message 6 of 11 (390 Views)

Re: GetString with Keywords FATAL ERROR

03-19-2012 12:01 AM in reply to: Hallex

Hallex, you didn't understand what I meat.

 

I want a string prompt, i want user to be able to enter a string, any string and also be able to choose a keyword for some action. But I guess it's not possible.

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 7 of 11 (384 Views)

Re: GetString with Keywords FATAL ERROR

03-19-2012 01:46 AM in reply to: matus.brlit

Sorry, Matus

I have disagreed completely

You didn't understand how to use the function I posted

Please, try complete solution:

       <CommandMethod("MatusBrilt", "matus", CommandFlags.Modal)> _
    Public Sub SampleTest()
        Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
        Dim kwords As String() = {"Rectangle", "Circle", "Ellipse", "Squiggle"}
        Dim strout As String = GetKwordOut(ed, vbLf + "Choose a Shape Type or Enter Another Type You Want: ", kwords)
        ed.WriteMessage(vbLf + "{0}", strout)
    End Sub



    Public Shared Function GetKwordOut(ByVal ed As Editor, ByVal msg As String, ByVal kwords As String()) As String
        Dim pko As New PromptKeywordOptions(vbLf + msg)
        pko.AllowNone = True
        pko.AllowArbitraryInput = True
        For Each itm As String In kwords
            pko.Keywords.Add(itm)
        Next
        pko.Keywords.Default = kwords.GetValue(kwords.Length - 1).ToString()
        Dim pkr As PromptResult = ed.GetKeywords(pko)
        If pkr.Status <> PromptStatus.OK Then
            Return String.Empty
        Else
            Return pkr.StringResult
        End If
    End Function

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Mentor
matus.brlit
Posts: 244
Registered: ‎03-11-2008
Message 8 of 11 (379 Views)

Re: GetString with Keywords FATAL ERROR

03-19-2012 01:57 AM in reply to: Hallex

If I enter anything else in the eg.GetKeywords prompt, I get an error "Invalid option keyword." and I am prompted again.

 

I use AutoCAD 2012.

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 9 of 11 (373 Views)

Re: GetString with Keywords FATAL ERROR

03-19-2012 02:41 AM in reply to: matus.brlit

You have to copy code I posted in the last post because I've added

ArbitaryInput=True in this function

Then it will be work as you need, see what I have a got after running the code

(tested on 2010th) :

 

 

Command: MATUS Choose a Shape Type or Enter Another Type You Want [Rectangle/Circle/Ellipse/Squiggle] <Squiggle>: Trapezoid

 Trapezoid

 Command:

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Mentor
matus.brlit
Posts: 244
Registered: ‎03-11-2008
Message 10 of 11 (366 Views)

Re: GetString with Keywords FATAL ERROR

03-19-2012 03:24 AM in reply to: Hallex

oh, finally :smileyhappy:

 

thank you very much, I missed that one

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