Jump to content

Interpolation Lisp Needed


johnshar123xx

Recommended Posts

Does my earlier code in post #5 not produce the desired result?

 

I'm sure when I wrote it that it was just a rewrite of Larrys code...

 

I wish it did, but I am drafting in 2D environment, no Z coordinates. Your code doesn't ask heights.

Link to comment
Share on other sites

Try this quick modificaton:

 

(defun c:test (/ p1 p2 h1 h2 i e n inc)
 (setvar "PDMODE" 3)

 (cond ((and (setq p1 (getpoint "\nPick Point 1: "))
             (setq h1 (getreal "\nSpecify First Height: "))
             (setq p2 (getpoint "\nPick Point 2: " p1))
             (setq h2 (getreal "\nSpecify Second Height: ")))

        (setq i 0 e (entmakex (list (cons 0 "LINE") (cons 10 p1) (cons 11 p2)))
              
              inc (/ (setq n (fix (abs (- h2 h1)))) (distance p1 p2)))

        (while (< (setq i (1+ i)) n)
          (entmake (list (cons 0 "POINT")
                         (cons 10 (vlax-curve-getPointatDist e (/ i inc))))))))
 (princ))

 

I haven't got access to CAD at the minute to test it.

Link to comment
Share on other sites

Maybe an if clause of some sort? For example, if the point was 21.324.

Then check if 21.250

 

 

any decimal greater than 0.25 will create an error, so I used some conditionals. This worked the one time I tried it

(defun c:test (/ pt1 el1 pnt1 pt1 el2 pnt2 len el1a slp d1)
 (vl-load-com)
 (setvar "osmode" 0)
 (setvar "pdmode" 3)
 (setq pt1 (getpoint "\nPick point 1: ")
       el1 (getreal "\nEnter elevation 1: ")
       pnt1 (list (car pt1) (cadr pt1) el1)
       pt2 (getpoint pt1 "\nPick point 2: ")
       el2 (getreal "\nEnter elevation 2: ")
       pnt2 (list (car pt2) (cadr pt2) el2)
       len (distance pnt1 pnt2)
   )
 (if
   (<= (rem el1 1.0) 0.25)
     (setq el1a (+ 0.25 (fix el1)))
   (progn
     (cond
   ((and (> (rem el1 1.0) 0.25) (<= (rem el1 1.0) 0.5)) (setq el1a (+ 0.5 (fix el1))))
   ((and (> (rem el1 1.0) 0.5) (<= (rem el1 1.0) 0.75)) (setq el1a (+ 0.75 (fix el1))))
   ((and (> (rem el1 1.0) 0.75) (<= (rem el1 1.0) 0.999)) (setq el1a (+ 1.0 (fix el1))))
      )
    )
   )
(setq slp (/  (- el2 el1)(distance pnt1 pnt2))
       d1 (/ (- el1a el1) slp)
)
 (setq obj (vlax-ename->vla-object
    (entmakex
      (list
        (cons 0 "LINE")
        (cons 10 pnt1)
        (cons 11 pnt2)
        )
      )
   )
   )
 (while (< d1 len)
        (entmakex
      (list
        (cons 0 "POINT")
        (cons 10 (vlax-curve-getPointAtDist Obj d1))
        )
      )
   (setq d1 (+ d1 (/ 0.25 slp)))
   )
 (princ)
 )

Link to comment
Share on other sites

lpseifert :shock: It works!

 

Thanks a thousand!

 

Lee Mac - The code seems to work, but it still makes a point after every 1 meter, not 0.25; 0.5; 0.75.

 

Thanks to everyone, usually noone has the time to explain stuff to me.

Link to comment
Share on other sites

lpseifert :shock: It works!

 

Thanks a thousand!

 

Lee Mac - The code seems to work, but it still makes a point after every 1 meter, not 0.25; 0.5; 0.75.

 

Thanks to everyone, usually noone has the time to explain stuff to me.

 

Ok, if I have time I shall perhaps tidy my code just for completeness.

Link to comment
Share on other sites

  • 8 months later...

Hi, lpseifert! Your lisp is amazing! But I need to interpolate with 5 height difference. What I should do? Can you help me? Thank you...

Link to comment
Share on other sites

  • 1 year later...
  • 4 years later...

I am trying to make a flexible click-based interpolate lisp to populate a drawing with elevations where I need them. Currently I just use the ol' measure-measure-manually calculate method...which gets tedious after about the 30th time...

 

To that end, I was trying to edit/combine several interpolation lisps (from above and also on other forums, see links at end of post), but have been unsuccessful - here is what I am trying to accomplish:

 

1) pick point "A" (snap options would be nice)

2) enter elevation (ability to grab from text or attribute content would be nice, but manual entry is ok)

3) pick point "B" (snap options would be nice)

4) enter elevation (ability to grab from text or attribute would be nice, but manual entry is ok)

5) create a layer "INTP_EL"

6) draw a temporary line from A to B on layer "INTP_EL"

7) prompt to click somewhere (point "C") along that line (using osnaps for intersection point with other lines, if any, or an arbitrary location along that line, etc)

8) interpolate the elevation at "C"

9) draw a circle with center at "C" and radius = 1/2 of defult text height on layer "INTP_EL"

10) create a text object next to that circle that contains the interpolated elevation of point "C" on layer "INTP_EL"

11) loop 7-10 for more points "D" "E" etc or to end

12) erase the temporary line

 

all the pieces are around, I just can't get them to work together...

 

any help would be much appreciated

 

similar discussion threads:

http://forums.augi.com/archive/index.php/t-69723.html

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/interpolate-lsp/td-p/2554741

https://www.theswamp.org/index.php?topic=45013.0

https://forums.autodesk.com/t5/autocad-civil-3d-customization/create-points-interpolate-with-lisp/td-p/4775209

Link to comment
Share on other sites

A simple version of what you want, it can be expanded to say enter z as -ve pick text its just a start not everything you asked for.

 

(defun c:test ( / z1 z2 z3 ratio pt1 pt3 pt2 obj len)
(if (not AH:getval3)(Load "getvals3"))
(setq oldsnap (getvar 'osmode))

(AH:getval3 "Enter start Z" 5 4 "0.0" "Enter end Z" 5 4 "0.0"  "Enter distance ratio " 5 4 "0.5")

(setq z1 (atof val1))
(setq z2 (atof val2))
(setq ratio (atof val3))

(setq pt1 (getpoint "Pick start point"))
(setq pt2 (getpoint "Pick end point"))
(setvar 'osmode 0)
(setq pt1 (list (car pt1)(cadr pt1) z1))
(setq pt2 (list (car pt2)(cadr pt2) z2))
(command "line" pt1 pt2 "")

(setq obj (vlax-ename->vla-object (entlast)))
(setq len (vla-get-length obj))

(setq pt3 (vlax-curve-getpointatdist obj (* len ratio)))
(command "circle" pt3 1.0)
(setvar 'osmode oldsnap)
)

GETVALS3.lsp

Edited by BIGAL
Link to comment
Share on other sites

bigal,

 

I tried it and I get as follows:

 

interpolate_Test.lsp") C:TEST

Command: test

; error: LOAD failed: "getvals3"

Command:

 

also I am in acad2011, 2-D drafting.

 

In an effort to learn I did some homework and took a stab at this. I have been working on trying to combine things to accomplish interpolation as I described above - this is my first stab at into writing lisps, so pardon the cave-man coding...

 

It works all the way to the end, and then I get:

 

"Command: ; error: bad DXF group: (1 . 3.0)"

 

(with the 3.0 being the elevation calculated as el3, see below). Where am I going wrong?

 

Thanks for your thoughts

 

(defun c:INTEL (/ p1 p2 p3 el1 el2 el3 dista distb distc h1 prod r1) ;define the function
(setq p1 (getpoint "\nPick First Point : "));get the first point
(setq el1 (getreal "\nSpecify First Elevation : "));manually enter first elevation
(setq p2 (getpoint "\nPick Second Point : "));get the second point
(setq el2 (getreal "\nSpecify Second Elevation : "));manually enter second elevation
(command "Line" p1 p2 "");draw the line
(setq p3 (getpoint "\ns Pick Interpolation Point : "));get the first point
(setq distb (distance p1 p3))
(setq distc (distance p2 p3))
(setq dista (+ distb distc))
(setq h1 (abs(- el1 el2)))
(setq prod (* h1 distb))
(setq r1 (/ prod dista))
(setq el3 (+ r1 el1));calculate interpolated elevation
;(print (strcat "Elevation at point is " (rtos el3)))
;(print (strcat "distb " (rtos distb)))
;(print (strcat "distc " (rtos distc)))
;(print (strcat "dista " (rtos dista)))
;(print (strcat "h1 " (rtos h1)))
;(print (strcat "el1 " (rtos el1)))
;(print (strcat "el2 " (rtos el2)))
;(print (strcat "prod " (rtos prod)))
;(print (strcat "r1 " (rtos r1)))
(command "circle" p3 0.5)
(entmake                                                              ;Start entity make
   (list                                                               ;Start list
     (cons 0   "TEXT")                                                 ;Entity type
     (cons 8   "TEXT")                                                 ;Layer name
     (cons 40   1.3)                                                 ;Text height
     (cons 1    el3)                                                   ;Text string 
     (cons 50   0.0)                                                   ;Text rotation
     (cons 41   1.0)                                                   ;Relative x scale factor
     (cons 51   25)                                                   ;Oblique angle
     (cons 7   "SIMPLEX")                                               ;Text style
     (cons 71   0)                                                     ;Text generation flag
     (cons 72   0)                                                     ;Horizontal justification flag center
     (cons 11   p3)                                                  ;Text first base point
     (cons 73   1)                                                     ;Bottom justification
   )                                                                   ;End list
)
);end defun

Edited by SLW210
Added Code Tags.
Link to comment
Share on other sites

You have to save the getvals3.lsp to a supported location on your PC or else change the Load to a full directory description so it can load. eg (Load "C:\\Myautocad_stuff\mylisps\\getvals3"))

Link to comment
Share on other sites

The DXF-code value for group code 1 should be a string:

(cons 1 (rtos el3))

 

Thanks... that fixed the dxf issue, but now it just says "nil"

 

...entmake seems fairly straightforward...not sure why I can't get it to work...

 

Thoughts?

Link to comment
Share on other sites

Updated code forgot about osnap

 

Why use getval3 ?

 

... the main functionality that I need is to click arbitrary third point and drop a text object with the calculated elevation (see my attempt at the script above). Distance ratio still means extra manual number crunching.

Link to comment
Share on other sites

Been tinkering. Got something that does the job. Any input on cleaning it up would be great.

 

;multiple interpolation function to populate text elevation labels 
; base lisp from thread at http://forums.augi.com/showthread.php?69723-LOOKING-FOR-A-LISP-ROUTINE, Last edited by CAB2k; 2007-10-25 at 08:51 PM. 
; modified by Nete Laana on 24.01.18
(defun c:MINT (/ p1 p2 p3 p4 el1 el2 el3 d12 vecs tepPt deltaE deltaE3 t1)
(setq p1 (getpoint "\nPick First point: "))
(setq el1 (getdist "\nEnter elevation."))
(setq p2 (getpoint p1 "\nPick Second point: "))
(setq el2 (getdist "\nEnter elevation."))
(command "Line" p1 p2 "");draw the line
(and
(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)))
(setq t1 (rtos el3 2 2)); convert to text string rounded to two digits
(command "circle" p4 0.15); draw circle to identify point
(and(command ".TEXT" p3 1.2 0 t1); dump el3 as text object
)
)
)
(princ)
)

I would like to exit the while loop and then delete the line with , but I can't get it to work yet with multiple instances. the closest I can get is this

 

;interpolation function to populate text elevation labels 
; written by Nete Laana on 24.01.18
(defun c:INTEL (/ p1 p2 p3 el1 el2 el3 dista distb distc h1 prod r1 t1) ;define the function intel
(setq p1 (getpoint "\nPick First Point : "));get the first point
(setq el1 (getreal "\nSpecify First Elevation : "));manually enter first elevation
(setq p2 (getpoint "\nPick Second Point : "));get the second point
(setq el2 (getreal "\nSpecify Second Elevation : "));manually enter second elevation
(command "Line" p1 p2 "");draw the line
(setq p3 (getpoint "\ns Pick Interpolation Point : ")); pick desired interpolation point
(setq distb (distance p1 p3)); calculate distance a
(setq distc (distance p2 p3)); calculate distance b
(setq dista (+ distb distc)); calculate total distance
(setq h1 (- el2 el1)); calculate height difference
(setq prod (* h1 distb)); numerator
(setq r1 (/ prod dista)); relative height 
(setq el3 (+ r1 el1));calculate interpolated elevation
(setq t1 (rtos el3 2 2)); convert to text string rounded to two digits
(entdel (entlast)); delete the line
(command "circle" p3 0.15); draw circle to identify point
(command ".TEXT" p3 1.2 0 t1); dump el3 as text object
;(print (strcat "Elevation at point is " (rtos el3)))
;(print (strcat "distb " (rtos distb)))
;(print (strcat "distc " (rtos distc)))
;(print (strcat "dista " (rtos dista)))
;(print (strcat "h1 " (rtos h1)))
;(print (strcat "el1 " (rtos el1)))
;(print (strcat "el2 " (rtos el2)))
;(print (strcat "prod " (rtos prod)))
;(print (strcat "r1 " (rtos r1)))
;(print (strcat "t1 " t1))
(princ)
) 

Link to comment
Share on other sites

  • 1 year later...

Sir,

anyone can help me. i am seeking a lisp for interpolation . Show elevation in grid pattern. as show in attached RFI.

here i had digitized Grid . i need Zvalue on grid Crossing. any oe can help me with lisp.

please please please help me.

image.thumb.png.a847ba0f615e2b83dcccbfc8ba60010d.png

Link to comment
Share on other sites

This is the one that I currently use... it is not ideal for a grid like this because you still need to manually run each segment, but it gets the job done. 

 

; multiple interpolation function to populate text elevation labels 
; base lisp from thread at http://forums.augi.com/showthread.php?69723-LOOKING-FOR-A-LISP-ROUTINE, Last edited by CAB2k; 2007-10-25 at 08:51 PM. 
; modified by Nete Laana on 24.01.18
; 22.03.18 ADDED SLOPE OUTPUT
(defun c:MINTS (/ p1 p2 p3 p4 el1 el2 el3 d12 vecs tmpPt deltaE deltaE3 t1 s1 l1 mpt)
(setq p1 (getpoint "\nPick First point: "))
(setq el1 (getdist "\nEnter elevation."))
(setq p2 (getpoint p1 "\nPick Second point: "))
(setq el2 (getdist "\nEnter elevation."))
(setq s1 (*(/ (- el2 el1) (distance p1 p2))100)); calc slope percentile
(print (strcat "the slope is " (rtos s1)"%")); cmd slope
(setq l1 (strcat (rtos s1)"% SLOPE")); string for slope
(print l1); cmd string
(setq mpt (polar p1 (angle p1 p2) (/ (distance p1 p2) 2.) )); find midpoint
(command ".TEXT" mpt 1.2 (* (angle p1 p2) (/ 180 pi)) l1); dump slope as text object
(command "Line" p1 p2 "");draw the line
(and
(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)))
(setq t1 (rtos el3 2 2)); convert to text string rounded to two digits
(command "circle" p4 0.15); draw circle to identify point
(and(command ".TEXT" p3 1.2 0 t1); dump el3 as text object
)
)
)
(princ)
)

 

in some newer drawings, I run into issues with the "text" command, and have modified: 

; multiple interpolation function to populate text elevation labels 
; base lisp from thread at http://forums.augi.com/showthread.php?69723-LOOKING-FOR-A-LISP-ROUTINE, Last edited by CAB2k; 2007-10-25 at 08:51 PM. 
; modified by Nete Laana on 2018.01.24
; 2018.03.22 netelaana added slope output
; 2018.10.24 netelaana modified text function
(defun c:MINTS (/ p1 p2 p3 p4 el1 el2 el3 d12 vecs tmpPt deltaE deltaE3 t1 s1 l1 mpt)
(setq p1 (getpoint "\nPick First point: "))
(setq el1 (getdist "\nEnter elevation."))
(setq p2 (getpoint p1 "\nPick Second point: "))
(setq el2 (getdist "\nEnter elevation."))
(setq s1 (*(/ (- el2 el1) (distance p1 p2))100)); calc slope percentile
(print (strcat "the slope is " (rtos s1)"%")); cmd slope
(setq l1 (strcat (rtos s1)"% SLOPE")); string for slope
(print l1); cmd string
(setq mpt (polar p1 (angle p1 p2) (/ (distance p1 p2) 2.) )); find midpoint
(command ".TEXT" mpt (* (angle p1 p2) (/ 180 pi)) l1); dump slope as text object
(command "Line" p1 p2 "");draw the line
(and
(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)))
(setq t1 (rtos el3 2 2)); convert to text string rounded to two digits
(command "circle" p4 0.15); draw circle to identify point
(and(command ".TEXT" p3 0 t1); dump el3 as text object
)
)
)
(princ)
)

 

hopefully this helps....

 

- NL

  • Dislike 1
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...