用autolisp写一个插件,可以统计选中直线的总长度
时间: 2023-05-19 15:06:08 浏览: 106
您好,以下是用 AutoLISP 编写的插件,可以统计选中直线的总长度:
(defun c:line_length (/ ss total_length ent)
(setq ss (ssget))
(setq total_length 0.0)
(repeat (setq ent (sslength ss))
(setq ent (ssname ss (setq ent (1- ent))))
(if (= "LINE" (cdr (assoc 0 (entget ent))))
(setq total_length (+ total_length (distance (cdr (assoc 10 (entget ent))) (cdr (assoc 11 (entget ent)))))))
(princ (strcat "\nTotal length of selected lines: " (rtos total_length)))
(princ)
)
请注意,此插件只能统计选中的直线的长度,如果选中的图形中包含其他类型的实体,则会被忽略。
相关问题
用autolisp写一个画圆程序
好的,以下是用AutoLISP语言编写画圆程序的代码:
(defun c:circle (/ center radius)
(setq center (getpoint "\nEnter center point: "))
(setq radius (getdist "\nEnter radius length: "))
(command "circle" center radius)
(princ)
)
这段代码定义了一个名为c:circle的AutoCAD命令,调用该命令后,程序会提示用户输入圆心坐标和半径长度,最后在AutoCAD中画出一个圆形。
用autolisp写一个画轴承的程序
以下是一个简单的AutoLISP程序,可以画一个基本的轴承模型:
```
(defun C:DRAW-BEARING ()
(setq dia (getreal "\nEnter the diameter of the bearing: "))
(initget (+ 2 4 16))
(setq shape (getkword "\nEnter the shape of the bearing - Round, Square, or Hex: "))
(setq height (getreal "\nEnter the height of the bearing: "))
(command "_.circle" "_non" (list 0 0) (/ dia 2))
(if (= shape "Round")
(progn
(command "_.circle" "_non" (list 0 0) (/ dia 4))
(command "_.circle" "_non" (list 0 0) (/ (* dia 3) 8))
(command "_.circle" "_non" (list 0 0) (/ dia 8)))
(if (= shape "Square")
(progn
(command "_.rectangle" "_non" (list (- (/ dia 4)) (- (/ dia 4))) (list (/ dia 4) (/ dia 4)))
(command "_.rectangle" "_non" (list (- (/ (* dia 3) 8)) (- (/ (* dia 3) 8))) (list (/ (* dia 3) 8) (/ (* dia 3) 8)))
(command "_.rectangle" "_non" (list (- (/ dia 8)) (- (/ dia 8))) (list (/ dia 8) (/ dia 8))))
(if (= shape "Hex")
(progn
(setq h (/ (* dia (sqrt 3)) 6))
(command "_.pline" "_non" (list (- (/ dia 4)) h) (list (- (/ dia 4)) (- h)) (list 0 (- (/ dia 2))) (list (/ dia 4) (- h)) (list (/ dia 4) h) (list 0 (/ dia 2)) (list (- (/ dia 4)) h))
(setq h (/ (* dia (sqrt 3)) 24))
(command "_.pline" "_non" (list (- (/ (* dia 3) 8)) h) (list (- (/ (* dia 3) 8)) (- h)) (list 0 (- (/ dia 4))) (list (/ (* dia 3) 8) (- h)) (list (/ (* dia 3) 8) h) (list 0 (/ dia 4)) (list (- (/ (* dia 3) 8)) h))
(setq h (/ (* dia (sqrt 3)) 48))
(command "_.pline" "_non" (list (- (/ dia 8)) h) (list (- (/ dia 8)) (- h)) (list 0 (- (/ dia 16))) (list (/ dia 8) (- h)) (list (/ dia 8) h) (list 0 (/ dia 16)) (list (- (/ dia 8)) h)))))))
```
运行这个程序后,程序会提示用户输入轴承的直径、形状和高度。根据用户输入的参数,程序将绘制一个基本的轴承模型。
请注意,这只是一个简单的程序,可能需要根据具体需求进行修改和调整。