Jump to content

Recommended Posts

Posted (edited)

hi frids,

 

if there is any other way to do this program in simply..please help me :(

(defun exc()

 

(setq f (findfile "plpl.csv"))

 

(setq g (open f "r"))

 

(setq tmpstr 0)

 

(while (/= tmpstr nil)

 

(cond

 

(

(setq tmpstr (read-line g))

(assing_val)

)

)

)

(princ))

 

 

(defun assing_val ()

 

(setq idx (strlen tmpstr))

 

 

;Pipe length

 

(if (and (= (substr tmpstr 3 5) "ND,25") (/= (substr tmpstr 8 1) "0")) (setq ND25 (substr tmpstr 9 4) ))

(if (and (= (substr tmpstr 3 5) "ND,50") (/= (substr tmpstr 8 1) "0")) (setq ND50 (substr tmpstr 9 4) ))

(if (and (= (substr tmpstr 3 5) "ND,80") (/= (substr tmpstr 8 1) "0")) (setq ND80 (substr tmpstr 9 4) ))

(if (and (= (substr tmpstr 3 6) "ND,100") (/= (substr tmpstr 9 1) "0")) (setq ND100 (substr tmpstr 10 4)))

(if (and (= (substr tmpstr 3 6) "ND,150") (/= (substr tmpstr 9 1) "0")) (setq ND150 (substr tmpstr 10 5)))

(if (and (= (substr tmpstr 3 6) "ND,200") (/= (substr tmpstr 9 1) "0")) (setq ND200 (substr tmpstr 10 5)))

(if (and (= (substr tmpstr 3 6) "ND,250") (/= (substr tmpstr 9 1) "0")) (setq ND250 (substr tmpstr 10 5)))

(if (and (= (substr tmpstr 3 6) "ND,300") (/= (substr tmpstr 9 1) "0")) (setq ND300 (substr tmpstr 10 5)))

(if (and (= (substr tmpstr 3 6) "ND,350") (/= (substr tmpstr 9 1) "0")) (setq ND350 (substr tmpstr 10 5)))

(if (and (= (substr tmpstr 3 6) "ND,400") (/= (substr tmpstr 9 1) "0")) (setq ND400 (substr tmpstr 10 5)))

(if (and (= (substr tmpstr 3 6) "ND,450") (/= (substr tmpstr 9 1) "0")) (setq ND450 (substr tmpstr 10 5)))

(if (and (= (substr tmpstr 3 6) "ND,500") (/= (substr tmpstr 9 1) "0")) (setq ND500 (substr tmpstr 10 5)))

(if (and (= (substr tmpstr 3 6) "ND,550") (/= (substr tmpstr 9 1) "0")) (setq ND550 (substr tmpstr 10 5)))

(if (and (= (substr tmpstr 3 6) "ND,600") (/= (substr tmpstr 9 1) "0")) (setq ND600 (substr tmpstr 10 5)))

(if (and (= (substr tmpstr 3 6) "ND,650") (/= (substr tmpstr 9 1) "0")) (setq ND650 (substr tmpstr 10 5)))

(if (and (= (substr tmpstr 3 6) "ND,700") (/= (substr tmpstr 9 1) "0")) (setq ND700 (substr tmpstr 10 5)))

(if (and (= (substr tmpstr 3 6) "ND,750") (/= (substr tmpstr 9 1) "0")) (setq ND750 (substr tmpstr 10 5)))

(if (and (= (substr tmpstr 3 6) "ND,800") (/= (substr tmpstr 9 1) "0")) (setq ND800 (substr tmpstr 10 5)))

(if (and (= (substr tmpstr 3 6) "ND,850") (/= (substr tmpstr 9 1) "0")) (setq ND850 (substr tmpstr 10 5)))

(if (and (= (substr tmpstr 3 6) "ND,900") (/= (substr tmpstr 9 1) "0")) (setq ND900 (substr tmpstr 10 5)))

(if (and (= (substr tmpstr 3 6) "ND,950") (/= (substr tmpstr 9 1) "0")) (setq ND950 (substr tmpstr 10 5)))

 

(if (and (= (substr tmpstr 3 7) "ND,1000") (/= (substr tmpstr 10 1) "0")) (setq ND950 (substr tmpstr 11 5)))

(if (and (= (substr tmpstr 3 7) "ND,1050") (/= (substr tmpstr 10 1) "0")) (setq ND1050 (substr tmpstr 11 5)))

(if (and (= (substr tmpstr 3 7) "ND,1100") (/= (substr tmpstr 10 1) "0")) (setq ND1100 (substr tmpstr 11 5)))

(if (and (= (substr tmpstr 3 7) "ND,1150") (/= (substr tmpstr 10 1) "0")) (setq ND1150 (substr tmpstr 11 5)))

(if (and (= (substr tmpstr 3 7) "ND,1200") (/= (substr tmpstr 10 1) "0")) (setq ND1200 (substr tmpstr 11 5)))

(if (and (= (substr tmpstr 3 7) "ND,1250") (/= (substr tmpstr 10 1) "0")) (setq ND1250 (substr tmpstr 11 5)))

(if (and (= (substr tmpstr 3 7) "ND,1300") (/= (substr tmpstr 10 1) "0")) (setq ND1300 (substr tmpstr 11 5)))

(if (and (= (substr tmpstr 3 7) "ND,1350") (/= (substr tmpstr 10 1) "0")) (setq ND1350 (substr tmpstr 11 5)))

(if (and (= (substr tmpstr 3 7) "ND,1400") (/= (substr tmpstr 10 1) "0")) (setq ND1400 (substr tmpstr 11 5)))

(if (and (= (substr tmpstr 3 7) "ND,1450") (/= (substr tmpstr 10 1) "0")) (setq ND1450 (substr tmpstr 11 5)))

(if (and (= (substr tmpstr 3 7) "ND,1500") (/= (substr tmpstr 10 1) "0")) (setq ND1500 (substr tmpstr 11 5)))

(if (and (= (substr tmpstr 3 7) "ND,1550") (/= (substr tmpstr 10 1) "0")) (setq ND1550 (substr tmpstr 11 5)))

(if (and (= (substr tmpstr 3 7) "ND,1600") (/= (substr tmpstr 10 1) "0")) (setq ND1600 (substr tmpstr 11 5)))

(if (and (= (substr tmpstr 3 7) "ND,1650") (/= (substr tmpstr 10 1) "0")) (setq ND1650 (substr tmpstr 11 5)))

(if (and (= (substr tmpstr 3 7) "ND,1700") (/= (substr tmpstr 10 1) "0")) (setq ND1700 (substr tmpstr 11 5)))

(if (and (= (substr tmpstr 3 7) "ND,1750") (/= (substr tmpstr 10 1) "0")) (setq ND1750 (substr tmpstr 11 5)))

(if (and (= (substr tmpstr 3 7) "ND,1800") (/= (substr tmpstr 10 1) "0")) (setq ND1800 (substr tmpstr 11 5)))

(if (and (= (substr tmpstr 3 7) "ND,1850") (/= (substr tmpstr 10 1) "0")) (setq ND1850 (substr tmpstr 11 5)))

(if (and (= (substr tmpstr 3 7) "ND,1900") (/= (substr tmpstr 10 1) "0")) (setq ND1900 (substr tmpstr 11 5)))

(if (and (= (substr tmpstr 3 7) "ND,1950") (/= (substr tmpstr 10 1) "0")) (setq ND1950 (substr tmpstr 11 5)))

(if (and (= (substr tmpstr 3 7) "ND,2000") (/= (substr tmpstr 10 1) "0")) (setq ND2000 (substr tmpstr 11 5)))

 

 

;Elbow length

 

(princ))

plpl.csv

Edited by anandhan
  • Replies 20
  • Created
  • Last Reply

Top Posters In This Topic

  • anandhan

    9

  • pBe

    7

  • SLW210

    2

  • hanhphuc

    2

Popular Days

Top Posters In This Topic

Posted Images

Posted

Convert the string content to a list from read-line

 

Remove all the ","

Convert the string to a list

Use another list for comparison check

 

Avoid using multiple "if's", instead use cond or while function to terminate evaluation when condition is met

Posted
(defun c:exc()

(setq f (findfile "plpl.csv"))

(setq g (open f "r"))

(setq tmpstr 0)

(while (/= tmpstr nil)

(cond

(
(setq tmpstr (read-line g))
(assing_val)
)
)
)
(princ))


(defun assing_val ()

(setq idx (strlen tmpstr))


;Pipe length 

(if (and (= (substr tmpstr 3 5) "ND,25") (/= (substr tmpstr 8 1) "0")) (setq ND25 (substr tmpstr 9 4) ))
(if (and (= (substr tmpstr 3 5) "ND,50") (/= (substr tmpstr 8 1) "0")) (setq ND50 (substr tmpstr 9 4) ))
(if (and (= (substr tmpstr 3 5) "ND,80") (/= (substr tmpstr 8 1) "0")) (setq ND80 (substr tmpstr 9 4) ))
(if (and (= (substr tmpstr 3 6) "ND,100") (/= (substr tmpstr 9 1) "0")) (setq ND100 (substr tmpstr 10 4)))
(if (and (= (substr tmpstr 3 6) "ND,150") (/= (substr tmpstr 9 1) "0")) (setq ND150 (substr tmpstr 10 5)))
(if (and (= (substr tmpstr 3 6) "ND,200") (/= (substr tmpstr 9 1) "0")) (setq ND200 (substr tmpstr 10 5)))
(if (and (= (substr tmpstr 3 6) "ND,250") (/= (substr tmpstr 9 1) "0")) (setq ND250 (substr tmpstr 10 5)))
(if (and (= (substr tmpstr 3 6) "ND,300") (/= (substr tmpstr 9 1) "0")) (setq ND300 (substr tmpstr 10 5)))
(if (and (= (substr tmpstr 3 6) "ND,350") (/= (substr tmpstr 9 1) "0")) (setq ND350 (substr tmpstr 10 5)))
(if (and (= (substr tmpstr 3 6) "ND,400") (/= (substr tmpstr 9 1) "0")) (setq ND400 (substr tmpstr 10 5)))
(if (and (= (substr tmpstr 3 6) "ND,450") (/= (substr tmpstr 9 1) "0")) (setq ND450 (substr tmpstr 10 5)))
(if (and (= (substr tmpstr 3 6) "ND,500") (/= (substr tmpstr 9 1) "0")) (setq ND500 (substr tmpstr 10 5)))
(if (and (= (substr tmpstr 3 6) "ND,550") (/= (substr tmpstr 9 1) "0")) (setq ND550 (substr tmpstr 10 5)))
(if (and (= (substr tmpstr 3 6) "ND,600") (/= (substr tmpstr 9 1) "0")) (setq ND600 (substr tmpstr 10 5)))
(if (and (= (substr tmpstr 3 6) "ND,650") (/= (substr tmpstr 9 1) "0")) (setq ND650 (substr tmpstr 10 5)))
(if (and (= (substr tmpstr 3 6) "ND,700") (/= (substr tmpstr 9 1) "0")) (setq ND700 (substr tmpstr 10 5)))
(if (and (= (substr tmpstr 3 6) "ND,750") (/= (substr tmpstr 9 1) "0")) (setq ND750 (substr tmpstr 10 5)))
(if (and (= (substr tmpstr 3 6) "ND,800") (/= (substr tmpstr 9 1) "0")) (setq ND800 (substr tmpstr 10 5)))
(if (and (= (substr tmpstr 3 6) "ND,850") (/= (substr tmpstr 9 1) "0")) (setq ND850 (substr tmpstr 10 5)))
(if (and (= (substr tmpstr 3 6) "ND,900") (/= (substr tmpstr 9 1) "0")) (setq ND900 (substr tmpstr 10 5)))
(if (and (= (substr tmpstr 3 6) "ND,950") (/= (substr tmpstr 9 1) "0")) (setq ND950 (substr tmpstr 10 5)))

(if (and (= (substr tmpstr 3 7) "ND,1000") (/= (substr tmpstr 10 1) "0")) (setq ND950 (substr tmpstr 11 5)))
(if (and (= (substr tmpstr 3 7) "ND,1050") (/= (substr tmpstr 10 1) "0")) (setq ND1050 (substr tmpstr 11 5)))
(if (and (= (substr tmpstr 3 7) "ND,1100") (/= (substr tmpstr 10 1) "0")) (setq ND1100 (substr tmpstr 11 5)))
(if (and (= (substr tmpstr 3 7) "ND,1150") (/= (substr tmpstr 10 1) "0")) (setq ND1150 (substr tmpstr 11 5)))
(if (and (= (substr tmpstr 3 7) "ND,1200") (/= (substr tmpstr 10 1) "0")) (setq ND1200 (substr tmpstr 11 5)))
(if (and (= (substr tmpstr 3 7) "ND,1250") (/= (substr tmpstr 10 1) "0")) (setq ND1250 (substr tmpstr 11 5)))
(if (and (= (substr tmpstr 3 7) "ND,1300") (/= (substr tmpstr 10 1) "0")) (setq ND1300 (substr tmpstr 11 5)))
(if (and (= (substr tmpstr 3 7) "ND,1350") (/= (substr tmpstr 10 1) "0")) (setq ND1350 (substr tmpstr 11 5)))
(if (and (= (substr tmpstr 3 7) "ND,1400") (/= (substr tmpstr 10 1) "0")) (setq ND1400 (substr tmpstr 11 5)))
(if (and (= (substr tmpstr 3 7) "ND,1450") (/= (substr tmpstr 10 1) "0")) (setq ND1450 (substr tmpstr 11 5)))
(if (and (= (substr tmpstr 3 7) "ND,1500") (/= (substr tmpstr 10 1) "0")) (setq ND1500 (substr tmpstr 11 5)))
(if (and (= (substr tmpstr 3 7) "ND,1550") (/= (substr tmpstr 10 1) "0")) (setq ND1550 (substr tmpstr 11 5)))
(if (and (= (substr tmpstr 3 7) "ND,1600") (/= (substr tmpstr 10 1) "0")) (setq ND1600 (substr tmpstr 11 5)))
(if (and (= (substr tmpstr 3 7) "ND,1650") (/= (substr tmpstr 10 1) "0")) (setq ND1650 (substr tmpstr 11 5)))
(if (and (= (substr tmpstr 3 7) "ND,1700") (/= (substr tmpstr 10 1) "0")) (setq ND1700 (substr tmpstr 11 5)))
(if (and (= (substr tmpstr 3 7) "ND,1750") (/= (substr tmpstr 10 1) "0")) (setq ND1750 (substr tmpstr 11 5)))
(if (and (= (substr tmpstr 3 7) "ND,1800") (/= (substr tmpstr 10 1) "0")) (setq ND1800 (substr tmpstr 11 5)))
(if (and (= (substr tmpstr 3 7) "ND,1850") (/= (substr tmpstr 10 1) "0")) (setq ND1850 (substr tmpstr 11 5)))
(if (and (= (substr tmpstr 3 7) "ND,1900") (/= (substr tmpstr 10 1) "0")) (setq ND1900 (substr tmpstr 11 5)))
(if (and (= (substr tmpstr 3 7) "ND,1950") (/= (substr tmpstr 10 1) "0")) (setq ND1950 (substr tmpstr 11 5)))
(if (and (= (substr tmpstr 3 7) "ND,2000") (/= (substr tmpstr 10 1) "0")) (setq ND2000 (substr tmpstr 11 5)))


;Elbow length 

(princ))

Posted

thank you. i post Code Tags for my program.

please help me any other way?

Posted

"," its attomatical comming while i read in CVS files, thas why i i called in my program.

 

can you post any sampl convertion the string to a list. pls

Posted
"," its attomatical comming while i read in CVS files, thas why i i called in my program.

 

can you post any sampl convertion the string to a list. pls

(setq l (read-line g))
(setq item (read (strcat "(" (vl-string-translate "," " " l) ")")))

Posted

 

Convert the string content to a list from read-line

 

Remove all the ","

Convert the string to a list

Use another list for comparison check

 

(setq l (read-line g))
(setq item (read (strcat "(" (vl-string-translate "," " " l) ")")))

 

Like that :)

Posted

thank you for your quick reply. let me try this....

Posted

What is the constant value here? the source or the target? looking at your if statement, it appears that if the value is on excel file then "assign" a variable for every value if the condition is met for the targetsource or sourcetarget. There's something odd about the way you approach this, i think you're going about it the wrong way.

 

What is the purpose of this routine anandhan?

Posted

we hv typical piping Isometric routing, but each routing pipe length will be defer depent on the pipe dia . i try to get value for attomaticaly using lisp.

 

and i get Excel value for that, try to use directly for that value from excel sheet.

Posted

i'm guessing that this thread from Excel input to Lisp is related to this query.

 

It sounds easy really, just need to understand is all. are you telling us prior to running your "piping Isometric routine", you need the values from the CSV file? and the CSV file is constantly changing? or is it the other way around? the CSV file is static?

 

I need an aspirin :?

Posted

yes its this thread from Excel input to Lisp is related to this query.

Posted

my understanding:

 

if string is

"P,ND,1500,11800"

you assign this (setq ND1500 "11800") ?? ;also 25

 

:?

Posted

yes your are correct .... my least ND = 25 only ...

 

ND25 = "3000" or "6000" its vary some time, thats why i need to get from excel sheet.

 

i hv this variation up to ND 4000 each pipe.....

Posted
my understanding:

 

if string is

"P,ND,1500,11800"

you assign this (setq ND1500 "11800") ?? ;also 25

 

:?

 

That much is clear hanhphuc, the odd part is the "assing_val" routine. what are the conditions? what values to look for? what are the source of those values?

 

(if (and (= (substr tmpstr 3 6) [b][i]"ND,500"[/i][/b]) (/= (substr tmpstr 9 1) "0")) (setq ND500 (substr tmpstr 10 5)))

 

Are they drawing dependent? or list dependent? so if i ran "assing_val" at every drawing for the same CSV file and the same items the result is the same.

 

What are the basis for that multiple conditions? The "assing_val" will have different conditions [if's] every time for every drawing session?

 

Different lisp codes? or different CSV file?

 

Now i need two aspirin

Posted

Pretty sure someone will help you , just be patient. As for me.....

 

fold.jpg

 

pBe right there.

Posted
That much is clear hanhphuc, the odd part is the "assing_val" routine. what are the conditions? what values to look for? what are the source of those values?

 

(if (and (= (substr tmpstr 3 6) [b][i]"ND,500"[/i][/b]) (/= (substr tmpstr 9 1) "0")) (setq ND500 (substr tmpstr 10 5)))

 

Are they drawing dependent? or list dependent? so if i ran "assing_val" at every drawing for the same CSV file and the same items the result is the same.

 

What are the basis for that multiple conditions? The "assing_val" will have different conditions [if's] every time for every drawing session?

 

Different lisp codes? or different CSV file?

 

perhaps OP just wanna assign variables? ie: ND1500 ,value returns "11800"

regardless any condition.

 

(defun [color="blue"]assign_val[/color] (str / i $ l )
 (while (setq i (vl-string-search "," str))
   (setq l   (cons (substr str 1 i) l)
  str (substr str (+ 2 i) (- (strlen str) i))
  ) ;_ end of setq
   ) ;_ end of while
 (setq l (reverse (vl-remove "" (cons str l))))
 (setq $ (nth 2 l) i (read $ ))
 (if (and (numberp i) (zerop (rem i 50)) (<= 25 i 2000))
   (set (read (strcat (nth 1 l) $)) (nth 3 l))
   ) ;_ end of if
 ) ;_ end of defun

 

example : "P,ND,1500,11800"

_$ (assign_val "P,ND,1500,11800")

"11800"

_$ ND1500

"11800"

_$

;something like that?

 

however i prefer assoc list than assign to global variables

 

 

Now i need two aspirin

:rofl:

Posted

About the code you posted, a problem i see is by using nth function the routine will be limited to a specific condition

 

(assign_val [color="blue"]"fl,nd,mo,25,150,ansi?150,,,"[/color])

 

That is why knowing and understanding the source is important.

 

And for this particular string syntax, from the (read-line ...) value

 

UET,ND,MI,1500,2620,1460,,,

,,,,,,,,

45Y,ND,MI,150,250,400,400,,

45Y,ND,MI,200,330,540,540,,

,,,,,,,,

,,,,,,,,

NWP,ND,-,300,50,440,,,

 

 

(defun _string2List (str)
 (if
   (setq
     lst (read (strcat "(" (vl-string-translate "," " " str) ")"))
   )
    (mapcar '(lambda (x)
	(if (numberp x)
	  (itoa x);<-- remove itoa if you want numbers
	  (vl-symbol-name x)
	)
      )
     lst
    )
 )
)

 

So, still the same questions, an "image" as an example just dont cut it for me.

 

Anyhoo, i already folded. :D, I'll be just observing from this point on.

 

pBe

 

EDIT: and YES association list is loads better than multiple variables

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...