Jump to content

Recommended Posts

Posted

I want to change this:

 

((member CNAME '(
			"W7072"
			))
(alert "WELL DONE!"))

 

So that instead of listing "W7072" "W1234" etc etc I can have it "scan" through a text file and say yes CNAME is part of the text file or CNAME is not.

 

Any pointers?

Posted

I think what I am after is;

All lines in the text file to be stored as a list within the routine. on which I can run "member". Not sure how to achieve the storing lines as a variable?

Posted

use SET function

 

 
(setq val 0.0)
(foreach var '("v1" "v2" "V3")
   (set (read var) (setq val (1+ val ))))

Posted

Not sure that help pBe sorry. Or I dont understand!

 

Lets say I have this.txt within this file is:

W111

W123

W112

 

etc etc.

 

I want to do:

(setq THISLIST (strcat ((open "this.txt")
                                 foreach read-line)))

 

Dont laugh at the code above :( but basically want THISLIST to return

"W111" "W123" "W112"

Posted
(setq open_file (open "this.txt" "r"))
(while (setq line (read-line open_file))
  (setq THISLIST (cons line THISLIST))
)

Posted

Consider a function such as:

 

(defun MemberOfTextFile ( item file / line )
   (if
       (and
           (setq file (findfile file))
           (setq file (open file "r"))
       )
       (progn
           (while (and (setq line (read-line file)) (not (eq line item))))
           (close file)
           (eq line item)
       )
   )
)

Will return T if 'item' is equal to a line in the supplied Text File:

 

(MemberOfTextFile "W111" "C:\\YourFolder\\Yourfile.txt")

 

Otherwise, will return nil if either the file is not found or cannot be opened, or the item is not present. Note that the above is case-sensitive.

Posted

Thanks everyone.

 

Lee:

 

How far wrong am I? Sorry im snowed under and trying to do ten things at once!

 

(cond 
((MemberOfTextFile "CNAME" "this.txt") (alert "WELL DONE!"))
(t (princ "\nYou suck"))
)

Posted
Lee:

 

How far wrong am I? Sorry im snowed under and trying to do ten things at once!

 

(cond 
((MemberOfTextFile "CNAME" "this.txt") (alert "WELL DONE!"))
(t (princ "\nYou suck"))
)

 

Is 'CNAME' a variable or a string? Is "this.txt" in the Support Path or Working Directory?

 

From your previous posts, I would guess you need to use:

 

(if (MemberOfTextFile CNAME "this.txt")
   (alert "WELL DONE!")
   (princ "\nYou Suck")
)

Posted (edited)

(setq CNAME (strcase (GETENV "COMPUTERNAME")))

 

Thats CNAME :)

 

Thanks

Edited by SLW210
Code Tags Added
Posted

Works like a charm... I did look at IF statement... Obviously I glazed over!

Posted
Works like a charm... I did look at IF statement... Obviously I glazed over!

 

Note that COND would work equally well, but I felt IF was better suited for this case.

 

(cond
   (   (MemberOfTextFile CNAME "this.txt")
       (alert "WELL DONE!")
   )
   (   t
       (princ "\nYou Suck")
   )
)

Posted
Not sure that help pBe sorry. Or I dont understand!

 

Apologies Monk, I was refering to this one.

 

Not sure how to achieve the storing lines as a variable?

Posted

Awesome thanks for your help peeps!

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