Author Topic: Variables in String  (Read 2025 times)

0 Members and 1 Guest are viewing this topic.

bchapman

  • Guest
Variables in String
« 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 ";

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Variables in String
« Reply #1 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.

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

bchapman

  • Guest
Re: Variables in String
« Reply #2 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?
« Last Edit: February 09, 2013, 03:59:38 AM by BC_in_NV »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Variables in String
« Reply #3 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.


kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

bchapman

  • Guest
Re: Variables in String
« Reply #4 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
« Last Edit: February 09, 2013, 04:24:46 AM by BC_in_NV »

WILL HATCH

  • Bull Frog
  • Posts: 450
Re: Variables in String
« Reply #5 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

TheMaster

  • Guest
Re: Variables in String
« Reply #6 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.