CadFrank Posted October 29, 2012 Posted October 29, 2012 Hi, I'm making a I beam routine. now I would like to use a file with all the specification and make them use it in the routine. Such as this file. Specification.txt (setq name (getstring T "\nGive name of I Beam : ")) (setq H L EA ES k k1 ) So I want to set those variable with the one in the .txt file according to the name given. Anyone have a suggestion ! Quote
MSasu Posted October 29, 2012 Posted October 29, 2012 This looks more like a job for ASSOC: (setq listProfiles '(("W530 x 85" 535 166 10.3 16.5 35 22) ("W530 x 74" 529 166 9.7 13.6 32 21))) (setq listBeam (cdr (assoc name listProfile)) (if listBeam (setq H (nth 0 listBeam) L (nth 1 listBeam) ... Quote
CadFrank Posted October 29, 2012 Author Posted October 29, 2012 Well can I put it in another file.. since the I beam list is pretty long Quote
Tharwat Posted October 29, 2012 Posted October 29, 2012 This is enough .. (mapcar 'set '(H L EA ES k k1) (list "W530 x 85" 535 166 10.3 16.5 35 22)) Quote
CadFrank Posted October 29, 2012 Author Posted October 29, 2012 Well i'm pretty sure they work and all... But i'd like to make it a seperate file since I have like 288 different I beam like it i would use : (setq list (open file "r") ... etc I know i'm asking alot But I want to learn fast more and more Quote
Tharwat Posted October 29, 2012 Posted October 29, 2012 That's correct . and use the function read-line to read the line of values with while function to run to the end . Quote
CadFrank Posted October 29, 2012 Author Posted October 29, 2012 Now I get to this and it's not keeping the variable in memori.. (setq f (open "C:\\Users\\francois.levesque\\Documents\\specification.txt" "r")) (setq name "W530 x 74") (setq listt (while (setq blist (read-line f)) (if (wcmatch blist (strcat "*"name"*")) (princ blist) ) ) ) Now, what am I missing. Quote
CadFrank Posted October 29, 2012 Author Posted October 29, 2012 Well keep the line in memorie so i can use them and put each variable in a setq Quote
Tharwat Posted October 29, 2012 Posted October 29, 2012 You should step through each line of string and divide it by spaces or characters or what ever you have in your criteria . functions may help in this regard . vl-position vl-string-search vl-string-position Quote
CadFrank Posted October 29, 2012 Author Posted October 29, 2012 Ok Thanks ill see what I can make of this. now my day of work is over Quote
Tharwat Posted October 29, 2012 Posted October 29, 2012 Ok Thanks ill see what I can make of this. now my day of work is over And for me it is time to go to bed Good luck buddy . Quote
David Bethel Posted October 29, 2012 Posted October 29, 2012 This old but VERY useful: http://www.cadtutor.net/forum/archive/index.php/t-1220.html In addtion to beams, Walter also did angles, channels and stdshps Quote
CadFrank Posted October 30, 2012 Author Posted October 30, 2012 Ok Well I figured out how to get the variable to stick now it doesnt reconize it as a list.. only a string (setq f (open "C:\\Users\\francois.levesque\\Documents\\specification.txt" "r")) (setq name "W530 x 74") (while (setq blist (read-line f)) (if (wcmatch blist (strcat "*"name"*")) (progn (setq a (substr blist 11)) ) ) ) _$ A "529 166 9.7 13.6 32 21" So i need to put this into a list so i can use nth. So how can i put it into a list? Unless some1 has a better idea Quote
Tharwat Posted October 30, 2012 Posted October 30, 2012 _$ A "529 166 9.7 13.6 32 21" So i need to put this into a list so i can use nth. So how can i put it into a list? Unless some1 has a better idea That means you did not read about the last three functions that I have posted for you to read nth function does not help you in this regard Quote
CadFrank Posted October 30, 2012 Author Posted October 30, 2012 Well I did read them.. I'll give it more though Quote
Lee Mac Posted October 30, 2012 Posted October 30, 2012 "529 166 9.7 13.6 32 21" So i need to put this into a list so i can use nth. So how can i put it into a list? (setq str "529 166 9.7 13.6 32 21") (read (strcat "(" str ")")) Alternatively, consider my String to List function for general purpose string parsing. Quote
CadFrank Posted October 30, 2012 Author Posted October 30, 2012 That means you did not read about the last three functions that I have posted for you to read not sure how to use them everything is try give me errors (vl-string-search(vl-position 1 a)) ; error: bad argument type: listp "529 166 9.7 13.6 32 21" (setq b (vl-string-search 1 a)) ; error: bad argument type: (or stringp symbolp): 1 (setq b (vl-string-position a 2)) ; error: bad argument type: fixnump: "529 166 9.7 13.6 32 21" Quote
Lee Mac Posted October 30, 2012 Posted October 30, 2012 not sure how to use them everything is try give me errors Don't guess, read the documentation. I provided the documentation for these functions in my response your previous thread: http://www.cadtutor.net/forum/showthread.php?74012-Getting-a-specific-string-from-a-file-path&p=503361&viewfull=1#post503361 Looks like I wasted my time retrieving all the links to the information. Quote
CadFrank Posted October 30, 2012 Author Posted October 30, 2012 (edited) Don't guess, read the documentation. I'm sorry Lee to dissapoint you. I did read the documentation on those. Thing is i'm not yet able to understand autolisp way to work. I'm still a beginner at this so even if I read no sure to understand the documentation. Edited October 30, 2012 by CadFrank Quote
Recommended Posts
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.