土木在线论坛 \ 电气工程 \ 供配电技术 \ 求CAD加载程序

求CAD加载程序

发布于:2011-03-11 16:55:11 来自:电气工程/供配电技术 [复制转发]
听朋友说有种加载程序,在CAD花多段线,可以自动计算出画了多长?
谁有?跪求
QQ231909174
  • skitering888
    skitering888 沙发
    ;;;功能:计算线段和多义线的长度,快捷命令:CD
    (defun c:CD( / a n index0 tuyname)
    (setq a (ssget))
    (setq n (sslength a)) ;求出选择集中的图元数目
    (setq index0 0) ;设置计数器
    (setq s 0)
    (repeat n ;对后面的表达式进行N次计算
    (setq tuyname (ssname a index0));返回选择集中由序号指定的图元名
    (setq index0 (+ index0 1)) ;计数器加一
    (setq ent1 (entget tuyname))
    (setq et (length ent1))
    (setq et1 et)
    (setq index1 0)

    (setq test 0)
    (setq x2 0)
    (setq y2 0)
    (setq x1 0 y1 0)
    (setq s0 0)
    (repeat 2
    (setq xy (nth index1 ent1))
    ;计算line线长
    (if (= (cdr xy) "LINE")
    (progn
    (setq index2 0)
    (repeat et1
    (setq xy (nth index2 ent1))
    (if (= (car xy) 10)
    (progn
    (setq x1 (nth 1 xy))
    (setq y1 (nth 2 xy))
    )
    )
    (if (= (car xy) 11)
    (progn
    (setq x2 (nth 1 xy))
    (setq y2 (nth 2 xy))
    )
    )
    (setq index2 (+ index2 1))
    )
    (setq s0 (sqrt (+(* (- x2 x1) (- x2 x1)) (* (- y2 y1) (- y2 y1)))))
    )
    )
    ;line线计算结束
    ;计算"LWPOLYLINE"线长
    (if (= (cdr xy) "LWPOLYLINE")
    (progn
    (setq index2 0)
    (repeat et1
    (setq xy (nth index2 ent1))
    (if (= (car xy) 10)
    (if (= test 1)
    (progn
    (setq x2 x1)
    (setq y2 y1)
    (setq x1 (nth 1 xy))
    (setq y1 (nth 2 xy))
    (setq s0 (+ s0 (sqrt (+(* (- x2 x1) (- x2 x1)) (* (- y2 y1) (- y2 y1))))))
    )
    )
    )
    (if (= (car xy) 10)
    (if (= test 0)
    (progn
    (setq x1 (nth 1 xy))
    (setq y1 (nth 2 xy))
    (setq test 1)
    )
    )
    )
    (setq index2 (+ index2 1))
    )
    )
    )
    ;计算"LWPOLYLINE"线结束
    (setq index1 (+ index1 1))
    )
    (print s0)
    (setq s (+ s s0))
    )
    (print )
    (princ "总长度:")
    (princ s)
    (setq a nil)
    (prin1)
    )

    把以上代码存为.lsp文件,然后用AP进行加载,运行时候直接输入“CD”即可。
    2011-03-19 14:01:19

    回复 举报
    赞同0
这个家伙什么也没有留下。。。

供配电技术

返回版块

97.87 万条内容 · 2093 人订阅

猜你喜欢

阅读下一篇

急!关于两台电容柜并联问题

一台变压器使用了两台电容柜,在两个地方就近补偿,由于是裸线进线分不出A,B,C三相。请问各位进入电容柜三相不相同对用电有安全影响不?谢谢!!!!急盼回复 小弟在线等!!!!!!!!!!

回帖成功

经验值 +10