From: Erik Halvarsson
Subject: AutoLISP help required: Is there a way to split up one element into several?
Date:
Message-ID: <38E4935A.AAA62B10@hotmail.com>
AKW wanted me to repost this with the word AutoLISP in the subject, so
thats what I'll do. Thanks to all who answered my last thread ;)
I am coding some stuff in AutoLISP, AutoCAD R14.
From an external file I need to get some data, and it's stored like:
VKA100 707898.512 78172.497 143.803
a simple xyz coordinate. When I use the (readline file) function, that
string becomes one single element in the list I assign it to. What I
need is four different elements in the list but I have so far no clue
how to achive this. Would be great if anyone out there could help me.
Erik Halvarsson
············@hotmail.com
From: Andrew K. Wolven
Subject: Re: AutoLISP help required: Is there a way to split up one element into several?
Date:
Message-ID: <38E4B632.D36A2617@redfernlane.org>
I didn't debug this, because you just reminded me that AutoLISP is like
driving a car with the windsheild painted black.
ex:
Command: (parse-line " abc 123 lala foo ")
("abc" "123" "lala" "foo")
Command:
note: you may have to do read on the individual strings if you want them
to be numbers:
(mapcar 'read '("some-text" "24.654" "6.5"))
=>
(SOME-TEXT 24.654 6.5)
(defun parse-line (string)
(setq *clean-string* (remove-leading-whitespace
string))
(setq *chunk* (chew-and-spit *clean-string*))
(setq *rest* (remove-leading-whitespace
(substr *clean-string* (1+ (strlen *chunk*)))))
(if (eq "" *rest*)
(list *chunk*)
(cons *chunk*
(parse-line *rest*))))
(defun chew-and-spit (string)
(if (or (zerop (strlen string))
(eq " " (substr string 1 1)))
""
(strcat (substr string 1 1)
(chew-and-spit (substr string 2)))))
(defun remove-leading-whitespace (string)
(if (eq " " (substr string 1 1))
(remove-leading-whitespace (substr string 2))
string))
-AKW
P.S.: Do your self a favor and get common-lisp (or scheme)
http://www.corman.net/CormanLisp.html
Erik Halvarsson wrote:
> AKW wanted me to repost this with the word AutoLISP in the subject, so
> thats what I'll do. Thanks to all who answered my last thread ;)
>
> I am coding some stuff in AutoLISP, AutoCAD R14.
> From an external file I need to get some data, and it's stored like:
>
> VKA100 707898.512 78172.497 143.803
>
> a simple xyz coordinate. When I use the (readline file) function, that
> string becomes one single element in the list I assign it to. What I
> need is four different elements in the list but I have so far no clue
> how to achive this. Would be great if anyone out there could help me.
>
> Erik Halvarsson
> ············@hotmail.com
In article <·················@redfernlane.org>, "Andrew K. Wolven"
<·······@redfernlane.org> wrote:
>I didn't debug this, because you just reminded me that AutoLISP is like
>driving a car with the windsheild painted black.
>
> ...
>
>P.S.: Do your self a favor and get common-lisp (or scheme)
I doubt he has a choice. In AutoCAD it's AutoLisp (several
strains) or a dialect of Basic. Given those choices, I
assume you'd recommend he stick with AutoLisp, no?
From: Andrew K. Wolven
Subject: Re: AutoLISP help required: Is there a way to split up one element into several?
Date:
Message-ID: <38E561F5.D4A25C87@redfernlane.org>
Chris Riesbeck wrote:
> In article <·················@redfernlane.org>, "Andrew K. Wolven"
> <·······@redfernlane.org> wrote:
>
> >I didn't debug this, because you just reminded me that AutoLISP is like
> >driving a car with the windsheild painted black.
> >
> > ...
> >
> >P.S.: Do your self a favor and get common-lisp (or scheme)
>
> I doubt he has a choice. In AutoCAD it's AutoLisp (several
> strains) or a dialect of Basic. Given those choices, I
> assume you'd recommend he stick with AutoLisp, no?
I think that If I were being forced to use AutoCAD,
I would link in a Common Lisp as an ARX application.
(or whatever they call ARX for the new version)
There are at least 12 different ways to interface CL to CAD software
I programmed AutoLISP for a while and realized CL was vastly superior.
Today was the first time I have used AutoLISP since then.
AKW
From: Andrew McDowell
Subject: Re: AutoLISP help required: Is there a way to split up one element into several?
Date:
Message-ID: <8c3apo$c6h$1@hammer.msfc.nasa.gov>
Erik Halvarsson <············@hotmail.com> wrote:
...
> I am coding some stuff in AutoLISP, AutoCAD R14.
> From an external file I need to get some data, and it's stored like:
>
> VKA100 707898.512 78172.497 143.803
>
> a simple xyz coordinate. When I use the (readline file) function, that
> string becomes one single element in the list I assign it to. What I
> need is four different elements in the list but I have so far no clue
> how to achive this. Would be great if anyone out there could help me.
I'm _very_ new to this, but would something like the following work ?
=-=-=-=-=-=-=-=
(defun string-split-ex (mystring seperator subscript result)
(if (not (= (length mystring) 0))
(if (string-equal seperator (substring mystring subscript (+ subscript
(length seperator))))
(if (eq subscript 0)
(string-split-ex
(substring mystring (+ (length seperator) subscript))
seperator
0
result)
(string-split-ex
(substring mystring (+ (length seperator) subscript))
seperator
0
(append result (list (substring mystring 0 subscript)))))
(if (>= (length seperator) (- (length mystring) subscript)) (append
result (list mystring))
(string-split-ex mystring seperator (1+ subscript) result)))
result))
(defun string-split (mystring &optional (seperator " "))
(string-split-ex mystring seperator 0 '()))
In article <·················@hotmail.com>, Erik Halvarsson
<············@hotmail.com> wrote:
>AKW wanted me to repost this with the word AutoLISP in the subject, so
>thats what I'll do. Thanks to all who answered my last thread ;)
>
>I am coding some stuff in AutoLISP, AutoCAD R14.
>From an external file I need to get some data, and it's stored like:
>
>VKA100 707898.512 78172.497 143.803
>
>a simple xyz coordinate. When I use the (readline file) function, that
>string becomes one single element in the list I assign it to. What I
>need is four different elements in the list but I have so far no clue
>how to achive this. Would be great if anyone out there could help me.
Somewhat simpler and more efficient solution than what I've seen
posted so far, and tested
using a small AutoLisp-like Common Lisp library. As with
the other solutions, this just returns a list of strings.
You have to convert them to numbers if necessary.
(defun parse-line (string / len start items)
(setq start 1)
(while (setq start (get-item-start string start))
(setq len (get-item-length string start))
(setq items (cons (substr string start len) items))
(setq start (+ start len)))
(reverse items))
(defun get-item-start (string i &aux end)
(setq end (strlen string))
(while (and (<= i end)
(equal " " (substr string i 1)))
(setq i (+ i 1)))
(if (> i end) nil i))
(defun get-item-length (string start &aux i end)
(setq i start)
(setq end (strlen string))
(while (and (<= i end)
(not (equal " " (substr string i 1))))
(setq i (+ i 1)))
(- i start))
From: Urban Reinhard
Subject: Re: AutoLISP help required: Is there a way to split up one element into several?
Date:
Message-ID: <38EA0A15.BEB1317@sbox.tu-graz.ac.at>
For autolisp exists a FAQ and some special newsgroups.
comp.lang.lisp should not be bothered with such questions.
The faq contains the answer for your particular question at #20.2
http://xarch.tu-graz.ac.at/autocad/news/faq/autolisp.html
news://comp.cad.autocad/
news://discussion.autodesk.com/autodesk.autocad.customization
Erik Halvarsson wrote:
> AKW wanted me to repost this with the word AutoLISP in the subject, so
> thats what I'll do. Thanks to all who answered my last thread ;)
>
> I am coding some stuff in AutoLISP, AutoCAD R14.
> From an external file I need to get some data, and it's stored like:
>
> VKA100 707898.512 78172.497 143.803
>
> a simple xyz coordinate. When I use the (readline file) function, that
> string becomes one single element in the list I assign it to. What I
> need is four different elements in the list but I have so far no clue
> how to achive this. Would be great if anyone out there could help me.
(setq line (readline file))
(read (strcat "(" line ")"))