笑傲江湖696594 发表于 2015-11-2 12:40:21

关于多线段一键标注 除数为零的错误

   我在网上下载了一个多线段一键标注的lsp,但有些多线段可以标注,有些有显示除数为零的错误,请高手看看是不是哪里不对呀,麻烦帮助改一下。


(defun C:DXBZ ( / *error*_bak *error*_CH arc_cen arc_cen3d arc_stap 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 pl_direction
                   pt3_arc pt3_line repeat_no ss ss_after_explod x y
                   )
(princ "\n 请选择多线段: ")
(setq ss (ssget '((0 . "LWPOLYLINE") (100 . "AcDbPolyline"))));选择多线段
(setq dist_offset (getdist "\n输入标注偏移距离: "))
(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)))
)
(command "_.dimaligned" "" (list ent_xname L_MidP2D) pt3_line)
)
)
(setq i (1+ i))
)
(lj ss_after_explod)
(setq i_ss (1+ i_ss))
)

(command "_.undo" "E")

(setq *error* *error*_bak)
(var_should)

(princ)
(prin1)


;;;更改系统变量------
(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 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 offsetplineObj (car (vlax-safearray->list (vlax-variant-value (vla-offset plineObj 0.0001)))))
      (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
)
;;;出错系统变量恢复函数-----
(defun *error*_CH (msg)
(command)
(setq *error* *error*_bak)
(setvar "CMDECHO" 1)
(setvar "osmode" osm_old)
; (print msg)
)
(princ)




http://bbs.mjtd.com/xwb/images/bgimg/icon_logo.png 该贴已经同步到 笑傲江湖696594的微博
页: [1]
查看完整版本: 关于多线段一键标注 除数为零的错误