.NET

Reply
Distinguished Contributor
RolandF
Posts: 172
Registered: ‎11-19-2003
Message 1 of 11 (136 Views)

Problem with GetString

136 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
Distinguished Contributor
Fatty
Posts: 1,986
Registered: ‎08-02-2004
Message 2 of 11 (136 Views)

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));
}
}
Distinguished Contributor
RolandF
Posts: 172
Registered: ‎11-19-2003
Message 3 of 11 (136 Views)

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));
}
}
Distinguished Contributor
RolandF
Posts: 172
Registered: ‎11-19-2003
Message 4 of 11 (136 Views)

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
Distinguished Contributor
Fatty
Posts: 1,986
Registered: ‎08-02-2004
Message 5 of 11 (136 Views)

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'~
Distinguished Contributor
Fatty
Posts: 1,986
Registered: ‎08-02-2004
Message 6 of 11 (136 Views)

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'~
Distinguished Contributor
RolandF
Posts: 172
Registered: ‎11-19-2003
Message 7 of 11 (136 Views)

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
Distinguished Contributor
Luis Esquivel
Posts: 445
Registered: ‎12-02-2004
Message 8 of 11 (136 Views)

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]
Distinguished Contributor
RolandF
Posts: 172
Registered: ‎11-19-2003
Message 9 of 11 (136 Views)

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
*Luis Esquivel
Message 10 of 11 (136 Views)

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.
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!