求在绘多义线的同时能在线附近上标注出整段线的长度(起点到终点的从长度)
本帖最后由 Gu_xl 于 2016-3-9 13:56 编辑求在绘多义线的同时能在线附近上标注出整段线的长度(起点到终点的从长度)
(defun C:DZ (/ *error*_bak *error*_ch ang0 arc_cen arc_cen3d arc_stap b dist_offset
ent_ss ent_xname entli_x i i_ss l_angle l_endp l_midp2d l_midp3d l_stap
list_l osm_old pt3_arc pt3_line repeat_no ss ss_after_explod sss x y
)
;;-----------------------------------------------------------------
;;;出错系统变量恢复函数-----
(defun *error*_CH (msg)
(command)
(setq *error* *error*_bak)
(setvar "CMDECHO" 1)
(setvar "osmode" osm_old)
; (print msg)
)
;;;更改系统变量------
(defun var_temp ()
(setvar "CMDECHO" 0)
(setvar "osmode" 0)
)
;;;恢复系统变量------
(defun var_should ()
(setvar "CMDECHO" 1)
(setvar "osmode" osm_old)
)
;;; ===角度转弧度===
(defun dtr (ang0)
(* ang0 (/ pi 180.0))
)
;;; 选择线,并转为多义线程序
(defun lj (sss / b)
(setvar "peditaccept" 1) ; 设置系统变量,避免区分直线和多段线.
(setq b sss)
(command "pedit" "m" b "" "j" "0" "")
(setvar "peditaccept" 0)
(prin1)
)
;| 判断POLYLINE顺时针或逆时针--------------------------------------------------------
(defun CH:plfx (ent_ss / ang direction fd offdis offobj offsetplineobj plineobj)
(if ent_ss
(progn
(setq plineObj (vlax-ename->vla-object ent_ss))
(setq fd (vlax-curve-getFirstDeriv plineObj 0.5))
(setq ang (atan (/ (cadr fd) (car fd))))
(setq offdis 1e-5)
(while (vl-catch-all-error-p
(setq offobj (vl-catch-all-apply 'vla-offset (list plineObj offdis)))
)
(setq offdis (* 10 offdis))
)
(setq offsetplineObj (car (vlax-safearray->list (vlax-variant-value offobj))))
(if (> (vla-get-length plineobj) (vla-get-length offsetplineobj))
(setq direction "clockwise")
(setq direction "anticlockwise")
)
(vla-delete offsetplineObj)
) ; progn
;(princ "\nNo object selected or object selected is not a polyline.")
) ; end_if
direction
)
|;;------------------------------------------------------------------------------------
;;-----------------------------------------------------------------
(princ "\n 请选择多线段: ")
(setq ss (ssget '((0 . "LWPOLYLINE") (100 . "AcDbPolyline"))));选择多线段
;(setq dist_offset (getdist "\n输入标注偏移距离: "))
(setq dist_offset 50)
(command "_.undo" "BE")
(setq *error*_bak *error*)
(setq *error* *error*_CH)
(setq osm_old (getvar "osmode"));获得原标注系统变量参数
(var_temp);更改系统变量
(graphscr)
(setq i_ss 0)
(repeat (sslength ss)
(setq ent_ss (ssname ss i_ss));获得多线图元名
;(setq pl_direction (CH:plfx ent_ss));判断多线方向
(command "_.EXPLODE" ent_ss "");炸开多线图元
(setq list_l nil)
(setq ss_after_explod (ssget "P"));获得炸开后线段的选择集
(setq repeat_No (sslength ss_after_explod)
i 0)
(repeat repeat_No
(setq ent_xname (ssname ss_after_explod i))
(setq entLi_x (entget ent_xname))
(if (= (cdr (assoc 0 entLi_x)) "ARC")
(progn
(setq arc_cen3D (cdr (assoc 10 entLi_x));弧形圆心坐标3D
arc_cen (list (car arc_cen3D) (cadr arc_cen3D));弧形圆心坐标2D
pt3_arc (polar arc_cen (+ (cdr (assoc 50 entLi_x)) 0.1) (+ dist_offset (cdr (assoc 40 entLi_x))));标注放置点
arc_StaP (polar arc_cen (cdr (assoc 50 entLi_x)) (cdr (assoc 40 entLi_x)));圆弧起点坐标
)
(command "_.DIMARC" (list ent_xname arc_StaP) pt3_arc)
)
(progn
(setq L_StaP (cdr (assoc 10 entLi_x));线段起点坐标
L_EndP (cdr (assoc 11 entLi_x));线段终点坐标
L_MidP3D (mapcar '(lambda (x y) (* (+ x y) 0.5)) L_StaP L_EndP);线段中心点3D
L_MidP2D (mapcar '+ '(0 0) L_MidP3D);线段中心点2D
L_angle (angle L_StaP L_EndP);线段角度
)
; (if (= pl_direction "clockwise")
; (setq pt3_line (polar L_MidP2D (+ L_angle (dtr 90)) dist_offset));标注放置点
; (setq pt3_line (polar L_MidP2D (+ L_angle (dtr 90)) (- dist_offset)))
; )
(setq pt3_line (polar L_MidP2D (+ L_angle (dtr 90)) dist_offset));标注放置点
;(command "_.dimaligned" "" (list ent_xname L_MidP2D) pt3_line)
;(command ".line"L_StaPL_EndP "")
(command ".TEXT" "j" "m" pt3_line "40" "0" (STRCAT (rtos i 2 0) "K"))
)
)
(setq i (1+ i))
)
(lj ss_after_explod)
(setq i_ss (1+ i_ss))
)
(command "_.undo" "E")
(setq *error* *error*_bak)
(var_should)
(princ)
(princ "\n共有< ")
(princ (sslength ss))
(princ " >条多线段标注完成,请查看!")
(princ)
)
页:
[1]