Jump to content

Routine to Write Interpolated Elevation


Recommended Posts

Posted

I have a great lisp routine that allows me to pick two 2d points and enter the elevation for each.

Then I can pick a point between these two points and the routine will interpolate the elevation and show it in the command bar.

I need these added features.

1. Draw a line between the two points so I can pick a point on the line.

2. Erase the line after I have picked a point.

3. Write the elevation of the picked point on the drawing. This can be done by inserting a point or using a leader with the elevation in text.

 

Here's my present routine:

 

(defun c:elevpt (/ p1 p2 p3 p4 el1 el2 el3 d12 vecs tepPt deltaE deltaE3)
  (and  (setq p1 (getpoint "\nPick First point: "))
        (setq el1 (getdist "\nEnter elevation."))
        (setq p2 (getpoint p1 "\nPick Second point: "))
        (setq el2 (getdist "\nEnter elevation."))
        (setq deltaE (- el2 el1)
              d12 (distance p1 p2))
        (while (setq p3 (getpoint "\nPick point for elevation: "))
          (redraw)
          (grvecs (list 1 p1 p3 p3 p2))
          (setq tmpPt (polar p3 (+ (/ pi 2) (angle p1 p2)) 10.0))
          (setq p4 (inters p1 p2 p3 tmpPt nil))
          (setq deltaE3 (*(/ (distance p1 p4) (distance p1 p2))deltaE))
          (if (> (distance p2 p4) d12)
            (setq el3 (- el1 deltaE3))
            (setq el3 (+ el1 deltaE3))
          )
          (print (strcat "Elevation at point is " (rtos el3)))
        )
        )
  (princ)
)

Posted (edited)

Perhaps something like this?

 

NOTE: You need to use the appropriate object snap (nea, mid, etc.) to get the point you want.

I'm not sure if this line is even needed: "(setq p3 (vlax-Curve-GetPointAtParam o (vlax-Curve-GetParamAtPoint o p3))..."

EDIT: It's not - Removed.

(defun c:Elevpt (/ p1 el1 p2 el2 p3 el3 o)

   (if (and
          (setq p1  (getpoint "\nPick First point: "))
          (setq el1 (getdist "\nEnter Z Elevation of First Point: "))
          (setq p2  (getpoint p1 "\nPick Second point: "))
          (setq el2 (getdist "\nEnter Z Elevation of Second Point: "))
       )
      (progn
         (setq p1 (list (car p1)(cadr p1) el1)
               p2 (list (car p2)(cadr p2) el2)
         )
         (command "._Line" "_non" p1 "_non" p2 "")
         (setq o (vlax-Ename->vla-Object (entlast)))
         (if (setq p3 (getpoint "\nSelect a point on the Line: "))
            (progn
               (setq el3 (caddr p3))
               (command "._Point" "_non" p3)
               (command "._mleader" "_non" p3 "_non" (polar p3 1.0 0.0) "" (strcat "The Elevation is: " (rtos el3)) "")
            )
            (princ "\nNo Point Selected.")
         )
         (vla-Delete o)
      )

   )

)

 

 

Edited by pkenewell
Posted

Many thanks, pkenewell. The routine now draws a line, puts a 3-d point where I pick it, draws a leader and erases the line.

(The Leader scale was off but I didn't bother to set my leader scale.)

 

We're almost there. When I run the routine it doesn't label the point and gives me the following error:

 

Unable to recognize command "THE ELEVATION IS: 16.44". Please try again.nil

 

I'm not good at all with Lisp. Could you check this code for me?

 

Thanks.

Posted
On 12/11/2019 at 9:40 PM, Read_My_Lisp said:

 

(defun c:elevpt (/ p1 p2 p3 p4 el1 el2 el3 d12 vecs tepPt deltaE deltaE3)

......
 

 

Hi 'Read_your_Lisp' in code tags

 

Posted

if just straight line related thread 

i prefer vlax-curve- function more generic

(defun c:test (/ *error* el1 el2 en k p p1 p2 p3 str)

  (defun *error* (msg)
    (if	en
      (entdel en)
      )
    (redraw)
    )
  
  (and (setq p1 (getpoint "\nPick First point.. "))
       (setq el1 (getdist "\nEnter elevation: "))
       (setq p2 (getpoint p1 "\nPick Second point.. "))
       (setq el2 (getdist "\nEnter elevation: "))
       (setq en (entmakex (cons '(0 . "LINE")(mapcar ''((a b)(cons a (trans b 1 0)))'(10 11) (list p1 p2)))))
       )
  (while (= (car (setq k (grread T 13))) 5)
    (redraw)
    (and (setq p3 (cadr k))
	 (setq p3 (cond ((osnap p3 "_end,_int"))
		       (p3)
		       )
	       )
	 (setq p (cadr
		   (hp:ptol p3
			    (mapcar ''((a b) (list (car a) (cadr a) b))
				    (list p1 p2)
				    (list el1 el2)
				    )
			    t
			    )
		   )
	       )
	 (progn	(grdraw p1 p2 1)
		(grdraw p3 p 2)
		(princ (setq str (strcat "\rElevation = " (rtos (caddr p) 2))))
		)
	 )
    )
  (redraw)
  (vl-cmdf "_LEADER" "_non" p "_non" "\\" "" str "")
  (entdel en)
  (princ)
  )


;point to line 
(defun hp:ptol (p 2p 3d / ad d pp) ; hanhphuc - 29.10.2015
  (setq	ad (mapcar '(lambda (f)
		      (apply f
			     (mapcar '(lambda (x) (list (car x) (cadr x))) 2p)
			     )
		      )
		   '(angle distance)
		   )
	d  (vxv	(mapcar '- p (car 2p))
		(mapcar '(lambda (f) (f (car ad))) (list cos sin))
		)
	pp (polar (car 2p) (car ad) d)
	)
  (if (<= 0. d (cadr ad))
    (list (distance p pp)
	  (list	(car pp)
		(cadr pp)
		(if 3d
		  (+ (*	(/ (apply '- (mapcar 'last (reverse 2p)))
			   (cadr ad)
			   )
			d
			)
		     (caddr (car 2p))
		     )
		  (caddr p)
		  )
		)
	  )
    )
  )
  
;; Vector Dot Product  -  Lee Mac
;; Args: u,v - vectors in R^n
(defun vxv ( u v )
   (apply '+ (mapcar '* u v))
)

 

Posted
14 hours ago, Read_My_Lisp said:

Many thanks, pkenewell. The routine now draws a line, puts a 3-d point where I pick it, draws a leader and erases the line.

(The Leader scale was off but I didn't bother to set my leader scale.)

 

We're almost there. When I run the routine it doesn't label the point and gives me the following error:

 

Unable to recognize command "THE ELEVATION IS: 16.44". Please try again.nil

 

I'm not good at all with Lisp. Could you check this code for me?

 

Thanks.

 

@Read_My_Lisp I have tested the code and it works fine for me. Here are a couple variable factors.

 

1) You have and old version of AutoCAD prior to Mleaders. What version of AutoCAD are you using? Would you rather use the legacy LEADER?

2) For some reason your prompts are different on the MLEADER command. Is your MLEADERSTYLE set up with a different annotation method (such as a keynote block or no annotation)?

 

Perhaps send me a sample drawing so I can see what is happening for you?

 

Posted

Again, thanks for your diligence, pkenewell.

 

I'm using BricsCad 15 Linux. Soon to be upgraded.

Maybe a bit unusual but there's a very good reason for my CAD setup.

That's a whole different issue that I won't get into now.

 

Your confirmation of the code has helped me a lot.

Yes, I have the mleader command but it must work a little differently than ACAD.

I'll try a tweak or two. Maybe using just text rather than a leader.

 

I wish I could find a good reference for Auto Lisp.

I'm a coder but I only know Pascal/Delphi/dbase and not Lisp.

 

If you could give me a command to write the x,y,z of the point that would really help.

 

Much thanks.

Posted (edited)

I got it!! I just used text instead of a leader.

 

I sometimes do takeoffs for contractors. Armed with this routine I can import a pdf (which is all they ever have) and make existing and proposed elevation grids.

I can then calculate earthwork manually using a grid method spreadsheet.

 

This method works great for small, relatively flat sites.

 

A huge thanks to pkenewell.

 

Here's the code.

 

(defun c:Elevpt (/ p1 el1 p2 el2 p3 el3 o)

   (if (and
          (setq p1  (getpoint "\nPick First point: "))
          (setq el1 (getdist "\nEnter Z Elevation of First Point: "))
          (setq p2  (getpoint p1 "\nPick Second point: "))
          (setq el2 (getdist "\nEnter Z Elevation of Second Point: "))
       )
      (progn
         (setq p1 (list (car p1)(cadr p1) el1)
               p2 (list (car p2)(cadr p2) el2)
         )
         (command "._Line" "_non" p1 "_non" p2 "")
         (setq o (vlax-Ename->vla-Object (entlast)))
         (if (setq p3 (getpoint "\nSelect a point on the Line: "))
            (progn
               (setq el3 (caddr p3))
               (command "._Point" "_non" p3)
               (command "DTEXT" p3 "" "" (rtos el3))               
            )
            (princ "\nNo Point Selected.")
         )
         (vla-Delete o)
      )

   )

)

 

Edited by Read_My_Lisp

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