• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Distinguished Contributor
    Posts: 172
    Registered: ‎11-19-2003

    Problem with GetString

    114 Views, 10 Replies
    06-21-2007 05:19 AM
    I wanted to ask for some stings, in this case for a prefix and a suffix.

    I do it with something like the following code
    ~~~~~~~~~~~~~~~
    PromptStringOptions optString = new PromptStringOptions("\nPrefix");

    optString.AllowSpaces = true;

    PromptResult prString = ed.GetString(optString);

    ~~~~~~~~~~~~~~~~~~~~

    If I write "km " or " km" for the string, it allways returns "km" without
    the spaces.

    Is it possible to get these spaces, too?

    Roland
    Please use plain text.
    Distinguished Contributor
    Posts: 1,986
    Registered: ‎08-02-2004

    Re: Problem with GetString

    06-21-2007 05:40 AM in reply to: RolandF
    Realy strange, your code works
    for me in A2007

    ~'J'~

    public class StringUtils
    {
    [CommandMethod("CTX")]
    public static void SpaceText()
    {
    Document doc = acadApp.DocumentManager.MdiActiveDocument;
    Editor ed = doc.Editor;
    string s = "1000";
    PromptStringOptions optString = new PromptStringOptions("\nPrefix: ");
    optString.AllowSpaces = true;
    PromptResult prString = ed.GetString(optString);
    string p = prString.StringResult;
    MessageBox.Show(string.Format("Result: {0}", s + p));
    }
    }
    Please use plain text.
    Distinguished Contributor
    Posts: 172
    Registered: ‎11-19-2003

    Re: Problem with GetString

    06-21-2007 05:49 AM in reply to: RolandF
    Thank you, Fatty.

    I work with 2008, and there I get the wrong result. With your example when i
    type " km" the MessageBox shows: "Result: 1000km" and not "Result: 1000 km".
    Very strange. Does anyone have the same problem?

    Roland

    schrieb im Newsbeitrag news:5633520@discussion.autodesk.com...
    Realy strange, your code works
    for me in A2007

    ~'J'~

    public class StringUtils
    {
    [CommandMethod("CTX")]
    public static void SpaceText()
    {
    Document doc = acadApp.DocumentManager.MdiActiveDocument;
    Editor ed = doc.Editor;
    string s = "1000";
    PromptStringOptions optString = new PromptStringOptions("\nPrefix: ");
    optString.AllowSpaces = true;
    PromptResult prString = ed.GetString(optString);
    string p = prString.StringResult;
    MessageBox.Show(string.Format("Result: {0}", s + p));
    }
    }
    Please use plain text.
    Distinguished Contributor
    Posts: 172
    Registered: ‎11-19-2003

    Re: Problem with GetString

    06-21-2007 07:06 AM in reply to: RolandF
    Hi Fatty,
    I tried it now in 2007 and it also doesn't work there.
    Does it really work correct for you?

    Roland
    Please use plain text.
    Distinguished Contributor
    Posts: 1,986
    Registered: ‎08-02-2004

    Re: Problem with GetString

    06-21-2007 08:23 AM in reply to: RolandF
    Hi Roland, yes it does work nice
    But in fact I use VB.NET, I just converted
    my code for you
    tested on A2007 only
    Here is it

    _
    Public Shared Sub SpaceText()
    Dim doc As Document = acadApp.DocumentManager.MdiActiveDocument
    Dim ed As Editor = doc.Editor
    Dim s As String = "1000"
    Dim optString As PromptStringOptions = New PromptStringOptions(vbcr & "Prefix: ")
    optString.AllowSpaces = True
    Dim prString As PromptResult = ed.GetString(optString)
    Dim p As String = prString.StringResult
    MessageBox.Show(String.Format("Result: {0}", s & p))
    End Sub

    ~'J'~
    Please use plain text.
    Distinguished Contributor
    Posts: 1,986
    Registered: ‎08-02-2004

    Re: Problem with GetString

    06-21-2007 08:29 AM in reply to: RolandF
    This works also with suffix and prefix
    See picture

    _
    Public Shared Sub SpaceText()
    Dim doc As Document = acadApp.DocumentManager.MdiActiveDocument
    Dim ed As Editor = doc.Editor
    Dim s As String = "1000"
    Dim optString As PromptStringOptions = New PromptStringOptions("\nPrefix")
    optString.AllowSpaces = True
    Dim prString As PromptResult = ed.GetString(optString)
    Dim p As String = prString.StringResult
    MessageBox.Show(String.Format("Result: {0}", p & s))
    End Sub

    ~'J'~
    Please use plain text.
    Distinguished Contributor
    Posts: 172
    Registered: ‎11-19-2003

    Re: Problem with GetString

    06-21-2007 09:35 PM in reply to: RolandF
    Thank you, again, Fatty.
    So this seems to be a bug in C#.

    Roland
    Please use plain text.
    Distinguished Contributor
    Posts: 445
    Registered: ‎12-02-2004

    Re: Problem with GetString

    06-24-2007 03:10 PM in reply to: RolandF
    It is working here using A2007

    [code]
    [CommandMethod("OTXT")]
    public void otxt()
    {
    Document doc = acadApp.DocumentManager.MdiActiveDocument;
    Editor ed = doc.Editor;
    PromptStringOptions optString = new PromptStringOptions("\nPrefix");
    optString.AllowSpaces = true;
    PromptResult prString = ed.GetString(optString);
    ed.WriteMessage("\nReturn: 1000" + prString.StringResult);
    }
    [/code]
    Please use plain text.
    Distinguished Contributor
    Posts: 172
    Registered: ‎11-19-2003

    Re: Problem with GetString

    06-24-2007 10:07 PM in reply to: RolandF
    Thank you, Luis.
    Your code also didn't work for me with 2007. Therefore I wanted to make a
    screenshot of the text-window and saw that the input had no spaces allthough
    I typed them in. Then I tried this command with opened text-window and it
    worked. So the problem is not the command, it is AutoCAD. I use the dynamic
    input, and with this it does not work.
    Am I right that no one of you does work with dynamic input and therefore you
    had no problems? I think so.

    Roland
    Please use plain text.
    *Luis Esquivel

    Re: Problem with GetString

    06-25-2007 06:27 AM in reply to: RolandF
    Hi Roland;

    Yes I use the dyn-input too, but did not tested with that, last night, I'll
    check a little later, and post the result here :smileyhappy:

    >>Am I right that no one of you does work with dynamic input and therefore
    >>you had no problems? I think so.
    Please use plain text.