View Full Version : Polyline contour labeling in Civil 3D
jwissler
2008-07-30, 04:56 PM
I have been searching for a lisp routine or some other way to label the polyline contours in Civil 3D the way that Land Desktop did it. My company still uses user created polyline contours at elevation for begining of onsite grading and in strange situations were grading tools just can't produce the proper look, if anyone has a good way to do this besides old fashioned dtext on each line one at a time.
Thanks
lpseifert
2008-07-30, 09:14 PM
here's one I use, feel free to modify and use
;Label finish grade contour by LPS 2008
(defun c:lc ()
(vl-load-com)
(defun rtd (a) (/ (* a 180.0) pi))
(defun dxf(code elist)
(cdr (assoc code elist))
)
(setq th (getvar "textsize")
ts (getvar "textstyle")
cl (getvar "clayer")
os (getvar "osmode")
)
(setq ent (entsel "Pick contour to be labeled: ")
p1 (vlax-curve-getclosestpointto (car ent) (cadr ent) )
ed (entget (car ent))
);setq
(if (= (caddr p1) 0.0)
(alert "Contour needs an elevation!!!")
(progn
(if (= (DXF 0 ED) "LWPOLYLINE")
(SETQ txt1 (rtos (DXF 38 ED)2 0))
(SETQ txt1 (rtos (CADDR (DXF 10 ED))2 0))
)
(setvar "osmode" 512)
(setq a1 (rtd(getangle "Specify angle of label: " p1)))
(setvar "clayer" "FG-CONT-ELEV")
(command "text" "s" "SIMPLEX" "M" P1 (* 0.1(GETVAR "DIMSCALE")) a1 txt1)
(setvar "textsize" th)
(setvar "textstyle" ts)
(setvar "clayer" cl)
(setvar "osmode" os)
(PRINC)
);progn
);if
)
jwissler
2008-07-30, 09:22 PM
Thanks for the program, it does start, but as soon as i pick a contour it gives me an error
Pick contour to be labeled: ; error: no function definition: DXF
Command:
unfortunately, i am not very good with the programming language and i am not sure want to change, and i did make sure it was a polyline with an elevation.
Thanks
Thanks for the program, it does start, but as soon as i pick a contour it gives me an error
Pick contour to be labeled: ; error: no function definition: DXF
Command:
unfortunately, i am not very good with the programming language and i am not sure want to change, and i did make sure it was a polyline with an elevation.
Thanks
If I had to guess, this might be the function you are missing.
(defun DXF (ELEMENT ENTITY /) (cdr (assoc ELEMENT ENTITY)))
lpseifert
2008-07-31, 12:27 AM
Oops, I have the DXF function in my acaddoc.lsp file and forgot to add it to the code I posted. Try it now...
Opie had it right...
I might add that the above code assumes there is a layer named FG-CONT-ELEV and a text style named SIMPLEX with a height of 0. Adjust to your needs.
MattAnderson
2008-07-31, 03:16 AM
You could just come up with a General Line Segment Label that labels the Z elevation of the Start point and be sure the label snaps to the middle of the line and masks the contour.
That is what we use for those situations.
Matthew Anderson, PE
Joseph A Schudt & Associates
Tom Beauford
2008-08-02, 11:47 PM
This works for all the contours I encounter: ; Annotate a Contour Line
; BY: Tom Beauford - 7/11/2005
; Tombu@LeonCountyFL.gov
; LEON COUNTY PUBLIC WORKS SURVEY & R/W SECTION
; (load "ContourAnnotate.lsp") ContourAnnotate
;=============================================================
(defun c:ContourAnnotate (/ mspace om osz e ent pt tblname Rot str mtextobj ent el)
(setq mspace (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))
om (getvar "osmode")
osz (getvar "osnapz")
)
(setvar "osnapz" 0)
(setvar "osmode" 512)
(setq pt (getpoint"\nSelect point on Contour Line: ")
e (nentselp pt)
ent (car e)
pt (cadr e)
tblname (car(ade_odgettables ent))
)
(setvar "osmode" 0)
(setq Rot (getangle pt "\nPick or Enter angle..." )
str (rtos (caddr pt) 2 0))
(ade_errsetlevel 2)
(if(ade_odgettables ent)
(cond
((ade_odgetfield ent (car(ade_odgettables ent)) "ELEV" 0)
(setq str (itoa(ade_odgetfield ent (car(ade_odgettables ent)) "ELEV" 0))))
((ade_odgetfield ent (ade_odgettables ent) "ELEVATION" 0)
(setq str (itoa(ade_odgetfield ent (ade_odgettables ent) "ELEVATION" 0))))
)
)
(ade_errsetlevel 0)
(princ "\nElev = ")
(princ str)
(setq mtextobj (vla-addMText mspace (vlax-3d-point pt) 0.0 str))
(vla-put-attachmentPoint mtextobj acAttachmentPointMiddleCenter)
(vla-put-insertionPoint mtextobj (vlax-3d-point pt))
(vla-put-Rotation mtextobj Rot)
(vla-put-Color mtextobj 7)
(vla-put-backgroundfill mtextobj :vlax-true); mask on with background color
(setq el (entget (vlax-vla-object->ename mtextobj)))
(setq el (subst (cons 45 1.15) (assoc 45 el) el)) ;Set MaskSize 1.15 × TextSize
(entmod el)
(setvar "osmode" om)
(setvar "osnapz" osz)
(princ)
)
It works on ESRI contours brought in with Map as well.
marijan.marsic
2009-02-26, 10:46 AM
If I had to guess, this might be the function you are missing.
(defun DXF (ELEMENT ENTITY /) (cdr (assoc ELEMENT ENTITY)))
;Label finish grade contour by LPS 2008
(defun DXF (ELEMENT ENTITY /) (cdr (assoc ELEMENT ENTITY)))
(defun c:lc ()
(vl-load-com)
(defun rtd (a) (/ (* a 180.0) pi))
(defun dxf(code elist)
(cdr (assoc code elist))
)
(setq th (getvar "textsize")
ts (getvar "textstyle")
cl (getvar "clayer")
os (getvar "osmode")
)
(setq ent (entsel "Pick contour to be labeled: ")
p1 (vlax-curve-getclosestpointto (car ent) (cadr ent) )
ed (entget (car ent))
);setq
(if (= (caddr p1) 0.0)
(alert "Contour needs an elevation!!!")
(progn
(if (= (DXF 0 ED) "LWPOLYLINE")
(SETQ txt1 (rtos (DXF 38 ED)2 0))
(SETQ txt1 (rtos (CADDR (DXF 10 ED))2 0))
)
(setvar "osmode" 512)
(setq a1 (rtd(getangle "Specify angle of label: " p1)))
(setvar "clayer" "FG-CONT-ELEV")
(command "text" "s" "SIMPLEX" "M" P1 (* 0.1(GETVAR "DIMSCALE")) a1 txt1)
(setvar "textsize" th)
(setvar "textstyle" ts)
(setvar "clayer" cl)
(setvar "osmode" os)
(PRINC)
);progn
);if
)
---------------------------------------------------------------------------
There is a new error:
"command: LC Pick contour to be labeled: Specify angle of label: 30
*Cancel*
AutoCAD variable setting rejected: "clayer" "FG-CONT-ELEV" "
marijan.marsic
2009-02-26, 11:00 AM
;Label finish grade contour by LPS 2008
(defun DXF (ELEMENT ENTITY /) (cdr (assoc ELEMENT ENTITY)))
(defun c:lc ()
(vl-load-com)
(defun rtd (a) (/ (* a 180.0) pi))
(defun dxf(code elist)
(cdr (assoc code elist))
)
(setq th (getvar "textsize")
ts (getvar "textstyle")
cl (getvar "clayer")
os (getvar "osmode")
)
(setq ent (entsel "Pick contour to be labeled: ")
p1 (vlax-curve-getclosestpointto (car ent) (cadr ent) )
ed (entget (car ent))
);setq
(if (= (caddr p1) 0.0)
(alert "Contour needs an elevation!!!")
(progn
(if (= (DXF 0 ED) "LWPOLYLINE")
(SETQ txt1 (rtos (DXF 38 ED)2 0))
(SETQ txt1 (rtos (CADDR (DXF 10 ED))2 0))
)
(setvar "osmode" 512)
(setq a1 (rtd(getangle "Specify angle of label: " p1)))
(setvar "clayer" "FG-CONT-ELEV")
(command "text" "s" "SIMPLEX" "M" P1 (* 0.1(GETVAR "DIMSCALE")) a1 txt1)
(setvar "textsize" th)
(setvar "textstyle" ts)
(setvar "clayer" cl)
(setvar "osmode" os)
(PRINC)
);progn
);if
)
---------------------------------------------------------------------------
There is a new error:
"command: LC Pick contour to be labeled: Specify angle of label: 30
*Cancel*
AutoCAD variable setting rejected: "clayer" "FG-CONT-ELEV" "
------------------------------------------------------------------------------------------------------------------------
By replacing this two rows;
(setvar "clayer" "KOTIRANJE")
(command "text" "s" "standard" "M" P1 (* 0.1(GETVAR "DIMSCALE")) a1 txt1)
IT works!!
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.