TheSwamp

Code Red => .NET => Topic started by: bchapman on February 09, 2013, 12:29:51 AM

Title: Variables in String
Post by: bchapman on February 09, 2013, 12:29:51 AM
Can someone please show me how to pass variables in a string. I'm using the following with SendCommand() method but I want the coordinate and the Attribute to be values I collected.  Thanks!

Code: [Select]
string strSend = "-insert ELVTAG \n 0,0 1 45 \n ";
Title: Re: Variables in String
Post by: Kerry on February 09, 2013, 03:47:53 AM

If I understand your request correctly :

You'd need to evaluate the variables in the routine and concatenate the values into the string.

Title: Re: Variables in String
Post by: bchapman on February 09, 2013, 03:51:41 AM
I have the values stored in variables... I just need to figure out how to get them into the string I'm using below in my SendCommand()

Code: [Select]
string strSend = "-insert ELVTAG \n" + COORD + " 1 45 \n ";
is ^ correct? If not what's the right format?
Title: Re: Variables in String
Post by: Kerry on February 09, 2013, 03:54:10 AM
you'll need to convert the value to a string I think.

Should be easy to test.


Title: Re: Variables in String
Post by: bchapman on February 09, 2013, 04:14:54 AM
That was the trick, thanks for sending me on the right path :)

I'm rewriting my lisp library I've developed over 10 years in c#... this is painful lol...

Thanks again for the help
Title: Re: Variables in String
Post by: WILL HATCH on February 11, 2013, 11:35:19 AM
A more elegant way of doing this is using

Code - C#: [Select]
  1. String.Format("-insert ELVTAG \n{0} 1 45 \n ", COORD);
  2.  

otherwise you can create the block reference on your own and do the whole thing behind the scenes
Title: Re: Variables in String
Post by: TheMaster on February 11, 2013, 12:10:10 PM
Can someone please show me how to pass variables in a string. I'm using the following with SendCommand() method but I want the coordinate and the Attribute to be values I collected.  Thanks!

Code: [Select]
string strSend = "-insert ELVTAG \n 0,0 1 45 \n ";

If you followed the advice that Gile offered in another thread regarding using the Editor's RunCommand() method, you wouldn't have this problem because unlike SendCommand(), RunCommand() doesn't require you to convert command input to strings.

The RunCommand() method is the direct equivalent of the LISP (command) function, and like the latter, it accepts numbers, points, selection sets, entity names (ObjectIds in managed code), and so on.