;; 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 STD-STRTOK
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$
)
;; -------------------------------------------------------------------73
;; Tokenizers
;; These might be renamed to the long versions:
;; std-string-tokenize, std-string-split and std-string-join
;; Converts string with delimiters into string list
;; Ignore repeated delims such as white space.
;; The order of chars in delim is not important.
;; Might be renamed to std-string-tokenize
;; Also named lex-string in some Common Lisps.
;; (std-strtok " 2 3 " " ") => ("2" "3")
;; (std-strtok "f 1,3" ", ") => ("f" "1" "3")
;; Same as std-string->strlist
(DEFUN STD-STRTOK (s delims / len s1 i c lst)
(SETQ delims (VL-STRING->LIST delims)
len (STRLEN s)
s1 ""
i (1+ len)
)
(WHILE (> (SETQ i (1- i)) 0)
(SETQ c (SUBSTR s i 1))
(IF (MEMBER (ASCII c) delims)
(IF (/= s1 "") ; no null tokens
(SETQ lst (CONS s1 lst)
s1 ""
)
)
(SETQ s1 (STRCAT c s1))
)
)
(IF (/= s1 "")
(CONS s1 lst) ; no ("" "1" "2")!
lst
)
)
;;My functions
(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 (STD-STRTOK 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 15 1)))
(COND ((= (CAR drag) 5)
(REDRAW)
(SETQ drag (CADR drag))
(IF (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
)