Steven P Posted July 8, 2021 Share Posted July 8, 2021 Good afternoon, Is it possible to create incremental strings (If that's what they are called) For example string [n] : String1 String2 String3 But number them in the fly where number can increase for example as you repeatedly go through a loop. I know I should probably append a list but the routine I am looking at changing would need a bit of rework to do that and a quick -maybe dirty- way around that is this idea. (of course, I am expecting the answer to be 'no, you fool, you can't do that' but you never know) Thanks Quote Link to comment Share on other sites More sharing options...
mhupp Posted July 8, 2021 Share Posted July 8, 2021 (edited) (defun C:foo () (setq i (getint "\nStarting number: ")) (setq string (getstring "\nString: ")) ;set i and string outside of loop (while (> 20 i) ;what ever your looping for (setq name (strcat string "-" (itoa i))) (setq i (1+ i)) (prompt (strcat "\n" name)) ) (princ) ) Running this command. Starting number: 15 String: test test-15 test-16 test-17 test-18 test-19 --edit also look at this http://www.lee-mac.com/numinc.html Edited July 8, 2021 by mhupp link 1 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted July 8, 2021 Share Posted July 8, 2021 Do you mean variables with a value ? You can do that as well, string1=a string2=b etc. Look at SET 1 Quote Link to comment Share on other sites More sharing options...
Steven P Posted July 9, 2021 Author Share Posted July 9, 2021 Thanks mhupp,, I don't think I explained well enough. More along the lines of changing (setq string (getstring "\nString: ")) (setq name1 string) (setq string (getstring "\nString: ")) (setq name2 string) (setq string (getstring "\nString: ")) (setq name3 string) (setq string (getstring "\nString: ")) (setq name4 string) (setq string (getstring "\nString: ")) (setq name5 string) to something like: (setq i (getint "\nStarting number: ")) (while (> 20 i) ;what ever you're looping for (setq string (getstring "\nString: ")) (setq name[-increment here-] string) (setq i (1+ i)) ) ;;then later (princ name3) ;;or whatever I want to use. Thanks BigAl, I'll read about SET today Quote Link to comment Share on other sites More sharing options...
satishrajdev Posted July 10, 2021 Share Posted July 10, 2021 Hi, Give a try on this set method: (setq i 0) (while (and (setq s (getstring "\nString : ")) (/= s "") ) (set (read (strcat "Name" (itoa (setq i (1+ i))))) s) ) Test on commandline: String : S1 String : S2 String : S3 Results: _2_$ name1 "S1" _2_$ name2 "S2" _2_$ name3 "S3" 1 Quote Link to comment Share on other sites More sharing options...
Steven P Posted July 12, 2021 Author Share Posted July 12, 2021 On 7/10/2021 at 6:17 AM, satishrajdev said: Hi, Give a try on this set method: (setq i 0) (while (and (setq s (getstring "\nString : ")) (/= s "") ) (set (read (strcat "Name" (itoa (setq i (1+ i))))) s) ) Thanks, that looks like what I was wondering, I'll try it this morning Quote Link to comment Share on other sites More sharing options...
ronjonp Posted July 12, 2021 Share Posted July 12, 2021 @Steven P What are going to use this code for? Quote Link to comment Share on other sites More sharing options...
Steven P Posted July 12, 2021 Author Share Posted July 12, 2021 Hi Ronjon, The background to this is that I was trying to make up a block creating routine (insert the block via a command rather than 'insert block' and then navigate to the relevant library on our system, scroll through that and then select and insert), and this is going into a part to grab the entity DXF codes for polylines used to create the block definition. All the other line types are put into strings and then outputted to a text file, LWPolylines weren't quite working and I thought creating a separate string for each would be easier then changing it all about so everything goes into lists. I can't say how many polylines I'd have so wanted to do it on the fly. Hope the description makes sense, though now there is half a chance that someone will post and say "what like this:", or "did you ever think of doing that" but there is no satisfaction in that is there. And the background to all of this is that part way through last year I wanted to put a 'thumbs up' emoji on the screen to the engineer on the other end of Microsoft Teams... and that set me wondering... can I do that with just a command line command.. which I can now... and I now think I should also use it for work too.... and so wanting to create more of a library in LISPs I want to speed up the creation. Apart from Emoji's I also have Elvis, John Wayne and a Jaguar e-type for when they ask if I can put a legend on the drawing..... some of the year was a bit slow. (The next part to this I have been beaten to it in AutoCAD 2020 where I'd use these LISP block definitions to make a pop up box with thumbnail tiles of them all to select, perhaps with pseudo tabs between block types, but I work for a living so this isn't going to happen quickly) Quote Link to comment Share on other sites More sharing options...
ronjonp Posted July 12, 2021 Share Posted July 12, 2021 Rather than creating a bunch of variables, maybe think about using an association list? (ALERT (ASSOC "B" '(("A" "A-DATA") ("B" "B-DATA") ("C" "C-DATA")))) Quote Link to comment Share on other sites More sharing options...
Steven P Posted July 12, 2021 Author Share Posted July 12, 2021 9 minutes ago, ronjonp said: Rather than creating a bunch of variables, maybe think about using an association list? (ALERT (ASSOC "B" '(("A" "A-DATA") ("B" "B-DATA") ("C" "C-DATA")))) Thanks. I don't use association lists enough I think. I might just look into that and see if I can make it nicer that way - what I was doing works now so everything else will be just improvements Quote Link to comment Share on other sites More sharing options...
ronjonp Posted July 12, 2021 Share Posted July 12, 2021 5 minutes ago, Steven P said: Thanks. I don't use association lists enough I think. I might just look into that and see if I can make it nicer that way - what I was doing works now so everything else will be just improvements Definitely look into them. They are a great way to organize data. 1 Quote Link to comment Share on other sites More sharing options...
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.