Jump to content

Increase value of a corrdinate set as a varible


pttr

Recommended Posts

 

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

 

Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

tf2.gif

 

 

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

 

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

  • Like 2
Link to comment
Share on other sites

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

 

  • Like 2
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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