TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Pad on October 09, 2015, 07:17:38 AM

Title: Split text string into variables
Post by: Pad 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
Title: Re: Split text string into variables
Post by: Lee Mac 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 (http://www.lee-mac.com/stringtolist.html) 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) ","))
Title: Re: Split text string into variables
Post by: Pad on October 09, 2015, 08:59:38 AM
Ah great. Thanks!
P