Results 1 to 8 of 8

Thread: Contour Labeling Lisp

  1. #1
    Member
    Join Date
    2008-10
    Posts
    34

    Default Contour Labeling Lisp

    On another forum a member by the name of "fixo" was nice enough to write this lisp for me but I just need a little help with it, if anyone can.

    Basically this lisp takes the "z" elevation of a contour and places the value in a rectangle above the contour line. The only slight problem I had with it is, I would like to be able to increase the size of the rectangle around the text. If I use a different font, it gets close to the rectangle, which you can notice even more so when plotted.

    I was wondering if someone can point out what numbers within the lisp I would have to change in order to increase the offset of this rectangle around the text. I am assuming it is towards the bottom where it says "text box".

    The lisp is a nice one for labeling contours without having to break the contour lines, hopefully others can use it. Again if "fixo" reads this, I thank you again for your help.


    Code:
    (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)
    Sorry for the *edit*, but code reads much better when the "Code" button is used.
    For further details please refer to "Reading and Posting Messages" on the FAQs Page.
    Last edited by Opie; 2009-12-16 at 02:43 PM. Reason: [code] tags adjusted

  2. #2
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,217

    Default Re: Contour Labeling Lisp

    Quote Originally Posted by johnshar123xx View Post
    On another forum a member by the name of "fixo" was nice enough to write this lisp for me but I just need a little help with it, if anyone can.

    Basically this lisp takes the "z" elevation of a contour and places the value in a rectangle above the contour line. The only slight problem I had with it is, I would like to be able to increase the size of the rectangle around the text. If I use a different font, it gets close to the rectangle, which you can notice even more so when plotted.

    I was wondering if someone can point out what numbers within the lisp I would have to change in order to increase the offset of this rectangle around the text. I am assuming it is towards the bottom where it says "text box".

    The lisp is a nice one for labeling contours without having to break the contour lines, hopefully others can use it. Again if "fixo" reads this, I thank you again for your help.
    Did you want increase offset rectangle gap from text?
    Let me minute

    ~'J'~
    "The whole problem with the world is that fools and fanatics are always
    so certain of themselves, and wiser people so full of doubts."
    Bertrand Russell

  3. #3
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,217

    Default Re: Contour Labeling Lisp

    Try edited lisp
    Code:
    (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
     gap (/ txthgt 4));<-- change gap here
        (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 gap)
       )
           (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) gap))
       p2 (polar pt ang (+ (/ wid 2) gap))
       p4 (polar p1 angp (+ txthgt (* gap 2)))
       p3 (polar p2 angp (+ txthgt (* gap 2)))
       )
    (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)
    ~'J'~
    "The whole problem with the world is that fools and fanatics are always
    so certain of themselves, and wiser people so full of doubts."
    Bertrand Russell

  4. #4
    Active Member
    Join Date
    2001-12
    Posts
    54

    Default Re: Contour Labeling Lisp

    Quote Originally Posted by fixo View Post
    Try edited lisp
    Code:
    (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
     gap (/ txthgt 4));<-- change gap here
        (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 gap)
       )
           (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) gap))
       p2 (polar pt ang (+ (/ wid 2) gap))
       p4 (polar p1 angp (+ txthgt (* gap 2)))
       p3 (polar p2 angp (+ txthgt (* gap 2)))
       )
    (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)
    ~'J'~
    Many times for accurate analysis we use contour intervals of 0.5 feet. Where in the program can we set the decimal accuracy to at least one decimal place ? Do it with cons = ??

  5. #5
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,217

    Default Re: Contour Labeling Lisp

    Quote Originally Posted by steveo View Post
    Many times for accurate analysis we use contour intervals of 0.5 feet. Where in the program can we set the decimal accuracy to at least one decimal place ? Do it with cons = ??
    Take a look at this line:
    Code:
     
    zstr  (rtos zvalue 2 0)
    Sorry I'm metric perhaps would be
    Code:
    zstr  (rtos zvalue 4 1)
    Test it by yourself

    ~'J'~
    "The whole problem with the world is that fools and fanatics are always
    so certain of themselves, and wiser people so full of doubts."
    Bertrand Russell

  6. #6
    Active Member
    Join Date
    2001-12
    Posts
    54

    Default Re: Contour Labeling Lisp

    Quote Originally Posted by fixo View Post
    Take a look at this line:
    Code:
     
    zstr  (rtos zvalue 2 0)
    Sorry I'm metric perhaps would be
    Code:
    zstr  (rtos zvalue 4 1)
    Test it by yourself

    ~'J'~
    Perfect help, thank you !!!!!!!

  7. #7
    Member
    Join Date
    2008-10
    Posts
    34

    Default Re: Contour Labeling Lisp

    Fixo you have done it again, that works perfect, it is exactly what I was looking for. Thank you so much for all your help with this lisp, it is greatly appreciated. It is also nice to see that other members are using the lisp as well.

  8. #8
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,217

    Default Re: Contour Labeling Lisp

    Quote Originally Posted by johnshar123xx View Post
    Fixo you have done it again, that works perfect, it is exactly what I was looking for. Thank you so much for all your help with this lisp, it is greatly appreciated. It is also nice to see that other members are using the lisp as well.
    You're welcome

    Glad if that helps

    Cheers

    ~'J'~
    "The whole problem with the world is that fools and fanatics are always
    so certain of themselves, and wiser people so full of doubts."
    Bertrand Russell

Similar Threads

  1. Help With Contour Labeling Elevation Precision
    By aspencer.226869 in forum AutoCAD Civil 3D - General
    Replies: 2
    Last Post: 2010-08-13, 09:26 PM
  2. Contour Labeling
    By tim_newsome in forum AutoCAD Civil 3D - General
    Replies: 3
    Last Post: 2010-05-06, 03:06 AM
  3. Polyline contour labeling in Civil 3D
    By jwissler in forum AutoLISP
    Replies: 8
    Last Post: 2009-02-26, 09:00 AM
  4. Contour Labeling & Data Shortcuts
    By pat.pennington in forum AutoCAD Civil 3D - Surfaces
    Replies: 1
    Last Post: 2009-01-30, 02:40 PM
  5. Lisp routine for Labeling Northing and Easting
    By mserapiglia in forum AutoLISP
    Replies: 1
    Last Post: 2008-05-21, 10:01 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •