- UID
- 76911
- 积分
- 428
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2003-9-3
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
TheSwamp.org上的联接:
http://www.theswamp.org/index.php?topic=12797.0
调用grread获取原始点,然后通过osnap函数捕捉准确点,并调用grvecs画出自动捕捉记号
我为了能发表在TheSwamp.org,所以很多说明是用英文写的,请大家见谅.
CAB的原代码只写了grread+osnap,判断及加入绘制捕捉记号的部分是我添加上的
[php]
;; Grread+osnap+GRVECS
;; Rewritten by Fools @ TheSwamp.org
;;
;; Use (grread) to get original point
;; Use (osnap) to calculate accurate point
;; Use (GRVECS) to show AutoSnapMarker
;; No return , just show the method
(DEFUN c:tmp (/ AUTOSNAPMARKERCOLOR AUTOSNAPMARKERSIZE
DRAG GHOSTPT LST_OSMODE STR_OSMODE TIME
DistPerPixel Bold Draftobj get_osmode YPY_StrParse
YPY_GetGrvecs YPY_DrawVecs
)
;; CAB 10/5/2006
;; Fools change a little about "," (3/3/2007)
;;
;; Function to return the current osmode setting in the form of a string
;; If (getvar "osmode") = 175
;; (get_osmode) returns "_end,_mid,_cen,_nod,_int,_per"
(DEFUN get_osmode (/ cur_mode mode$)
(SETQ mode$ "")
(IF (< 0 (SETQ cur_mode (GETVAR "osmode")) 16383)
(MAPCAR (FUNCTION (LAMBDA (x)
(IF (NOT (ZEROP (LOGAND cur_mode (CAR x))))
(IF (ZEROP (STRLEN mode$))
(SETQ mode$ (CADR x))
(SETQ mode$ (STRCAT mode$ "," (CADR x)))
)
)
)
)
'((1 "_end")
(2 "_mid")
(4 "_cen")
(8 "_nod")
(16 "_qua")
(32 "_int")
(64 "_ins")
(128 "_per")
(256 "_tan")
(512 "_nea")
(1024 "_qui")
(2048 "_app")
(4096 "_ext")
(8192 "_par")
)
)
)
mode$
)
;;My functions
(DEFUN YPY_StrParse (str delim / ptr lst)
(WHILE (SETQ ptr (VL-STRING-SEARCH delim str))
(SETQ lst (CONS (SUBSTR str 1 ptr) lst))
(SETQ str (SUBSTR str (+ ptr 2)))
)
(REVERSE (CONS str lst))
)
(DEFUN YPY_GetGrvecs (pt dragpt lst / KEY)
(SETQ key T)
(WHILE (AND key lst)
(IF (EQUAL (OSNAP dragpt (CAR lst)) pt 1E-6)
(SETQ key nil)
(SETQ lst (CDR lst))
)
)
(CDR (ASSOC (CAR lst)
'(("_end"
((-1 1) (-1 -1))
((-1 -1) (1 -1))
((1 -1) (1 1))
((1 1) (-1 1))
) ;square
("_mid"
((0 1.414) (-1.225 -0.707))
((-1.225 -0.707) (1.225 -0.707))
((1.225 -0.707) (0 1.414))
) ;triangle
("_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))
) ;circle
("_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))
) ;circle+cross
("_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))
) ;square rotate 45
("_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))
) ;cross
("_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))
) ;two squares
("_per"
((-1 1) (-1 -1))
((-1 -1) (1 -1))
((0 -1) (0 0))
((0 0) (-1 0))
) ;half square
("_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))
) ;circle+line
("_nea"
((-1 1) (1 -1))
((1 -1) (-1 -1))
((-1 -1) (1 1))
((1 1) (-1 1))
) ;two triangle
("_qui") ; ???
("_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))
) ;square+cross
("_ext"
((0.1 0) (0.13 0))
((0.2 0) (0.23 0))
((0.3 0) (0.33 0))
) ;three points
("_par" ((0 1) (-1 -1)) ((1 1) (0 -1))) ;two lines
)
)
)
)
;;Use GRVECS
(DEFUN YPY_DrawVecs (Pt Vecs Size Color / lst matrix)
;;no Z axis
(SETQ matrix (LIST (LIST Size 0.0 0.0 (CAR pt))
(LIST 0.0 Size 0.0 (CADR pt))
(LIST 0.0 0.0 1.0 0.0)
(LIST 0.0 0.0 0.0 1.0)
)
)
(SETQ lst (MAPCAR 'CONS
(MAPCAR (FUNCTION (LAMBDA (x) Color)) Vecs)
Vecs
)
)
(GRVECS (APPLY 'APPEND lst) matrix)
)
;;****************************
;; Main Routine starts here
;;****************************
(VL-LOAD-COM)
(SETQ time T)
(SETQ str_osmode (get_osmode))
(SETQ lst_osmode (YPY_StrParse str_osmode ","))
(SETQ Draftobj (VLA-GET-DRAFTING
(VLA-GET-PREFERENCES (VLAX-GET-ACAD-OBJECT))
)
)
(SETQ AutoSnapMarkerSize (VLA-GET-AUTOSNAPMARKERSIZE Draftobj))
(SETQ AutoSnapMarkerColor (VLA-GET-AUTOSNAPMARKERCOLOR Draftobj))
(WHILE time
(grread (SETQ drag (GRREAD T 1 1))) ;;Can change like (grread T 15 2)
(COND ((= (CAR drag) 5)
(REDRAW)
(SETQ drag (CADR drag))
(IF (or (zerop (strlen str_osmode)) (NULL (SETQ ghostpt (OSNAP drag str_osmode))))
(SETQ ghostpt drag)
;;Beacuse of mouse middle button scroll , calculate "DistPerPixel" every time
(PROGN (SETQ DistPerPixel (/ (GETVAR "VIEWSIZE") (CADR (GETVAR "SCREENSIZE"))))
;;Bold
(SETQ Bold (MAPCAR '*
(LIST DistPerPixel DistPerPixel DistPerPixel)
(LIST (+ AutoSnapMarkerSize 0.5)
AutoSnapMarkerSize
(- AutoSnapMarkerSize 0.5)
)
)
)
(FOREACH item Bold
(YPY_DrawVecs
ghostpt
(YPY_GetGrvecs ghostpt drag lst_osmode)
item
AutoSnapMarkerColor
)
)
)
)
)
((= (CAR drag) 3)
(IF (NULL (SETQ ghostpt (OSNAP (CADR drag) (get_osmode))))
(SETQ ghostpt (CADR drag))
)
(REDRAW)
(SETQ time nil)
)
)
)
(PRINC) ;can return ghostpt if want
)
[/php] |
|