- 积分
- 29080
- 明经币
- 个
- 注册时间
- 2013-1-25
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 尘缘一生 于 2024-7-1 09:57 编辑
新开一贴,对于这个问题,希望在本帖要解决了它,
什么问题呢?那就是,grread下支持扑捉象限点,这个问题
请大家移步先看技术帖子,再来进一步的研究...
顾版的
http://bbs.mjtd.com/forum.php?mo ... 91&highlight=grread
廊大师的
http://bbs.mjtd.com/forum.php?mo ... 90&highlight=grread
下面代码,是我今上午改写的,尝试一下,还不完美,
- ;;grread图元捕捉子函数-----(一级)------有缺憾,会闪烁
- ;;name为移动的图元、选择集,pt为光标点
- ;;有捕捉点则返回捕捉点,无返回光标点
- (defun slosnappt (name pt / cl osmo d h k lst nearpt p0 p00 p1 p2 p3 p4 p5 ptx pty x newe)
- (redraw)
- (if (< (getvar "OSMODE") 16384) ;;打开捕捉
- (progn
- (cond
- ((= (type name) 'ENAME) (entdel name)) ;图元先删除
- ((= (type name) 'PICKSET) ;选择集
- (sl-sel-redrawsel name 2) ;先隐藏
- )
- )
- (setq
- p1 nil p2 nil
- cl (vla-get-autosnapmarkercolor (vla-get-drafting (vla-get-preferences *Acad*)))
- h (p2uu 1.0) d (getvar "PICKBOX")
- lst (list (* d h) (* (- d 0.5) h) (* (+ d 0.5) h)) k (* 30.0 d h)
- p1 (cadr (grread 5))
- )
- ;下面三行,此时如果扑捉到实体,取得它中心p2
- (if (setq newe (car (nentselp pt)))
- (setq p2 (e-mid newe))
- )
- ;;这是第一步,取得扑捉点
- (if (setq p0 (osnap pt "_NEA,_MID,_END,_INT,_CEN,_NOD,_QUA,_INS,_PER,_TAN,_APP,_EXT,_PAR"))
- (setq osmo 1 nearpt p0)
- )
- ;;如果是NEA 只不过是判定osmo罢了吗?值得进行下去if,如果能模拟到和CAD一样丝滑,建议osmo仅仅一个好了,那就是osmo=1 ,画个矩形
- (if (and (setq p0 (osnap pt "_NEA")) (equal nearpt p0 k))
- (setq osmo 2 nearpt p0)
- )
- (if (and (setq p0 (osnap pt "_MID")) (equal nearpt p0 k))
- (setq osmo 3 nearpt p0)
- )
- (if (and (setq p0 (osnap pt "_INT")) (equal nearpt p0 k))
- (setq osmo 4 nearpt p0)
- )
- ;;下面三句吗,我尝试给于象限点p2,并设为OSMO=4,画交叉矢量线,可以是可以,但是操作不如CAD本身丝滑
- (if (and p2 nearpt (not (equal nearpt p2 k)))
- (setq osmo 4 nearpt p2)
- )
- (cond
- ((= (type name) 'ENAME) (entdel name)) ;图元恢复
- ((= (type name) 'PICKSET) ;选择集
- (sl-sel-redrawsel name 1) ;恢复显示
- )
- )
- (if nearpt
- (progn
- (setq ptx (car nearpt) pty (cadr nearpt))
- (while lst
- (setq x (car lst) p1 (list (- ptx x) (- pty x)) p2 (list (+ ptx x) (- pty x))
- p3 (list (+ ptx x) (+ pty x)) p4 (list (- ptx x) (+ pty x))
- p5 (list ptx (+ pty x))
- )
- (cond
- ((= osmo 1) (grvecs (list cl p1 p2 p2 p3 p3 p4 p4 p1))) ;正方形
- ((= osmo 2) (grvecs (list cl p1 p2 p2 p4 p3 p4 p3 p1))) ;俩三角
- ((= osmo 3) (grvecs (list cl p1 p2 p2 p5 p5 p1))) ;三角
- ((= osmo 4) (grvecs (list cl p1 p3 cl p2 p4))) ;交叉
- )
- (setq lst (cdr lst))
- )
- (setq pt nearpt)
- )
- )
- )
- )
- pt
- )
下面为了大家能更好的解决这个问题,贴上另一种优秀代码,还没来得及尝试扑捉象限点的改写
- ;;重画选择集中的对象-----(一级)-----
- ;;Sel为选择集或图元名; mode为方式码
- ;;mode 1 在屏幕重画该选择集对象
- ;;mode 2 隐藏该选择集对象
- ;;mode 3 <醒目显示> 该选择集对象
- ;;mode 4 取消<醒目显示>该选择集对象
- (defun sl-sel-redrawsel (sel mode / n)
- (if sel
- (cond
- ((= 'PICKSET (type sel))
- (repeat (setq n (sslength sel))
- (redraw (ssname sel (setq n (1- n))) mode)
- )
- )
- ((= 'ENAME (type sel))
- (redraw sel mode)
- )
- )
- )
- t
- )
- ;;grread图元捕捉子函数-----(一级)------
- ;;name为移动的图元、选择集,pt为光标点
- ;;有捕捉点则返回捕捉点,无返回光标点
- (defun slosnappt (name pt / p mode osmod osmode size k)
- (defun sldectobin (n m / c f) ;;十进制转二进制
- (setq f (if (< n 0) 1 0) n (abs n))
- (while (> (setq c (cons (rem n 2) c) n (* n 0.5)) 0))
- (while (< (length c) (1- m)) (setq c (cons 0 c)))
- (cons f c)
- )
- ;;------------------
- (defun sldrawvecs (pt vecs size cl / xdir)
- (setq xdir (getvar 'ucsxdir)
- vecs (mapcar '(lambda (x) (mapcar '(lambda (a) (mapcar '+ pt (mapcar '* (setq a (trans a 0 xdir) a (list (caddr a) (car a))) (list size size)))) x)) vecs)
- )
- (grvecs (apply 'append (mapcar 'cons (mapcar (function (lambda (x) cl)) vecs) vecs)))
- )
- ;;----------------
- (if (< (getvar "OSMODE") 16384) ;;打开捕捉
- (progn
- (if name (progn (sl-sel-redrawsel name 2) (setq k t))) ;隐藏
- (if (setq
- osmod '("_NEA," "_QUA," "_END," "_MID," "_CEN," "_NOD," "_INT," "_INS," "_PER," "_TAN," "_APP," "_EXT," "_PAR")
- osmode (reverse (sldectobin (getvar 'osmode) 1))
- size (* (/ (getvar "VIEWSIZE") (cadr (getvar "SCREENSIZE"))) (getvar "PICKBOX"))
- p (osnap pt (apply 'strcat (mapcar '(lambda (x y) (if (zerop x) "" y)) osmode osmod)))
- mode (cdr (assoc (if p
- (vl-some '(lambda (x) (if (equal p (cdr x) 1e-8) (car x)))
- (vl-remove 'nil (mapcar '(lambda (x y / p) (if (zerop x) nil (if (setq p (osnap pt y)) (cons y p)))) osmode osmod)))
- )
- '(("_END," ((-1 1)(-1 -1))((-1 -1)(1 -1))((1 -1) (1 1))((1 1) (-1 1)))
- ("_MID," ((0 1.414) (-1.225 -0.707)) ((-1.225 -0.707)(1.225 -0.707))((1.225 -0.707) (0 1.414)))
- ("_CEN," ((0 1) (-0.707 0.707))((-0.707 0.707)(-1 0))((-1 0) (-0.707 -0.707))((-0.707 -0.707)(0 -1))
- ((0 -1)(0.707 -0.707))((0.707 -0.707)(1 0)) ((1 0) (0.707 0.707))((0.707 0.707) (0 1)))
- ("_NOD," ((0 1) (-0.707 0.707))((-0.707 0.707)(-1 0))((-1 0)(-0.707 -0.707))((-0.707 -0.707)(0 -1))((0 -1)(0.707 -0.707))
- ((0.707 -0.707)(1 0))((1 0)(0.707 0.707))((0.707 0.707)(0 1))((-1 1)(1 -1))((-1 -1)(1 1)))
- ("_QUA," ((0 1.414)(-1.414 0))((-1.414 0)(0 -1.414))((0 -1.414)(1.414 0))((1.414 0)(0 1.414)))
- ("_INT," ((-1 1)(1 -1))((-1 -1)(1 1))((1 0.859)(-0.859 -1))((-1 0.859)(0.859 -1))((0.859 1)(-1 -0.859))((-0.859 1)(1 -0.859)))
- ("_INS," ((-1 1)(-1 -0.1))((-1 -0.1)(0 -0.1))((0 -0.1)(0 -1.0))((0 -1.0)(1 -1))
- ((1 -1)(1 0.1))((1 0.1)(0 0.1))((0 0.1) (0 1.0))((0 1.0)(-1 1)))
- ("_PER," ((-1 1)(-1 -1))((-1 -1)(1 -1))((0 -1)(0 0))((0 0)(-1 0)))
- ("_TAN," ((0 1)(-0.707 0.707))((-0.707 0.707)(-1 0))((-1 0)(-0.707 -0.707))((-0.707 -0.707)(0 -1))
- ((0 -1)(0.707 -0.707))((0.707 -0.707)(1 0))((1 0)(0.707 0.707))((0.707 0.707)(0 1))((1 1)(-1 1)))
- ("_NEA," ((-1 1)(1 -1))((1 -1)(-1 -1))((-1 -1)(1 1))((1 1)(-1 1)))
- ("_APP," ((-1 1)(-1 -1))((-1 -1)(1 -1))((1 -1)(1 1))((1 1)(-1 1))((-1 1)(1 -1))((-1 -1)(1 1)))
- ("_EXT," ((0.1 0)(0.13 0))((0.2 0)(0.23 0))((0.3 0)(0.33 0)))
- ("_PAR" ((0 1)(-1 -1))((1 1)(0 -1)))
- )
- )
- )
- )
- (sldrawvecs (setq p (if p p pt)) mode size (vla-get-autosnapmarkercolor (vla-get-drafting (vla-get-preferences *Acad*))))
- )
- (if k (sl-sel-redrawsel name 1)) ;恢复显示
- )
- )
- (if p p pt)
- )
|
评分
-
查看全部评分
|