明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
楼主: Gu_xl

[【Gu_xl】] 【Gu_xl】【源码分享】自定义带捕捉的grread函数

    [复制链接]
发表于 2016-6-6 18:53 | 显示全部楼层
不错 学习了 .................
发表于 2016-6-6 18:54 | 显示全部楼层
没看到代码在哪啊...............grread
发表于 2016-6-7 08:04 | 显示全部楼层
谢谢G版分享,学习一下!
发表于 2016-7-24 16:58 | 显示全部楼层
学习学习,找了好久了
发表于 2016-7-24 17:01 | 显示全部楼层
之前在theswamp上看到一个类似的,不过想看看楼主的
发表于 2016-7-24 17:02 | 显示全部楼层
我之前用的,但没有显示
  1. ;;  eGrid.lsp
  2. ;;  Rewritten by CAB @ TheSwamp.org
  3. ;;
  4. ;;  User picks a rectangle to size the 24x24 grid lines the
  5. ;;  User drags the grid to it's final position

  6. (defun c:egrid (/       DRAG    GHOSTPT H_CNT   H_CNT   H_DIST  H_OFS   PLIST
  7.                 PT_1    PT_2    TIME    TMP     V_CNT   V_CNT   V_DIST  V_OFS
  8.                 get_osmode calc_ get_points DrawGrid ghost
  9.                )


  10.   ;;  CAB  10/5/2006
  11.   ;;
  12.   ;;  Function to return the current osmode setting in the form of a string
  13.   ;;  If (getvar "osmode") = 175
  14.   ;;  (get_osmode)  returns   "_end,_mid,_cen,_nod,_int,_per"
  15.   (defun get_osmode (/ cur_mode mode$)
  16.     (setq mode$ "")
  17.     (if (< 0 (setq cur_mode (getvar "osmode")) 16383)
  18.       (mapcar
  19.         '(lambda (x)
  20.            (if (not (zerop (logand cur_mode (car x))))
  21.              (setq mode$ (strcat mode$ (cadr x)))
  22.            )
  23.          )
  24.         '(
  25.           (0    "_non,")
  26.           (1    "_end,")
  27.           (2    "_mid,")
  28.           (4    "_cen,")
  29.           (8    "_nod,")
  30.           (16   "_qua,")
  31.           (32   "_int,")
  32.           (64   "_ins,")
  33.           (128  "_per,")
  34.           (256  "_tan,")
  35.           (512  "_nea,")
  36.           (1024 "_qui,")
  37.           (2048 "_app,")
  38.           (4096 "_ext,")
  39.           (8192 "_par")
  40.          )
  41.       )
  42.     )
  43.     mode$
  44.   )

  45.   ;;  Subrutine - calc offset & count
  46.   (defun calc_ (dist / rm ofs count)
  47.     (setq count (/ dist 24.0))
  48.     (setq rm (- count (fix count)))
  49.     (setq ofs (* rm 12))

  50.     (cond
  51.       ((zerop rm)                       ; 24 even
  52.        (setq count (1- count)
  53.              ofs   24
  54.        )
  55.       )
  56.       ((< ofs 12)
  57.        (setq ofs   (+ ofs 12)
  58.              count (1- count)
  59.        )
  60.       )
  61.     )
  62.     (list ofs (fix count))
  63.   )


  64.   (defun get_points (ll h_ofs h_cnt v_ofs v_cnt h_dist v_dist / up ptl pts pte)
  65.     (setq up (/ pi 2))
  66.     ;;  hor lines
  67.     (setq pts (polar ll up v_ofs)
  68.           pte (polar pts 0 h_dist)
  69.     )
  70.     (setq ptl (list (list pts pte)))
  71.     (repeat v_cnt
  72.       (setq pts (polar pts up 24)
  73.             pte (polar pts 0 h_dist)
  74.       )
  75.       (setq ptl (cons (list pts pte) ptl))
  76.     )
  77.     ;;  vert lines
  78.     (setq pts (polar ll 0 h_ofs)
  79.           pte (polar pts up v_dist)
  80.     )
  81.     (setq ptl (cons (list pts pte) ptl))
  82.     (repeat h_cnt
  83.       (setq pts (polar pts 0 24)
  84.             pte (polar pts up v_dist)
  85.       )
  86.       (setq ptl (cons (list pts pte) ptl))
  87.     )
  88.     ptl
  89.   )


  90.   ;;  Draw the Grid
  91.   (defun DrawGrid (plist / mk_line)
  92.     (defun mk_line (st en)
  93.       (entmake (list
  94.                  (cons 0 "LINE")        ;***
  95.                  (cons 6 "BYLAYER")
  96.                  (cons 8 "0")
  97.                  (cons 10 st)           ;***
  98.                  (cons 11 en)           ;***
  99.                  (cons 39 0.0)
  100.                  (cons 62 256)
  101.                  (cons 210 (list 0.0 0.0 1.0))
  102.                )
  103.       )
  104.     )
  105.     (mapcar '(lambda (x) (mk_line (car x) (cadr x))) plist)

  106.   )


  107.   ;;  Ghost the Grid
  108.   (defun ghost (plist / pv)
  109.     (mapcar '(lambda (x)
  110.                (if pv
  111.                  (setq pv (cons (car x) (cons (cadr x) (cons 4 pv))))
  112.                  (setq pv (list (car x) (cadr x) 4))
  113.                )
  114.              )
  115.             plist
  116.     )
  117.     (grvecs (reverse pv))
  118.   )


  119.   ;;****************************
  120.   ;;  Main Routine starts here
  121.   ;;****************************
  122.   (setq pt_1 (getpoint "\n* Size the Grid, Pick Lower-Left corner *"))
  123.   (setq pt_2 (getcorner pt_1 "\n* Pick Upper-Right corner *"))

  124.   (setq h_dist (- (car pt_2) (car pt_1))) ; horizontal length of the rectangle
  125.   (setq v_dist (- (cadr pt_2) (cadr pt_1))) ; vertical length of the rectangle


  126.   (setq tmp   (Calc_ h_dist)
  127.         h_ofs (car tmp)
  128.         h_cnt (cadr tmp)
  129.   )

  130.   (setq tmp   (Calc_ v_dist)
  131.         v_ofs (car tmp)
  132.         v_cnt (cadr tmp)
  133.   )


  134.   (setq time T)
  135.   (while time
  136.     (setq drag (grread t 1 1))
  137.     (cond
  138.       ((= (car drag) 5)
  139.        (if (null (setq ghostpt (osnap (cadr drag) (get_osmode))))
  140.          (setq ghostpt (cadr drag))
  141.        )
  142.        (redraw)
  143.        (setq plist (get_points ghostpt h_ofs h_cnt v_ofs v_cnt h_dist v_dist))
  144.        (ghost plist)
  145.       )
  146.       ((= (car drag) 3)
  147.        ;;(setq ghostpt (cadr drag))
  148.        (if (null (setq ghostpt (osnap (cadr drag) (get_osmode))))
  149.          (setq ghostpt (cadr drag))
  150.        )
  151.        (redraw)
  152.        (setq plist (get_points ghostpt h_ofs h_cnt v_ofs v_cnt h_dist v_dist))
  153.        (DrawGrid plist)
  154.        (setq time nil)
  155.       )
  156.     )
  157.   )
  158.   (princ)
  159. )
发表于 2016-7-24 18:24 | 显示全部楼层
本帖最后由 jpgmeta 于 2016-7-25 06:16 编辑

楼主,当我将图纸用鼠标缩小时,会出现"INTERSECT 所选对象太多"的提示,可能是光标下的点太多引起的
----------------------
刚发现关掉捕捉中的"交点"就可以了


发表于 2016-8-2 19:58 | 显示全部楼层
看一下,支持楼主
发表于 2016-9-13 16:36 | 显示全部楼层
发表于 2016-9-19 09:42 | 显示全部楼层
grread的捕捉lihai
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-5-14 00:58 , Processed in 0.145736 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表