3 point text interpolation

3 point text interpolation

stojanov1
Observer Observer
639 Views
5 Replies
Message 1 of 6

3 point text interpolation

stojanov1
Observer
Observer

Hello,

 

I'd like to ask for a very usefull .lsp routine for site work. Reutine steps should be:

1. Click on a text (value of text is Z value, text in example below has SPACE instead of decimal point, but I can easily make it point or comma - do not worry about text syntax)

2. Click on second text

3. Click on third text (ideally, if possible, optionally click ENTER for third entry to interpolate just between the first two points)

4. Click on a point - the routine will put a text with interpolated Z value on this point.

 

(( I did look the forums, but was not able to find this exact functionality, and I'm not good enought with LISP to edit other scripts))

 

 

acadlsp.jpg

0 Likes
Accepted solutions (1)
640 Views
5 Replies
Replies (5)
Message 2 of 6

CADaSchtroumpf
Advisor
Advisor
Accepted solution

Hi,

This can help you?

 

(defun c:3text_interp  ( / mesg loop ent dxf_ent flag pxb pt z lst_pt n X1 X2 X3 Y1 Y2 Y3 Z1 Z2 Z3 E1 E2 E3 E4)
  (defun interp (pt1 pt2 px1 px2 / l_pt pint ptz)
    (setq l_pt (mapcar '(lambda (x) (list (car x) (cadr x) 0.0)) (list pt1 pt2 px1 px2)))
    (setq
      pint (inters (car l_pt) (cadr l_pt) (caddr l_pt) (cadddr l_pt) nil)
      ptz (inters pt1 pt2 pint (list (car pint) (cadr pint) (caddr pt1)) nil)
      ptz (list (car pint) (cadr pint) (if ptz (caddr ptz) 0.0))
    )
  )
  (repeat 3
    (if lst_pt
      (setq mesg "\nNext text: ")
      (setq mesg "\nFirst text: ")
    )
    (setq loop T)
    (while loop
      (setq ent (entsel mesg))
      (cond
        (ent
          (setq
            dxf_ent (entget (car ent))
            pt (cdr (assoc 10 dxf_ent))
            z (cdr (assoc 1 dxf_ent))
            z (read (vl-string-subst "." " " z))
            pt (list (car pt) (cadr pt) z)
            lst_pt (cons pt lst_pt)
            loop nil
          )
        )
        (setq loop T)
      )
    )
  )
  (if (equal pt (cadr lst_pt)) (setq flag T) (setq flag nil))
  (initget 9)
  (setq pt (getpoint "\nGive the point to interpolate: ") n 0)
  (cond
    (flag
      (setq pxb (polar pt (+ (angle (caddr lst_pt) (cadr lst_pt)) (* 0.5 pi)) (distance (caddr lst_pt) (cadr lst_pt))))
      (setq pt (interp (caddr lst_pt) (cadr lst_pt) pt pxb) Z (caddr pt))
    )
    (T
      (foreach item '(("X" . "'car") ("Y" . "'cadr") ("Z" . "'caddr"))
        (mapcar '(lambda (x) (set (read (strcat (car item) (itoa (setq n (1+ n))))) x))
          (mapcar (eval (read (cdr item))) lst_pt)
        )
        (setq n 0)
      )
      (setq
        E1 (+ (* X1 (- Y2 Y3)) (* X2 (- Y3 Y1)) (* X3 (- Y1 Y2)))
        E2 (+ (* Y1 (- Z2 Z3)) (* Y2 (- Z3 Z1)) (* Y3 (- Z1 Z2)))
        E3 (+ (* Z1 (- X2 X3)) (* Z2 (- X3 X1)) (* Z3 (- X1 X2)))
        E4 (- (- (* E2 X1)) (* E3 Y1) (* E1 Z1))
        Z (- (- (* (/ E2 E1) (car pt))) (* (/ E3 E1) (cadr pt)) (/ E4 E1))
      )
    )
  )
  (entmake
    (list
      '(0 . "POINT")
      '(100 . "AcDbEntity")
      (assoc 67 dxf_ent)
      (assoc 410 dxf_ent)
      (assoc 8 dxf_ent)
      '(100 . "AcDbPoint")
      (cons 10 (list (car pt) (cadr pt) Z))
    )
  )
  (entmake
    (list
      '(0 . "TEXT")
      '(100 . "AcDbEntity")
      (assoc 67 dxf_ent)
      (assoc 410 dxf_ent)
      (assoc 8 dxf_ent)
      '(100 . "AcDbText")
      (cons 10 (list (car pt) (cadr pt) Z))
      (assoc 40 dxf_ent)
      (cons 1 (vl-string-subst " " "." (rtos z 2 2)))
      (assoc 50 dxf_ent)
      (assoc 41 dxf_ent)
      (assoc 51 dxf_ent)
      (assoc 7 dxf_ent)
    )
  )
  (prin1)
)

 

Message 3 of 6

komondormrex
Mentor
Mentor

hi,

it is not an interpolation but averaging imho.

(defun c:average (/ text_ename_list 4th_text_value)
	(setq text_ename_list (list
					(car (entsel "\nPick 1st text: "))
					(car (entsel "\nPick 2nd text: "))
					(car (entsel "\nPick 3rd text: "))
				)
		text_ename_list (vl-remove nil text_ename_list)
		4th_text_value (vl-string-subst " "
			                      "."
			       		      (rtos (/
						      (apply '+
							     (mapcar '(lambda (text) (atof (vl-string-subst "." " " (cdr (assoc 1 (entget text))))))
									text_ename_list
								)
							)
						      	(length text_ename_list)
						      )
						)
			       )
	)
	(entmake (list '(0 . "text")
		       (cons 10 (getpoint "\Pick point for 4th text: "))
		       (cons 1 4th_text_value)
		       (assoc 40 (entget (car text_ename_list)))
		       (assoc 8 (entget (car text_ename_list)))
		 )
	)
  	(princ)
)
Message 4 of 6

stojanov1
Observer
Observer

This one works and does what I need it to do. I need to always pick 3 texts. Does not work with only two, but that is alright. Thanks for help.

 

(yes, I need interpolation, not average 🙂

 

 

0 Likes
Message 5 of 6

CADaSchtroumpf
Advisor
Advisor

@stojanov1  a écrit :

This one works and does what I need it to do. I need to always pick 3 texts. Does not work with only two, but that is alright. Thanks for help.

 

(yes, I need interpolation, not average 🙂

 

 


For a linear interpolation (with 2 points) for the 'Next point' click twice on the same point.

I updated the previous code

 

0 Likes
Message 6 of 6

hosneyalaa
Advisor
Advisor

Hi all 

 

Maybe @stojanov1 

Want like this 

Immagine.png.f87164af18f5e33430641133946e2dab.png

 

0 Likes