本帖最后由 masterlong 于 2022-3-28 23:21 编辑
正在编一个略微有点复杂的程序
远远没有完工
其中某个片段感觉还有点意思
先单独摘出来共享一下
源码放二楼
;=============================
给多边形增加了对象反应器以后
发生奇怪的事情
框内图元随对象拉伸操作同步拉伸
谁能解释下?
------------------------------------------------------------
上面的问题目前无解
怀疑是CAD的BUG
现在只有一个曲线救国的办法
框内目标图元全部复制原件删除
- (defun c:tt()
- (if (setq ent (car (entsel))
- *ent2obj* vlax-Ename->Vla-Object
- *obj2ent* vlax-vla-object->ename
- *acad* (vlax-get-acad-object)
- )
- (setq dbpl_obj_Reactor (vlr-object-reactor (list (vlax-Ename->Vla-Object ent)) "" '((:vlr-modified . about_fw_xfs))))
- )
- )
- ;;对象反应器
- (defun about_fw_xfs( theobj reactor parameter-list )
- ;;是否已删除
- (if (*obj2ent* theobj)
- ;
- ;有个奇怪的现象,为啥框内图元会随着多边形的拉伸操作(STRETCH命令拉伸多边形的某一段),同步执行“拉伸” ?????????
- ;
- (progn
- (zoomsave)
- (setq theplent (*obj2ent* theobj))
- (setq box (entbox theplent))
- (zoomptlist box 1.5)
- (setq theplptlist (massoc 10 theplent))
- (setq ss (ssget "cp" theplptlist '((0 . "CIRCLE") (8 . "0") (62 . 3))))
- (if ss
- (princ (strcat "\n多边形内找到【 " (itoa (sslength ss)) " 】" ))
- (princ "\n多边形内找到【 0 】")
- )
- (zoomload)
- )
- )
- (princ)
- )
- ;999当前视窗save
- (defun zoomsave()
- (setq zoom*savelist (list (getvar "ctab") (vlax-3D-Point (trans (getvar "viewctr") 1 0)) (getvar "viewsize")))
- )
- ;999当前视窗load
- (defun zoomload()
- (if zoom*savelist
- (progn
- (setvar "ctab" (car zoom*savelist))
- (vla-ZoomCenter (vlax-get-acad-object) (trans (cadr zoom*savelist) 0 1) (caddr zoom*savelist))
- )
- )
- )
- ;;单个物体的最小(正交)包围框---------------------------------这个程序在遇到无法显示的图元时,还是会出错的,比如形。天正图元会不会也不支持,未测试
- (defun entbox ( ent / ll ur )
- (vla-getboundingbox (*ent2obj* ent) 'll 'ur)
- (mapcar 'vlax-safearray->list (list ll ur))
- )
- ;999以指定点表的包围框中心,缩放窗口——————主要用来保证后续可执行 (ssget 'CP/'WP ptlist)
- (defun zoomptlist( ptlist sc / box x midpo )
- (setq box (npt2box ptlist))
- (setq midpo (getmidpo box))
- (vla-zoomwindow *acad* (vlax-3d-point (car box)) (vlax-3d-point (cadr box)))
- (vla-ZoomScaled *acad* (/ 1.0 sc) 1)
- )
- ;999公共函数
- ;;求n个点的正交包围框
- ;;(setq npt (list p1 p2 p3 p4 ... ))
- (defun npt2box( npt )
- (list
- (apply 'mapcar (cons 'min npt))
- (apply 'mapcar (cons 'max npt))
- )
- )
- ;999公共函数
- ;;求点对中点
- (defun getmidpo( pts / P1 P2 X Y )
- (setq p1 (car pts) p2 (cadr pts))
- (if (= (length p1) (length p2))
- nil
- (setq p1 (list (car p1) (cadr p1))
- p2 (list (car p2) (cadr p2))
- )
- )
- (mapcar '(lambda (X Y) (/ (+ X Y) 2.0)) P1 P2)
- )
|