求计算重量的vlisp或 dvb,各位老师帮忙啊
www.dimcax.com
求计算重量的vlisp或 dvb,各位老师帮忙啊
在方框内,点下,就可以得到这个圆柱的重量,怎么实现???
大家看看我这个代码怎么优化,我不懂,自己写的,能用,可我觉得不可靠,不能判断是不是封闭正四边形,,,,汗^^^^^^!
(defun c:zl( / ax ay pt ss key xy ct vv dx1 dx2 dy1 dy2 dj txt cm os)
(setq ax nil ay nil) ;创建表(数组)
(command "-layer" "off" "*" "y" "")
(command "-layer" "on" "1轮廓实线层" "")
(command "-layer" "on" "0" "")
(command "-layer" "on" "排图层" "")
(command "-layer" "s" "排图层" "" "")
(setq cm (getvar "clayer"))
(setq os (getvar "osmode"))
(setvar "osmode" 0)
(while (setq pt (getpoint "\n选取点: "))
(command "-boundary" pt "")
(setq ss (entget(entlast)))
(setq i -1)
(setq key 10)
(foreach xy ss
(if (eq (car xy) key)
(progn
(setq pe (cdr xy))
(setq y (cadr pe))
(setq x (car pe))
(setq ax (cons x ax))
(setq ay (cons y ay))
)
)
)
)
(command "-layer" "on" "*" "")
(command "-layer" "off" "消隐层" "")
(setq s (ssget "x" (list (cons 8 "排图层"))))
(command "erase" s "")
(setq ax (reverse ax)) ;顺序取反
(setq ay (reverse ay));顺序取反
(setq ct 0)
(setq vv 0)
(repeat (fix (* (length ax) 0.25))
(setq dx1 (nth (* 4 ct) ax))
(setq dy1 (nth (* 4 ct) ay))
(setq dx2 (nth (+ 2 (* 4 ct)) ax))
(setq dy2 (nth (+ 2 (* 4 ct)) ay))
(setq dx (- dx1 dx2))
(setq dy (- dy1 dy2))
(setq vv (+ vv (* (* (* (* dy dy) pi) 0.25) dx)))
(setq ct (+ 1 ct))
)
(print vv);打印体积
(setq dj (*(* vv 7.85) 0.000001)) ;算重量
(setq txt (strcat "锻件重: " (rtos dj 2 3) "kg"))
(command "-layer" "s" "6文字层" "" )
(command "text" "j" "mc" (getpoint "\n选取点: ") "30" "0" txt);将重量写在图形上
(command "-layer" "s" cm "" )
(setvar "osmode" os)
;(command "-layer" "off" "排图层" "y" "");没有使用,使用该命令总是关不上该图层,不知道为什么,请高手解决
)