我那个代码,为了减少块内对齐点的拾取,直接代码读出了块的两个圆心,因为我的图是4个圆,而你的图是2个圆,所以代码出错了,
对应你这个图,代码这样就行了,看里面的注释。
(defun c:tt()
(if (and (setq e (car (xdrx_entsel "\n拾取曲线<退出>:" '((0 . "*line,arc,ellipse,circle")))))
(setq e1 (car (xdrx_entsel "\n拾取块<退出>:" '((0 . "insert")))))
)
(progn
(xdrx_begin)
(setq ents (xdrx_block_getentities e1 '((0 . "circle")))
mat (xdrx_matrix_block2wcs e1)
p1 (xdrx_getpropertyvalue (car ents) "center") ;;两个块内圆的圆心,P1,P2
p2 (xdrx_getpropertyvalue (cadr ents) "center")
p1 (xdrx_point_transform p1 mat)
p2 (xdrx_point_transform p2 mat)
)
(setq spt (xdrx_getpropertyvalue e "startpoint")
ept (xdrx_getpropertyvalue e "endpoint")
)
(xdrx_document_setprec 1e-3 1)
(while (setq ept1 (xd::curve:getpointatchord e spt ept (distance p1 p2)))
(xdrx_entity_copy e1)
(xdrx_entity_align (entlast) p1 p2 spt ept1)
(setq spt ept1)
)
(xdrx_end)
)
)
(princ)
)
如果要更通用,那就得多两次交互去拾取块内的两个对齐点,更通用的版本下面代码:
(defun c:tt ()
(if (and
(setq e (car (xdrx_entsel "\n拾取曲线<退出>:" '((0 . "*line,arc,ellipse,circle")))))
(setq e1 (car (xdrx_entsel "\n拾取块<退出>:" '((0 . "insert")))))
(setq p1 (getpoint "\n图块内第一点<退出>:"))
(setq p2 (getpoint "\n图块内对齐第二点<退出>"))
)
(progn
(xdrx_begin)
(setq spt (xdrx_getpropertyvalue e "startpoint")
ept (xdrx_getpropertyvalue e "endpoint")
)
(xdrx_document_setprec 1e-3 1)
(while (setq ept1 (xd::curve:getpointatchord e spt ept
(distance p1 p2)
)
)
(xdrx_entity_copy e1)
(xdrx_entity_align (entlast) p1 p2 spt ept1)
(setq spt ept1)
)
(xdrx_end)
)
)
(princ)
)
你试试,如果成,做个动画上来看看。用API写程序代码很短,你可以试试对着手册,看每个函数的作用,自己修改代码适合自己的使用。最新的晓东通用LISP函数库,XD::Curve:GetPointAtChord已经包含在里面了,你加载了函数库就能用上面代码了。
|