除了COMMAND命令有没有更快批量生成直线的命令
大家好!我的日常工作中用到的生成直线(非多段线)命令较多,之前一直用command创建直线,后面了解到entmake创建直线,但只有起点和终点,我有个疑问,就是有没有什么好方法比command创建直线速度更快,或者entmake能不能一下创建多条直线,或者有其他的办法优化创建直线的命令
[*](command "line" pt1 p1 p2 p3 p4 p5 p6 p7 p8 p9 "c")
本帖最后由 xj6019 于 2024-3-11 11:29 编辑
;; [函数名称]:MK-line
;; [功 能]:列表数据绘制直线
;; [参 数]: 点列表
;; [示 意]: (MK-line LST)
(defun MK-line (S / m-line)
(defun M-line (p1 p2)
(entmakex (list '(0 . "line") (cons 10 p1) (cons 11 p2)))
)
(mapcar
(function
(lambda(p1 p2)
(M-line p1 p2)
)
)
S (cdr s)
)
(M-line (car s) (last s))
)
;测试例子1
(defun C:NM (/ lst)
(setq lst nil)
(repeat 5
(setq lst(cons(getpoint)lst)) ;组建点列表
)
(MK-line lst);列表绘制直线
(princ)
)
;测试例子2
;(MK-line (list pt1 p1 p2 p3 p4 p5 p6 p7 p8 p9))
;;;lst 点表ucs
;;; oi闭合否
(defun tt(lst oi)
(if oi
(setq lst (reverse (cons (car lst) (reverse lst)))))
(mapcar
'(lambda (x y)
(entmakex (list (cons 0 "line")
(cons 10 (trans x 1 0))
(cons 11 (trans y 1 0)))))
lst
(cdr lst)))
;;;test
(defun c:test (/ lst1 lst2 pt1)
(setvar "pdmode" 35)
(setq pt1 (getpoint "\nget point:"))
(setq lst1 (list (entmakex (list (cons 0 "point")
(cons 10 (trans pt1 1 0)))))
lst2 (cons pt1 lst2))
(while (setq pt1 (getpoint pt1 "\nget next point:"))
(setq lst1
(cons
(entmakex (list (cons 0 "point")
(cons 10 (trans pt1 1 0))))
lst1)
lst2 (cons pt1 lst2)))
(tt (reverse lst2) nil)
(foreach n lst1 (entdel n))
(setvar "pdmode" 0)) command可以这样:
(command "line")(mapcar (function (lambda (x) (command x))) (list pt1 p1 p2 p3 p4 p5 p6 p7 p8 p9))(command "c") (setq a1 (car lst)) ;;;取出第一个点
(while (and (car lst)(cadr lst))
(entmake (list '(0. "line") (cons 10 (car lst))(cons 11 (cadr lst)))
(setq lst (cdr lst))
)
;;;;
(if c (entmake (list '(0. "line") (cons 10 (car lst))(cons 11 a1))) ;;;假如需要闭合 (defun c:tt (/ pt0 pt1 pt2 tst n)
(setvar "cmdecho" 0)
(setq tst t
pt1 (getpoint "\n指定第一个点:")
pt0 pt1
n 0
)
(while (and
pt1
tst
)
(initget "C")
(if (> n 1)
(setq pt2 (getpoint pt1 "\n指定下一点或 [闭合(C)/放弃(U)]:"))
(setq pt2 (getpoint pt1 "\n指定下一点或 [放弃(U)]:"))
)
(cond
((or
(= pt2 "C")
(= pt2 "c")
)
(if (> n 1)
(entmake (list '(0 . "LINE") (cons 10 (trans pt1 1 0)) (cons 11 (trans pt0 1 0))))
)
(setq pt2 nil)
)
)
(if pt2
(progn
(entmake (list '(0 . "LINE") (cons 10 (trans pt1 1 0)) (cons 11 (trans pt2 1 0))))
(setq pt1 pt2)
)
(setq tst nil)
)
(setq n (1+ n))
)
(setvar "cmdecho" 1)
(princ)
)
搞一大堆,还不如command (defun MK-line (ptn / m-line)
(defun M-line (a b) (entmakex (list '(0 . "line") (cons 10 a) (cons 11 b))))
(mapcar 'M-line (cons (last ptn) ptn) ptn)
)
页:
[1]