明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 810|回复: 0

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

[复制链接]
发表于 2015-11-2 16:54 | 显示全部楼层 |阅读模式
     我在网上下载了一个多线段一键标注的lsp,但有些多线段可以标注,有些有显示除数为零的错误,而且CAD本身的对象捕捉也会自动关闭,请高手看看是不是哪里不对呀,麻烦帮忙改一下。


(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)
  (princ "\n共有< ")
  (princ (sslength ss))
  (princ " >条多线段标注完成,请查看!")
  (princ "\n -->-->> 多线段一键标注程序,命令:DXBZ ")
  (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)




该贴已经同步到 笑傲江湖696594的微博
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-20 20:15 , Processed in 0.881140 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表