1. (defun gxl-Sel-ReDrawSel(Sel mode / m n)
    2. (if sel
    3. (progn
    4. (cond
    5. ((= 'pickset (type Sel))
    6. (setq m (sslength Sel) n 0)
    7. (repeat m (redraw (ssname Sel n) mode) (setq n (1+ n)))
    8. )
    9. ((= 'ename (type Sel)) (redraw Sel mode))
    10. )
    11. )
    12. )
    13. )
    14. ;;;gxl-Ge-grread 自定义带捕捉的GrRead函数
    15. ;;;参数:GR_MODE = 函数GrRead的参数表 如: (list [track] [allkeys [curtype]),参数个数按需要设置,可为nil
    16. ;;; STARTPT = 基点,计算垂足点、正交模式等坐标的基点,若为nil,则基点默认为系统变量LastPoint
    17. ;;; SS = 捕捉避开的物体,可以是选择集或图元名
    18. (defun gxl-Ge-grread (gr_mode startpt ss / get_osmode getgrvecs drawvecs time f3 f8 str_osmode lst_osmode draftobj autosnapmarkersize autosnapmarkercolor drag dragmode ghostpt x0 y0 x1 y1 z1 distperpixel bold)
    19. (defun gxl-StrParse ( str del / pos lst )
    20. (while (setq pos (vl-string-search del str))
    21. (setq lst (cons (substr str 1 pos) lst) str (substr str (+ pos 1 (strlen del))))
    22. )
    23. (if (= " " Del) (vl-remove "" (reverse (cons str lst))) (reverse (cons str lst)))
    24. )
    25. (defun get_osmode (/ cur_mode mode$)
    26. (setq mode$ "")
    27. (if (< 0 (setq cur_mode (getvar "osmode")) 16384) (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")))
    28. )
    29. mode$
    30. )
    31. (defun GetGrvecs (pt dragpt lst / KEY)
    32. (setq key T)
    33. (while (and key lst)
    34. (IF (equal (osnap dragpt (car lst)) pt 1E-6)
    35. (setq key nil)
    36. (setq lst (cdr lst))
    37. )
    38. )
    39. (cdr (assoc (car lst)
    40. '(
    41. ("_end"
    42. ((-1 1) (-1 -1))
    43. ((-1 -1) (1 -1))
    44. ((1 -1) (1 1))
    45. ((1 1) (-1 1))
    46. ) ;正方形
    47. ("_mid"
    48. ((0 1.414) (-1.225 -0.707))
    49. ((-1.225 -0.707) (1.225 -0.707))
    50. ((1.225 -0.707) (0 1.414))
    51. ) ;三角形
    52. ("_cen"
    53. ((0 1) (-0.707 0.707))
    54. ((-0.707 0.707) (-1 0))
    55. ((-1 0) (-0.707 -0.707))
    56. ((-0.707 -0.707) (0 -1))
    57. ((0 -1) (0.707 -0.707))
    58. ((0.707 -0.707) (1 0))
    59. ((1 0) (0.707 0.707))
    60. ((0.707 0.707) (0 1))
    61. ) ;圆
    62. ("_nod"
    63. ((0 1) (-0.707 0.707))
    64. ((-0.707 0.707) (-1 0))
    65. ((-1 0) (-0.707 -0.707))
    66. ((-0.707 -0.707) (0 -1))
    67. ((0 -1) (0.707 -0.707))
    68. ((0.707 -0.707) (1 0))
    69. ((1 0) (0.707 0.707))
    70. ((0.707 0.707) (0 1))
    71. ((-1 1) (1 -1))
    72. ((-1 -1) (1 1))
    73. ) ;圆+十字交叉
    74. ("_qua"
    75. ((0 1.414) (-1.414 0))
    76. ((-1.414 0) (0 -1.414))
    77. ((0 -1.414) (1.414 0))
    78. ((1.414 0) (0 1.414))
    79. ) ;旋转45°的正方形
    80. ("_int"
    81. ((-1 1) (1 -1))
    82. ((-1 -1) (1 1))
    83. ((1 0.859) (-0.859 -1))
    84. ((-1 0.859) (0.859 -1))
    85. ((0.859 1) (-1 -0.859))
    86. ((-0.859 1) (1 -0.859))
    87. ) ;十字交叉
    88. ("_ins"
    89. ((-1 1) (-1 -0.1))
    90. ((-1 -0.1) (0 -0.1))
    91. ((0 -0.1) (0 -1.0))
    92. ((0 -1.0) (1 -1))
    93. ((1 -1) (1 0.1))
    94. ((1 0.1) (0 0.1))
    95. ((0 0.1) (0 1.0))
    96. ((0 1.0) (-1 1))
    97. ) ;两个正方形
    98. ("_per"
    99. ((-1 1) (-1 -1))
    100. ((-1 -1) (1 -1))
    101. ((0 -1) (0 0))
    102. ((0 0) (-1 0))
    103. ) ;半个正方形
    104. ("_tan"
    105. ((0 1) (-0.707 0.707))
    106. ((-0.707 0.707) (-1 0))
    107. ((-1 0) (-0.707 -0.707))
    108. ((-0.707 -0.707) (0 -1))
    109. ((0 -1) (0.707 -0.707))
    110. ((0.707 -0.707) (1 0))
    111. ((1 0) (0.707 0.707))
    112. ((0.707 0.707) (0 1))
    113. ((1 1) (-1 1))
    114. ) ;园+线
    115. ("_nea"
    116. ((-1 1) (1 -1))
    117. ((1 -1) (-1 -1))
    118. ((-1 -1) (1 1))
    119. ((1 1) (-1 1))
    120. ) ;两个三角形
    121. ("_qui")
    122. ("_app"
    123. ((-1 1) (-1 -1))
    124. ((-1 -1) (1 -1))
    125. ((1 -1) (1 1))
    126. ((1 1) (-1 1))
    127. ((-1 1) (1 -1))
    128. ((-1 -1) (1 1))
    129. ) ;正方形+十字交叉
    130. ("_ext"
    131. ((0.1 0) (0.13 0))
    132. ((0.2 0) (0.23 0))
    133. ((0.3 0) (0.33 0))
    134. ) ;三个点
    135. ("_par" ((0 1) (-1 -1)) ((1 1) (0 -1))) ;两条线
    136. )
    137. )
    138. )
    139. )
    140. (defun DrawVecs (Pt Vecs Size Color / lst xdir)
    141. (setq xdir (getvar 'ucsxdir))
    142. (setq vecs (mapcar '(lambda (x) (mapcar '(lambda (a) (setq a (trans a 0 xdir)) (setq a (list (caddr a) (car a))) (list (+ (car pt) (* size (car a))) (+ (cadr pt) (* size (cadr a))))) x)) vecs))
    143. (setq lst (mapcar 'cons (mapcar (function (lambda (x) Color)) Vecs) Vecs))
    144. (grvecs (apply 'append lst))
    145. )
    146. (vl-load-com)
    147. (if STARTPT
    148. (setvar 'lastpoint STARTPT)
    149. (setq STARTPT (getvar 'lastpoint))
    150. )
    151. (setq time T)
    152. (setq F3 (getvar "osmode"))
    153. (setq F8 (getvar "ORTHOMODE"))
    154. (setq str_osmode (get_osmode))
    155. (setq lst_osmode (gxl-StrParse str_osmode ","))
    156. (setq Draftobj (vla-get-Drafting (vla-get-Preferences (vlax-get-acad-object))))
    157. (setq AutoSnapMarkerSize (vla-get-AutoSnapMarkerSize Draftobj))
    158. (setq AutoSnapMarkerColor (vla-get-AutoSnapMarkerColor Draftobj))
    159. (setq drag (apply 'grread GR_mode))
    160. (setq dragmode (car drag))
    161. (cond
    162. ((equal drag '(2 6))
    163. (if (< f3 16384)
    164. (progn (setq f3 (+ f3 16384))(prompt "\n<对象捕捉 关>"))
    165. (progn (setq f3 (- f3 16384))(prompt "\n<对象捕捉 开>"))
    166. )
    167. (setvar "OSMODE" f3)(redraw)
    168. )
    169. ((equal drag '(2 15))
    170. (if (= f8 0)
    171. (progn(setq f8 1)(prompt "\n<正交 开>"))
    172. (progn(setq f8 0)(prompt "\n<正交 关>"))
    173. )
    174. (setvar "orthomode" f8)(redraw)
    175. )
    176. ((= dragmode 5)
    177. (redraw)
    178. (gxl-Sel-ReDrawSel ss 2)
    179. (setq drag (cadr drag))
    180. (if (or (zerop (strlen str_osmode)) (null (setq ghostpt (osnap drag str_osmode))))
    181. (if (and startpt (= 1 f8) (/= 2 (car drag)))
    182. (progn
    183. (setq x0 (car startpt) y0 (cadr startpt) x1 (car drag) y1 (cadr drag) z1 (caddr drag))
    184. (if (> (abs (- x0 x1)) (abs (- y0 y1)))
    185. (setq ghostpt (list x1 y0 z1))
    186. (setq ghostpt (list x0 y1 z1))
    187. )
    188. )
    189. (setq ghostpt drag)
    190. )
    191. (progn (setq DistPerPixel (/ (getvar "VIEWSIZE") (cadr (getvar "SCREENSIZE"))))
    192. (setq Bold (mapcar '* (LIST DistPerPixel DistPerPixel DistPerPixel) (list (+ AutoSnapMarkerSize 0.5) AutoSnapMarkerSize (- AutoSnapMarkerSize 0.5))))
    193. (foreach item Bold (DrawVecs ghostpt (GetGrvecs ghostpt drag lst_osmode) item AutoSnapMarkerColor))
    194. )
    195. )
    196. (gxl-Sel-ReDrawSel ss 1)
    197. )
    198. ((or (= dragmode 3) (= dragmode 12))
    199. (gxl-Sel-ReDrawSel ss 2)
    200. (IF (Null (setq ghostpt (OSNAP (CADR drag) (get_osmode))))
    201. (if (and startpt (= 1 f8) (/= 2 (car drag)))
    202. (progn
    203. (setq x0 (car startpt)
    204. y0 (cadr startpt)
    205. x1 (caadr drag)
    206. y1 (cadadr drag)
    207. z1 (caddar (cdr drag))
    208. )
    209. (if (> (abs (- x0 x1)) (abs (- y0 y1)))
    210. (setq ghostpt (list x1 y0 z1))
    211. (setq ghostpt (list x0 y1 z1))
    212. )
    213. )
    214. (setq ghostpt (CADR drag))
    215. )
    216. )
    217. (REDRAW)
    218. (gxl-Sel-ReDrawSel ss 1)
    219. (setq time nil)
    220. )
    221. (t
    222. (if (and startpt (= 1 f8) (/= 2 (car drag)))
    223. (progn
    224. (setq x0 (car startpt)
    225. y0 (cadr startpt)
    226. x1 (caadr drag)
    227. y1 (cadadr drag)
    228. z1 (caddar (cdr drag))
    229. )
    230. (if (> (abs (- x0 x1)) (abs (- y0 y1)))
    231. (setq ghostpt (list x1 y0 z1))
    232. (setq ghostpt (list x0 y1 z1))
    233. )
    234. )
    235. (setq ghostpt (CADR drag))
    236. )
    237. (REDRAW)
    238. )
    239. )
    240. (list dragmode ghostpt)
    241. )