如何获取图元信息
LISP如何能获取所选图元的长和宽,以及所选线段的总长。并复制到粘贴板上,以便调用。谢谢。本帖最后由 htlaser 于 2022-3-7 12:01 编辑
按要求重修改:框选 长宽 是指啥比如圆 椭圆样条线等 entget(car(entsel))?:o 本帖最后由 htlaser 于 2022-3-2 18:12 编辑
[*];============================================================================================================================
(defun c:test (/ cp ent len plst txt txt2x0 x1 xx y0 y1 yy )
(vl-load-com)
(defun ZML-CLIP-SETSTRING (STR / HTML RESULT)
(and (= (type STR) 'STR)
(setq HTML (vlax-create-object "htmlfile"))
(setq RESULT (vlax-invoke (vlax-get(vlax-get HTML 'PARENTWINDOW) 'CLIPBOARDDATA )'SETDATA "Text" STR ))
(vlax-release-object HTML)))
(setq ent (car (entsel "\n请指定一条多段线")))
(setq len(vlax-curve-getdistatparam ent (vlax-curve-getendparam ent)))
(setq plst(mapcar 'cdr (vl-remove-if (function (lambda (e)(/= 10 (car e)))) (entget ent))))
(setq x0 (car (vl-sort (mapcar 'carplst) (function (lambda(e1 e2)(< e1 e2))))))
(setq X1 (car (vl-sort (mapcar 'carplst) (function (lambda(e1 e2)(> e1 e2))))))
(setq y0 (car (vl-sort (mapcar 'cadr plst) (function (lambda(e1 e2)(< e1 e2))))))
(setq y1 (car (vl-sort (mapcar 'cadr plst) (function (lambda(e1 e2)(> e1 e2))))))
(setq cp (mapcar '(lambda(x y) (/ (+ x y) 2.0)) (list x0 y0)(list x1 y1)))
(setq xx (rtos (- x1 x0)2 3))
(setq yy (rtos (- y1 y0)2 3))
(setq txt(strcat "线段总长="(rtoslen 2 3)"mm" "" "X="xx"mm" "" "Y="yy"mm" ))
(ZML-CLIP-SETSTRING txt)
(princ "\n ")
(setq txt2 (strcat"复制成功:" "线段总长="(rtoslen 2 3)"mm" "" "X="xx"mm" "" "Y="yy"mm" ))
(princ txt2)
(princ )
)
;============================================================================================================================
(defun c:test2 (/ ent len obj p1 p2 txt txt2 x y)
(vl-load-com)
(defun ZML-CLIP-SETSTRING (STR / HTML RESULT)
(and (= (type STR) 'STR)
(setq HTML (vlax-create-object "htmlfile"))
(setq RESULT (vlax-invoke (vlax-get(vlax-get HTML 'PARENTWINDOW) 'CLIPBOARDDATA )'SETDATA "Text" STR ))
(vlax-release-object HTML)))
(setq ent (car (entsel "\n请获取一个对象")))
(setq len(vlax-curve-getdistatparam ent (vlax-curve-getendparam ent)))
(setq obj (vlax-ename->vla-object ent))
(vla-GetBoundingBox obj 'p1 'p2 )
(setq p1 (vlax-safearray->list p1))
(setq p2 (vlax-safearray->list p2))
(setq X (rtos (abs (- (car p1)(carp2))) 2 3))
(setq Y (rtos (abs (- (cadr p1) (cadr p2))) 2 3))
(setq txt(strcat "线段总长="(rtoslen 2 3)"mm" "" "X="X"mm" "" "Y="Y"mm" ))
(ZML-CLIP-SETSTRING txt)
(princ "\n ")
(setq txt2 (strcat"复制成功:" "线段总长="(rtoslen 2 3)"mm" "" "X="X"mm" "" "Y="Y"mm" ))
(princ txt2)
(princ )
)
;============================================================================================================================
题目不清楚 搜动态信息查询 htlaser 发表于 2022-3-2 17:28
[*]
可能我没有说清楚,不是单选,要框选。附图如下。
很好的东西
学习 htlaser 发表于 2022-3-2 10:44
按要求重修改:框选
如果想把精度精确下个位,四舍五入。可能实现?还有就是想把总线长度放在 长宽的后面。
页:
[1]
2