Jump to content

Recommended Posts

Posted

Hi,

 

i want to split Words(coma included) from list and create variable for each splitted words

 

Example: "1,221866.070,1937463.651,611.892,A1"
want to split like this 
"1"
"221866.070"
"1937463.651"
"611.892"
"A1" 

 

waiting for your replies ....

:(:(:(:(:(:(

 

Ganesh Shetty

Posted (edited)

Godofcad. splitting the "words" is simple. Are the number of "words" always 5 such as this case? if not. thats where the problem will start, What will be the variable name? diffrent everytime?

 

sample

(defun _delFinder  (str md / d l str)
     (while (setq d (vl-string-position md str nil T))
           (setq l (cons (substr str (+ 2 d)) l)
                 str (substr str 1 d)))
     (cons str l)
     )

 

(setq str "1,221866.070,1937463.651,611.892,A1")
(setq tovar (_delfinder str 44) cnt 0)
(foreach words tovar
     (set (read (strcat "[b][color=blue]Var[/color][/b]" (itoa (setq cnt (1+ cnt))))) words))

 

var1 -> "1"

var2 -> "221866.070"

var3 -> "1937463.651"

var4 -> "611.892"

var5 -> "A1"

 

You can however make do without the variable names and do your thing straight off the list.

Edited by pBe
Posted

We can take this one step further by assigning the true value of the the collected/splitted "words"

 

(foreach words tovar
     (set (read (strcat "Var" (itoa (setq cnt (1+ cnt)))))
          [b][color=blue](if (numberp (setq num (read words))) num words))[/color][/b])

 

 

var1 -> 1

(type var1) INT

var2 -> 221866.070

(type var2) REAL

var3 -> 1937463.651

(type var3) REAL

var4 -> 611.892

(type var4) REAL

var5 -> "A1"

(type var5) STR

 

HTH

Posted

Hi .

 

A little bit late to the party , but better than nothing :)

 

(defun _StepThrough (lst / integer position values variables)
 ;;;                 Tharwat 19. May. 2012               ;;;
 ;;; divide a list that contains commas within ;;;
 (setq lst     (strcat lst ",")
       integer 0
 )
 (while (setq position (vl-string-search "," lst 0))
   (if (setq values
              (cons
                (set
                  (read (strcat "a" (itoa (setq integer (1+ integer))))
                  )
                  (substr lst 1 position)
                )
                values
              )
       )
     (setq variables (cons (strcat "a" (itoa integer)) variables))
   )
   (setq lst (substr lst (+ position 2) (strlen lst)))
 )
 (print (reverse variables))
 (print (reverse values))
 (princ)
)

Example of usage ...

 

(_StepThrough "1,221866.070,1937463.651,611.892,A1")

Posted

A little bit better .... :D

 

(defun _StepThrough (lst / chars integer position values variables)
;;;                 Tharwat 19. May. 2012               ;;;
;;; divide a list of strings that contain commas within ;;;
 (if (eq (type lst) 'STR)
   (setq chars (vl-string->list lst)))
 (if (eq (car chars) 44)
   (setq lst (substr lst 2 (strlen lst))))
 (if (eq (last chars) 44)
   (setq lst (substr lst 1 (1- (strlen lst)))))
 (setq lst (strcat lst ",") integer 0)
 (while (setq position (vl-string-search "," lst 0))
   (if (setq values (cons (set (read (strcat "a" (itoa (setq integer (1+ integer)))))
                  (substr lst 1 position)
                )
                values
              )
       )
     (setq variables (cons (strcat "a" (itoa integer)) variables))
   )
   (setq lst (substr lst (+ position 2) (strlen lst)))
 )
 (print (reverse variables))
 (print (reverse values))
 (princ)
)

Posted

I just noticed the OP's screen name: God of CAD. One would think the God of CAD would know all the answers.:rofl:

Posted (edited)
I just noticed the OP's screen name: God of CAD. One would think the God of CAD would know all the answers.:rofl:

 

Well it could also be an anagram for cadd goof ,take no offence godofcad, we're just "goofing" around ;)

 

Anyhoo. it appears that the "words" are label\coordinates\description for a survey point. Then like i sugested before, go ahead and write (my guess is attributes) the values directly off the list and that will eliminate the need to assign each value to a variable

 

(foreach words (_delfinder str 44)
........  ;<-- your code here
)

HTH

Edited by pBe
Posted
Well it could also be an anagram for cadd goof ,take no offence godofcad, we're just "goofing" around ;)

 

Anyhoo. it appears that the "words" are label\coordinates\description for a survey point. Then like i sugested before, go ahead and write (my guess is attributes) the values directly off the list and that will eliminate the need to assign each value to a variable

 

(foreach words (_delfinder str 44)
........  ;<-- your code here
)

HTH

 

Yeah ! exactly Right they are Survey Points ...i just want to import all survey points to cad .... anyhw tanx for codes .....:)

 

Tank u pBe and Tharwat ...you guys are awesome...........

Posted

Glad it helps. :)

 

Holler if you need help inserting the block abd assigning the values.

Posted
I just noticed the OP's screen name: God of CAD. One would think the God of CAD would know all the answers.:rofl:

 

And 'LISP' as an avatar!!! :oops:

Posted
Yeah ! exactly Right they are Survey Points ...i just want to import all survey points to cad .... anyhw tanx for codes .....:)

 

Tank u pBe and Tharwat ...you guys are awesome...........

 

You're welcome .

 

If you are going to import points to cad , I should confess that pBe's code is faster and shorter without a doubt , while my code gives the same result but slower due to few extra checks before giving the needed result . :)

 

Best of luck.

 

Tharwat

Posted
You're welcome .

 

If you are going to import points to cad , I should confess that pBe's code is faster and shorter without a doubt , while my code gives the same result but slower due to few extra checks before giving the needed result . :)

 

Best of luck.

 

Tharwat

 

Here is my codes (csv to cad)

Here i used Pbe's Codes to split word

 

---------------------------------------------------------------------
(defun Splitter  (str md / d l str)
     (while (setq d (vl-string-position md str nil T))
           (setq l (cons (substr str (+ 2 d)) l)
                 str (substr str 1 d)))
     (cons str l)
)
---------------------------------------------------------------------

(defun c:csv_import (/ snp lay file opn rd point est lvl north base_pt
	     sno_pt rmrk_pt sno code )
 (setq snp(getvar "osmode"))
 (setq lay(getvar "clayer"))
 (setvar "cmdecho" 0)
 (setvar "osmode" 0)
 (command "_.UNDO" "G")
 -------------------------------------------------------------------
 (command "_.LAYER" "M" "Serial_No" "c" "1" "" "")
 (command "_.LAYER" "M" "Level" "c" "2" "" "")
 (command "_.LAYER" "M" "Remark" "c" "3" "" "")
 (command "_.LAYER" "M" "Point" "c" "4" "" "")
 -------------------------------------------------------------------
 (setq file(getfiled "Select File To Import" "" "csv" 4))
 (setq opn(open file "r"))
 (while
   (setq rd(read-line opn))
   (setq str rd)
   (setq Point (Splitter str 44))
   -----------------------------------------------------------------
   (setq Est(atof(nth 1 point))) (setq north(atof (nth 2 point)))
   (setq Lvl(atof (nth 3 point))) (setq base_pt (list est north lvl))
   -----------------------------------------------------------------
   (setq sno_pt(list est (+ north 0.7) lvl))
   (setq rmrk_pt(list est (- north 0.7) lvl))
   (setq sno(nth 0 point))
   (setq Code(nth 4 point))

   (command "TEXT" "J" "MC" sno_pt "0.5" "0" sno)
   (Command "Change" (entlast) "" "p" "la" "Serial_No" "c" "bylayer" "")
   (command "TEXT" "J" "MC" rmrk_pt "0.5" "0" code)
   (Command "Change" (entlast) "" "p" "la" "Remark" "c" "bylayer" "")
   (command "TEXT" "J" "MC" Base_pt "0.5" "0" (rtos lvl))
   (Command "Change" (entlast) "" "p" "la" "Level" "c" "bylayer" "")
   (command "point" base_pt)
   (Command "Change" (entlast) "" "p" "la" "Point" "c" "bylayer" "")
   

 );while
 (command "pdmode" 35)
 (command "pdsize" 0.5)
 (setvar "cmdecho" 1)
 (setvar "osmode" snp)
 (setvar "clayer" lay)
 (command "_.UNDO" "E")
 (command "Zoom" "e")
 (princ)
 );end defun

 

and i am really sorry for i mentioned my cp name as godofcad

and my avtar is lisp ...sorry to other guys

 

i am closing my account today

 

:(:(

Posted

You can improve your codes by replacing the command calls with function entmake(x) for layers , texts and points . ;)

Posted

and i am really sorry for i mentioned my cp name as godofcad

and my avtar is lisp ...sorry to other guys

 

i am closing my account today

 

:(:(

 

Why would you do that? I said it before. take no offence, Members are just being silly thats all :)

 

All work and no play makes godofcad a dull boy.... ;)

Posted
Why would you do that? I said it before. take no offence, Members are just being silly thats all :)

 

All work and no play makes godofcad a dull boy.... ;)

 

Tank u pBe ...hmm.....Tats ok ....

 

I will Not Feel Bad and Not Closing My Account

 

Tanks for your support

 

 

:):):):):):):):)

Posted
Tank u pBe..

 

Tanks for your support

 

All the time. keep on coding :)

Posted

Wow first time ever i'm trying help (maybe because i thing i have something to help with, but i admit asking is much more fun.

 

(defun LM:str->lst ( str del / pos )
   (if (setq pos (vl-string-search " " str))
       (cons (substr str 1 pos) (LM:str->lst (substr str (+ pos 1 (strlen del))) del))
       (list str)
   )

 

I had a similar problem, and i think this thing helped me.it could be modified for criteria of dividing string, i don't remeber details.

I'm sorry that i dont remember where i aqcuired this to.

Posted

First of all

(setq pos (vl-string-search [b][color=blue]del [/color][/b]str))

 

and here's a hint

[b][color=blue]LM[/color][/b]:str->lst

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...