Use code from .txt file and use in .lsp

Use code from .txt file and use in .lsp

C.Utzinger
Collaborator Collaborator
1,432 Views
7 Replies
Message 1 of 8

Use code from .txt file and use in .lsp

C.Utzinger
Collaborator
Collaborator

Hi

I have the attached File, an .txt file. With another code I write to this .txt file and I want to use it later as a code in another .lsp file.

 

Is that possible?

 

Regards

0 Likes
Accepted solutions (2)
1,433 Views
7 Replies
Replies (7)
Message 2 of 8

dlanorh
Advisor
Advisor

I'm pretty certain you can do this reading each line and evaluating it (autolisp eval function).

 

One question, is the intention to greet the user on their birthday? or inform everyone else that it is their birthday? as if I read it correctly it will do the latter not the former.

I am not one of the robots you're looking for

0 Likes
Message 3 of 8

C.Utzinger
Collaborator
Collaborator

Thanks for the input.

Yes the latter.

0 Likes
Message 4 of 8

dlanorh
Advisor
Advisor
Accepted solution
Open the file -> (setq fp (open "filename" "r"))
read from file (setq x (read-line fp))
evaluate (eval (read x))

I am not one of the robots you're looking for

0 Likes
Message 5 of 8

C.Utzinger
Collaborator
Collaborator

OK

How can I evaluate a String? When you read a line of .txt, you got a string, and then?

0 Likes
Message 6 of 8

cadffm
Consultant
Consultant
Accepted solution

@dlanorh  schrieb:
Open the file -> (setq fp (open "filename" "r"))
read from file (setq x (read-line fp))
evaluate (eval (read x))

 

Sebastian

Message 7 of 8

C.Utzinger
Collaborator
Collaborator

OK

Works perfect

 

Thank you a lot

0 Likes
Message 8 of 8

C.Utzinger
Collaborator
Collaborator

Sorry, we just crossed messages 😂

0 Likes