Jump to content

Lisp to draw existing level Line on elevation


addresstemp

Recommended Posts

Hi!

 

I'm new in lisp loop. I want to draw existing topo line on elevation from topo survey plan. Surveyor drawing attached on top of elevation and get x coordinate to click point from survey plan and input z coordinate. These (x,z) on plan to draw polyline on elevation as (x,y). Drawing units is millimeter and show on plan data are meter.

 

Untitled-1.jpg

 

I tried to write lisp as below. I don't really know how to use "while" "list".

 

(defun c:Elevel (/ x1 l1 y1 pt1 x2 l2 y2 pt2)
 (setq x1 (rtos (car (getpoint "\nPick Point1: ")) 2 2))
 (setq l1 (getreal "\nEnter Level1: "))
 (setq y1 (rtos (* l1 1000) 2 2))
 (setq pt1 (strcat x1 "," y1))

 (while (/= nil
     (setq x2 (rtos (car (getpoint "\nPick Point2: ")) 2 2))
     (setq l2 (getreal "\nEnter Level2: "))
     (setq y2 (rtos (* l2 1000) 2 2))
     (setq pt2 (strcat x2 "," y2))
 )


   (command "_pline" pt1 pt2 "")
   (setq pt1 pt2)
 )

 (princ)

)

 

Thanks in advance,

Jack

Link to comment
Share on other sites

polyline are not continuous. and exit error. can anyone help me to fix lisp?

Edited by addresstemp
Link to comment
Share on other sites

Something like this ?

 

(defun c:Elevel (/ l1 p1 l2 p2)
 (if (and (setq p1 (getpoint "\nPick Point 1: "))
          (setq l1 (getreal "\nEnter Level 1: "))
     )
   (progn
     (setq p1 (strcat (rtos (car p1) 2 2) "," (rtos (* l1 1000.) 2 2)))
     (while (and (setq p2 (getpoint "\nPick Point2: "))
                 (setq l2 (getreal "\nEnter Level2: "))
            )
       (command "_pline"
                "_non"
                p1
                "_none"
                (setq p2
                       (strcat (rtos (car p2) 2 2) "," (rtos (* l2 1000.) 2 2))
                )
                ""
       )
       (setq p1 p2)
     )
   )
 )
 (princ)
)

Link to comment
Share on other sites

You should only need to pick the text or the cross if it has a Z to get the elevation value its an extra step not needed, If the text insert is at the cross point then you can use that for X,Y. The bit missing was working out the true distance between the points I could not see that in your code, its probably easier to make a list of the points and then draw the pline in one go. Did you create the points from maybe a X,Y,Z file CSV then it would be easier to just use that and not pick any points.

Link to comment
Share on other sites

Hi

 

AFAIK you have to delve a little deeper into AutoLISP to generate continuous polylines.

 

  (setq file (open name "r"))                        ; Open file for second read
 (entmake '((0 . "polyline")
            (66 . 1)
            (62 . 5)))
 (entmake '((0 . "vertex")(10 0 0 0)))              ; Set init polyline point
 (setq info (read-line file))                       ; Read data line
 (while (/= info nil)
    (setq data (read (strcat "(" info ")"))         ; Convert to list
               x1 (nth 2 data)                      ; Point Resist
               y1 (car data)                        ; Y coord (depth)
               y2 (* y1 -10)                        ; Plot Y's downward
               x2 (* (* x1 0.2) 10)
               )                                    ; end setq
               (entmake  (list '(0 . "vertex") (list 10 x2 y2 0)))
               (setq info (read-line file))
    )                                               ; end while
  (entmake '((0 . "seqend")))                       ; Close polyline

Link to comment
Share on other sites

Try this program , and when you finish picking points just hit ENTER and NOT escape button .

 

(defun c:Test  (/ l i l1 p1 l2 p2)
;;; Tharwat 15.03.2015    ;;;
 (if (and (setq p1 (getpoint "\nPick Point 1: "))
          (setq l1 (getreal "\nEnter Level 1: "))
          )
   (progn
     (setq p1 (list (car p1) (* l1 1000.))
           l  (cons p1 l)
           )
     (while (and (setq p2 (getpoint "\nPick Point2: "))
                 (setq l2 (getreal "\nEnter Level2: "))
                 )
       (setq l (cons (setq p2
                            (list (car p2) (* l2 1000.))
                           )
                     l)
             i 0
             )
       (repeat (1- (length l))
         (grdraw (nth i l) (nth (setq i (1+ i)) l) 2 1)
         )
       )
     (entmakex
       (append (list '(0 . "LWPOLYLINE")
                     '(100 . "AcDbEntity")
                     '(100 . "AcDbPolyline")
                     (cons 90 (length l))
                     '(70 . 0))
               (mapcar (function (lambda (p) (cons 10 p))) l)))
     )
   )
 (redraw)
 (princ)
 )

Link to comment
Share on other sites

  • 1 month later...

Thank you Tharwat. Your lisp can generate continuous polyline and draw from world UCS. But for elevation, I changed UCS origin and draw elevation around the plan. These topo levels are draw from user ucs. but it is not relate with user ucs. It's far from user ucs. I attached sample dwg. Please check for me. Thanks

For Lisp.dwg

Edited by addresstemp
Missing attach file
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...