pttr Posted June 11, 2022 Posted June 11, 2022 Hi i´m gonna use the If function multiple times and need to change co, ip1 and ip2. Problem is I want to increase the value with something like +1 +2 and not define a new string. For example i dont want (setq co "1,0") I want (setq(+1)) (defun c:tf1 (/ co ip1 ip2 abl bfind) (setq co "0,0") ;sett coordinates block (setq ip1 "10,0") ;sett coordinates of first insertionpoint text (setq ip2 "41.99,0") ;sett coordinates of second insertionpoint text (setq bfind (tblsearch "block" "BSL_L6")) ;Search for block BSL_L6 in modell (if bfind(command "-insert" "BSL_L6" co "1" "" "" "-MTEXT" ip1 "H" "1.6" ip2 "Handbrandsläckare" "") ;if block exist in modell place block + text to block BSL_L6 ) ) Quote
Tharwat Posted June 11, 2022 Posted June 11, 2022 Here is one example for you to get started and its easy to modify it for the rest of your variables. (setq co (list 0.0 0.0)) (setq co (list (+ (car co) 1.0) (cadr co))) Just ask if you stuck or might need any further help. 1 Quote
Steven P Posted June 11, 2022 Posted June 11, 2022 Could also loot at mapcar - I'm having to learn to use that this week, (setq co (mapcar '1+ c0)) which add 1 to each list item or (setq co (mapcar '+ co listtoadd)) Which should add item 1 in listtoadd to item 1 in co, item 2 in listtoadd to item 2 in co and so on (example if co is (2 4 6) and listtoadd is (1 2 3) the end result is co being (3 6 9) However you will also need to make co, ip1, ip2 as lists, in between ".... " as they are now and they are treated as strings in the LISP. Depends what you need your lists to do later, you might need Lee Macs string to List and his List to String routines for the conversion - convert it one way, do the sums, convert it back again http://lee-mac.com/listtostring.html http://lee-mac.com/stringtolist.html Quote
exceed Posted June 12, 2022 Posted June 12, 2022 (defun c:tf1 (/ co ip1 ip2 abl bfind oldcmd xdelta ydelta) (setq oldcmd (getvar 'cmdecho)) (if (= oldcmd 1) (setvar 'cmdecho 0)) (setq co (list 0 0)) ;set coordinates block (setq bfind (tblsearch "block" "BSL_L6")) ;search for block BSL_L6 in modell (if bfind (progn (setq xdelta 200) ;this is for test (setq ydelta 300) ;this is for test (repeat 10 ;this is for test (setq ip1 (list (+ (car co) 10) (cadr co))) ;set coordinates of first insertionpoint text (setq ip2 (list (+ (car co) 41.99) (cadr co))) ;set coordinates of second insertionpoint text (command "-insert" "BSL_L6" co "1" "" "" "-MTEXT" ip1 "H" "1.6" ip2 "Handbrandslackare" "") ;if block exist in modell place block + text to block BSL_L6 (setq co (list (+ (car co) xdelta) (+ (cadr co) ydelta))) ) ) ) (setvar 'cmdecho oldcmd) (princ) ) like this? As mentioned above, handle the coordinates as a list than string is more easy. Quote
pttr Posted June 12, 2022 Author Posted June 12, 2022 Thanks for at lot of answers! In this funcion i understand that cadr is the second value in the list but how do I change it? (setq co (list (+ (car co) 1.0) (cadr co))) I tried doing this: (setq co (list (- (cadr co) 15.0) (car co))) Dosent like it at all.. Thoughts? Quote
Tharwat Posted June 12, 2022 Posted June 12, 2022 The same way you did deduct the first element ( X coordinates ) although it has to be car and not cadr (setq co (list (- (car co) 15.0) ;; X = (car co) so now it is minus 15.0 from oroginal X value. (- (car co) 10.0) ;; Y = (cadr co) so now it is minus 10.0 from original Y value. ) ) 1 1 Quote
Tharwat Posted June 12, 2022 Posted June 12, 2022 1 minute ago, pttr said: Man super! Works like a dream! Good for you, happy coding. 1 Quote
pttr Posted June 12, 2022 Author Posted June 12, 2022 Ok i have a new problem... Im trying to use "list" as coordinates for -MTEXT problem is that -MTEXT needs a , inbetween the coordinates. example: -Mtext 0.0,-15.0 ;first insertionpoint 40.0,-30.0 ;second insertionpoint Here is code (setq co (list (car co) (- (car co)15.0))) (setq ip1 (list (car ip1) (cadr ip1))) (setq ip2 (list (car ip2) (cadr ip2))) (command "-insert" "BSL_L6" co "1" "" "" "-MTEXT" ip1 "H" "1.6" ip2 "Handbrandsläckare" "") Any idea? Man i´m bad at lisp syntax Quote
Tharwat Posted June 12, 2022 Posted June 12, 2022 No it does not need command in between the coordinates if you used them as lists as examples posted above. But if you use them as strings then yes that's required although this is not needed at all because command accepts decimal or string inputs at the same time. 2 Quote
Tharwat Posted June 12, 2022 Posted June 12, 2022 Here is an example for you to move forward which should help you to know who it works. (setq ip1 (list 0.0 0.0) ip2 (list 0.0 1.0) ) (repeat 3 ;; repeat 3 times (command "-MTEXT" "_non" ip1 "H" "1.6" "_non" ip2 "Handbrandsläckare" "") (setq ip1 (list (+ (car ip1) 25.0) (cadr ip1)) ;; add 25.0 units to X coordinates ip2 (list (+ (car ip2) 25.0) (cadr ip2)) ;; add 25.0 units to X coordinates ) ) 2 Quote
Steven P Posted June 12, 2022 Posted June 12, 2022 1 hour ago, pttr said: Thanks for at lot of answers! In this funcion i understand that cadr is the second value in the list but how do I change it? (setq co (list (+ (car co) 1.0) (cadr co))) I tried doing this: (setq co (list (- (cadr co) 15.0) (car co))) Dosent like it at all.. Thoughts? See my answer above with mapcar, (setq co (mapcar '+ '(0 1 ) co)) will add 1 to the second list item in CO for example, Also see my answer above if your MTEXT coordinates are strings, Lee Mac LISP to convert the string to a list, makes the whole thing a lot easier if needed. 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.