Author Topic: Tough Questions - Drawing Contours and Contour Labeling Lisp Needed  (Read 6481 times)

0 Members and 1 Guest are viewing this topic.

johnshar123xx

  • Guest
Tough Questions - Drawing Contours and Contour Labeling Lisp Needed


AutoCAD 2007
I have a quite a few tough questions/requests and I am currently looking for some lisps to solve them.  I have been doing some searching online to find the lisps I need, and although I have been able to find some stuff, I still have some things that I can't seem to find exactly what I am looking for.  I would like to take the opportunity ahead of time to thank every who views my
questions and for any help that is given.


1.) Wondering what is the easiest way to cad draw contours on a site plan, is the polyline tool the best thing to use?

2.) I am looking for a lisp that can label contours with their elevation in a specific way.  What I need is a lisp that uses the "current" textstyle selected for text size of label.  The lisp starts off asking the user to click a point to select a starting point of contour label and then asks for a second point to specify the text labels angle.  Then the lisp asks the elevation of the contour to be entered. Now for the tough part, I need the lisp to then place the contour label above the contour in a rectangle created with the "TCIRCLE" command with an offset factor of .20 with the two bottom points of the rectangle lining up with the contour (which is based on the two points clicked in the beginning of the lisp).  I have included a cad drawing file for an example of what I am looking for.

3.) I am also looking for the exact same lisp above for question two, but instead of having to enter an elevation by manually typing it in, the lisp asks you to select the contour line and it takes the "Z" elevation assigned to the contour line you select.

Who is up for the challenge?

fixo

  • Guest
Re: Tough Questions - Drawing Contours and Contour Labeling Lisp Needed
« Reply #1 on: November 30, 2009, 07:26:14 PM »
Code: [Select]
(defun alg-ang (obj pnt)
  (angle '(0. 0. 0.)
(vlax-curve-getfirstderiv
   obj
   (vlax-curve-getparamatpoint
     obj
     pnt
     )
   )
)
  )


(defun C:LAB(/ ang angp box dv en ent p1 p2 p3 p4 pt txten txthgt txtpt wid zstr zvalue)

  (setvar "osmode" 512)
  (setq txthgt 3.2);<--text height
    (if
    (setq ent (entsel "\nSelect contour line >>"))
     (progn
       (setq en (car ent))
       
  (while (setq pt (getpoint "\nPick a point on the contour (or press Enter to Exit) >> "))
   
    (setq pt (vlax-curve-getclosestpointto en pt)
  zvalue (caddr pt)
  zstr (rtos zvalue 2 0)
  dv (vlax-curve-getfirstderiv
   en
   (vlax-curve-getparamatpoint en pt))
  ang (alg-ang en pt)
  ang
(cond ((< (/ pi 2) ang (* pi 1.5)) (+ pi ang))
       (T ang)
       
  )
   angp (+ (/ pi 2) ang)
   txtpt (polar pt angp 0.2)
  )

       (entmake
       (list
       '(0 . "TEXT")
       '(100 . "AcDbEntity")
       (cons 67
  (if (= 0 (getvar "tilemode"))
    1
    0))
       (cons 410 (getvar "ctab"))
       '(8 . "C-TOPO-TEXT");<-- layer for texts
       '(100 . "AcDbText")
       (cons 10 txtpt)
       (cons 11  txtpt)
       (cons 40 txthgt)
       (cons 1 zstr)
       (cons 50 ang)
       '(41 . 1.0)
       '(51 . 0.0)
       '(7 . "Regular");<-- text style
       '(71 . 0)
       '(72 . 1)
       '(73 . 0)
       )
       )
    (setq txten (entlast)
  elist (entget txten)
  box (textbox (entget txten))
  wid (abs (apply '- (mapcar 'car box)))
  p1 (polar pt (+ ang pi) (+ (/ wid 2) 0.2))
  p2 (polar pt ang (+ (/ wid 2) 0.2))
  p4 (polar p1 angp (+ txthgt 0.4))
  p3 (polar p2 angp (+ txthgt 0.4))
  )

(entmake
    (append
    (list
    '(0 . "LWPOLYLINE")
    '(100 . "AcDbEntity")
    (cons 8  "C-TOPO-TEXT")
    '(100 . "AcDbPolyline")
    (cons 90 4)
    (cons 70 1)
    (cons 43 0.0)
    )
    (mapcar '(lambda (x) (cons 10 x)) (list p1 p2 p3 p4))    
    )
    )
   
    )
       )
    )
       (princ)
    )
(vl-load-com)
(princ "\n\t\t***Start command with LAB ...   ***")
(prin1)
    (vl-load-com)

johnshar123xx

  • Guest
Re: Tough Questions - Drawing Contours and Contour Labeling Lisp Needed
« Reply #2 on: December 02, 2009, 05:12:39 PM »
Wow, that is exactly what I was looking for.  I don't know if you wrote that specifically for me or if you found that, but it really means a lot.  I really appreciate your help.  That is a very impressive lisp created.

Can you tell me what in the lisp makes the rectangle size around the text.  On some of my drawings I may use different fonts which may conflict a little with the rectangle when printed.  If I could edit the size of the rectangle that would be great. 

But again I thank you a great deal for your help