Author Topic: Split text string into variables  (Read 1341 times)

0 Members and 1 Guest are viewing this topic.

Pad

  • Bull Frog
  • Posts: 330
Split text string into variables
« on: October 09, 2015, 07:17:38 AM »
Hi

I would like to split some text strings into variables,  the idea is to click on the text string them click on a block and the corresponding attributes are automatically populated.
In the future I'm going to try and expand this lisp so that it is fully automatic, the text is always in the same position relative to the block insertion point.  But obviously this changes depending on the drawing scale.  But for now I'd like to get a semi-automatic version working.

These two examples are typical:

A0.25,5,4,2,4

var1 = A
var2 = 0.25
var3 = 5,4,2,4

T0.3,2.5

var4 = T
var5 = 0.3
var6 = 2.5

Any help with this would be appreciated.
Thanks
Pad

Lee Mac

  • Seagull
  • Posts: 12711
  • London, England
Re: Split text string into variables
« Reply #1 on: October 09, 2015, 07:57:44 AM »
Assuming the first item will always be a single character, you could use my String to List function in the following way:

Code - Auto/Visual Lisp: [Select]
  1. (setq str "A0.25,5,4,2,4")
  2. (cons (substr str 1 1) (LM:str->lst (substr str 2) ","))

Pad

  • Bull Frog
  • Posts: 330
Re: Split text string into variables
« Reply #2 on: October 09, 2015, 08:59:38 AM »
Ah great. Thanks!
P