明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
楼主: daidong013

【求助】请大侠门来编一个这样的程序!

  [复制链接]
发表于 2011-6-25 14:40:17 | 显示全部楼层
daidong013 发表于 2011-6-25 13:59
回复 ZZXXQQ 的帖子

非常感谢大侠!~~画完后感觉还是6楼的好用些,因为四面的线都是段开的!~~

ZZXXQQ版编得多么简捷,你还觉得不好用,6#的简单型有改过了,你试试,升级版也出来过,不过不完美,改好再说。。。
发表于 2011-6-25 15:04:38 | 显示全部楼层
本帖最后由 zhynt 于 2011-6-25 15:12 编辑

再来个组合版的:(简版去掉了四边框线)
将;(progn
    ;  (command "_.rectang" nk_pt1 nk_pt3)
      (setvar "clayer" "nk_line")
    ;)
的"号去掉为有框线

  1. (defun err (s)
  2.   (if (and
  3.         (/= s "console break")
  4.         (/= s "Function cancelled")
  5.         (/= s "quit/exit abort")
  6.       )
  7.     (progn
  8.       (setvar "LUPREC" oldlup)
  9.       (setvar "LUNITS" oldlun)
  10.       (setvar "osmode" oldos)
  11.       (setvar "cmdecho" oldcmd)
  12.       (setvar "clayer" oldlay)
  13.       (setq *error* olderr)
  14.       (princ (strcat "\n程序出错或用户退出:" s))
  15.     )
  16.   )
  17. )
  18. (defun c:ldf (/                wk_pt1          wk_pt2    wk_pt3    wk_pt4
  19.               nk_pt1        nk_pt2          nk_pt3    nk_pt4    olds
  20.               oldcmd        oldlup          oldlay    nk_n      nk_kd
  21.               ptax        ptay          ptaz            ptbx      ptby
  22.               ptbz        l_pt1_pt4 l_pt2_pt3 l_n              ang_pt1_pt4
  23.              )
  24.   (setq oldos (getvar "osmode"))
  25.   (if (< oldos 16384)
  26.     (setvar "osmode" (+ oldos 16384))
  27.   )
  28.   (setq        oldcmd        (getvar "cmdecho")
  29.         oldlun        (getvar "LUNITS")
  30.         oldlup        (getvar "LUPREC")
  31.         olderr        *error*
  32.         *error*        err
  33.         oldlay        (getvar "clayer")
  34.   )
  35.   (setvar "cmdecho" 0)
  36.   (setvar "LUPREC" 8)
  37.   (setvar "LUNITS" 2)
  38.   (if (= (TBLOBJNAME "LAYER" "wk_line") nil)
  39.     (command "layer" "m" "wk_line" "c" "2" "" "")
  40.   )
  41.   (if (= (TBLOBJNAME "LAYER" "nk_line") nil)
  42.     (command "layer" "m" "nk_line" "c" "1" "" "")
  43.   )
  44.   (setvar "clayer" "wk_line")
  45.   (setq        wk_pt1 (getpoint "\n指定第一角点")
  46.         wk_pt3 (getcorner wk_pt1 "\n指定第二角点:")
  47.         nk_n   (getint "\n请输入大于零的等分数:")
  48.         wk_kd  (getreal "\n输入边框宽度:输入0为简版<20mm>:")
  49.   )
  50.   (if (= wk_kd nil)
  51.     (setq wk_kd 20.0)
  52.   )
  53.   (setq        ptax (car wk_pt1)
  54.         ptay (cadr wk_pt1)
  55.         ptbx (car wk_pt3)
  56.         ptby (cadr wk_pt3)
  57.   )
  58.   (setq        wk_pt2 (list ptax ptby)
  59.         wk_pt4 (list ptbx ptay)
  60.   )
  61.   (if (/= wk_kd 0)
  62.     (progn
  63.       (setq nk_pt1
  64.              (polar wk_pt1
  65.                     (/ (- (angle wk_pt1 wk_pt2) (angle wk_pt1 wk_pt4)) 2.0)
  66.                     (* wk_kd (* 2 (sqrt 2)))
  67.              )
  68.       )
  69.       (setq nk_pt3
  70.              (polar wk_pt3
  71.                     (+ (/ (- (angle wk_pt3 wk_pt2) (angle wk_pt3 wk_pt4)) 2.0)
  72.                        (/ (* pi 3.0) 2.0)
  73.                     )
  74.                     (* wk_kd (* 2 (sqrt 2)))
  75.              )
  76.       )
  77.       (setq ptax (car nk_pt1)
  78.             ptay (cadr nk_pt1)
  79.             ptbx (car nk_pt3)
  80.             ptby (cadr nk_pt3)
  81.       )
  82.       (setq nk_pt2 (list ptax ptby)
  83.             nk_pt4 (list ptbx ptay)
  84.       )
  85.     )
  86.     (setq nk_pt1 wk_pt1
  87.           nk_pt2 wk_pt2
  88.           nk_pt3 wk_pt3
  89.           nk_pt4 wk_pt4
  90.     )
  91.   )
  92.   (setq        l_pt1_pt4   (distance nk_pt1 nk_pt4)
  93.         l_pt1_pt2   (distance nk_pt1 nk_pt2)
  94.         ang_pt1_pt4 (angle nk_pt1 nk_pt4)
  95.         l_n            (/ l_pt1_pt4 nk_n)
  96.   )
  97.   (if (/= wk_kd 0)
  98.     (progn
  99.       (command "_.rectang" wk_pt1 wk_pt3)
  100.       (setvar "clayer" "nk_line")
  101.       (command "_.rectang" nk_pt1 nk_pt3)
  102.     )
  103.    ; (progn
  104.    ;   (command "_.rectang" nk_pt1 nk_pt3)
  105.       (setvar "clayer" "nk_line")
  106.    ; )
  107.   )     
  108.   (setq        n_pt1 nk_pt1
  109.         n_pt2 nk_pt2
  110.   )
  111.   (repeat (- nk_n 1)
  112.     (setq n_pt3        (polar n_pt1 ang_pt1_pt4 l_n)
  113.           n_pt4        (polar n_pt3 (+ ang_pt1_pt4 (/ pi 2.0)) l_pt1_pt2)
  114.     )
  115.     (command "_.line" n_pt1 n_pt4 n_pt3 n_pt2 "")
  116.     (setq n_pt1        n_pt3
  117.           n_pt2        n_pt4
  118.     )
  119.   )
  120.   (command "_.line" n_pt1 nk_pt3 "")
  121.   (command "_.line" nk_pt4 n_pt2 "")
  122.   (setvar "osmode" oldos)
  123.   (setvar "cmdecho" oldcmd)
  124.   (setvar "clayer" oldlay)
  125.   (setvar "LUPREC" oldlup)
  126.   (setvar "LUNITS" oldlun)
  127.   (princ)
  128. )
发表于 2011-6-25 15:28:13 | 显示全部楼层
  1. ;;;拉框N等分加边距 在ZZXXQQ基础上扩展的
  2. (defun c:tt ()
  3.   (setvar "CMDECHO" 0)
  4.   (command "undo" "g")
  5.   (setq oldos (getvar "OSMODE"))
  6.   (if (and  (setq p1 (getpoint "\n第一角点 :"))
  7.            (setq p2 (getcorner p1 "\n另一角点 :"))
  8.            (setq n (getint "\n等分数 :"))
  9.            (or (setq d (getreal "\n输入边框宽度:<20mm>:"))
  10.                (setq d 20.)
  11.            )
  12.       )
  13.    
  14.     (progn
  15.       (setvar "OSMODE" 0)
  16.       (setq dx1        (abs (- (car p2) (car p1)))
  17.             dy1        (abs (- (cadr p2) (cadr p1)))
  18.       )
  19.       (setq ptm        (list (min (car p1) (car p2)) (min (cadr p1) (cadr p2)))
  20.             p2        (list (max (car p1) (car p2)) (max (cadr p1) (cadr p2)))
  21.             p01        ptm
  22.       )
  23.       (setq p1        (list (+ (car p01) d) (+ (cadr p01) d))
  24.             p00        p1
  25.       )
  26.       ;;内基准点
  27.       (setq dx (- dx1 (* d 2))
  28.             dy (- dy1 (* d 2))
  29.       )
  30.       (if (> dx dy)
  31.         (progn
  32.           (setq dd (/ dx n))
  33.           (repeat n
  34.             (setq p3 (polar p1 0 dd)
  35.                   p4 (polar p1 (/ pi 2) dy)
  36.                   p5 (polar p4 0 dd)
  37.             )
  38.             (command "_.LINE" p1 p5 p3 "")
  39.             (setq ent (entlast))
  40.             (command "_.LINE" p3 p4 "")
  41.             (setq p1 p3)
  42.           )
  43.         )
  44.         (progn
  45.           (setq dd (/ dy n))
  46.           (repeat n
  47.             (setq p3 (polar p1 (/ pi 2) dd)
  48.                   p4 (polar p1 0 dx)
  49.                   p5 (polar p3 0 dx)
  50.             )
  51.             (command "_.LINE" p1 p5 p3 "")
  52.             (setq ent (entlast))
  53.             (command "_.LINE" p3 p4 "")
  54.             (setq p1 p3)
  55.           )
  56.         )
  57.       )
  58.       (entdel ent)
  59.       (command "RECTANG" p00 p5)
  60.       (setvar "OSMODE" oldos)
  61.     )
  62.   )
  63.   (command "undo" "e")
  64.   (setvar "CMDECHO" 1)
  65.   (princ)
  66. )
 楼主| 发表于 2011-6-25 15:49:07 | 显示全部楼层
回复 zhynt 的帖子

大侠!不错不错,不过怎么没有捕捉呢!!~~
 楼主| 发表于 2011-6-25 15:55:55 | 显示全部楼层
回复 ljpnb 的帖子

真厉害!~~这就是我想要的效果!~~~!~~
不过最外面的外框矩形可以选择有或者没有要怎么改一下!~~
【zhynt】大侠的组合版有最外面的矩形外框!~~
发表于 2011-6-25 16:08:22 | 显示全部楼层
如果加外框,可以在(command "RECTANG" p00 p5)
之后再加一句(command "RECTANG" ptm p2)

 楼主| 发表于 2011-6-25 16:14:02 | 显示全部楼层
回复 ljpnb 的帖子

万分感谢!~~终于完美了!~~~
发表于 2011-6-25 16:18:07 | 显示全部楼层
将关闭捕捉的位置调整了一下:

  1. (defun err (s)
  2.   (if (and
  3.         (/= s "console break")
  4.         (/= s "Function cancelled")
  5.         (/= s "quit/exit abort")
  6.       )
  7.     (progn
  8.       (setvar "LUPREC" oldlup)
  9.       (setvar "LUNITS" oldlun)
  10.       (setvar "osmode" oldos)
  11.       (setvar "cmdecho" oldcmd)
  12.       (setvar "clayer" oldlay)
  13.       (setq *error* olderr)
  14.       (princ (strcat "\n程序出错或用户退出:" s))
  15.     )
  16.   )
  17. )
  18. (defun c:ldf (/                nk_pt1          nk_pt2    nk_pt3    nk_pt4
  19.               olds        oldcmd          oldlup    oldlay    nk_n
  20.               nk_kd        ptax          ptay            ptaz      ptbx
  21.               ptby        ptbz          l_pt1_pt4 l_pt2_pt3 l_n
  22.               ang_pt1_pt4
  23.              )
  24.   (setq oldos (getvar "osmode"))  
  25.   (setq        oldcmd        (getvar "cmdecho")
  26.         oldlun        (getvar "LUNITS")
  27.         oldlup        (getvar "LUPREC")
  28.         olderr        *error*
  29.         *error*        err
  30.         oldlay        (getvar "clayer")
  31.   )
  32.   (setvar "cmdecho" 0)
  33.   (setvar "LUPREC" 8)
  34.   (setvar "LUNITS" 2)
  35.   (if (= (TBLOBJNAME "LAYER" "wk_line") nil)
  36.     (command "layer" "m" "wk_line" "c" "2" "" "")
  37.   )
  38.   (if (= (TBLOBJNAME "LAYER" "nk_line") nil)
  39.     (command "layer" "m" "nk_line" "c" "1" "" "")
  40.   )
  41.   (setvar "clayer" "wk_line")
  42.   (setq        wk_pt1 (getpoint "\n指定第一角点")
  43.         wk_pt3 (getcorner wk_pt1 "\n指定第二角点:")
  44.         nk_n   (getint "\n请输入大于零的等分数:")
  45.         wk_kd  (getreal "\n输入边框宽度:输入0为简版<20mm>:")
  46.   )
  47.   (if (= wk_kd nil)
  48.     (setq wk_kd 20.0)
  49.   )
  50.   (setq        wk_ptn (list (min (car wk_pt1) (car wk_pt3))
  51.                      (min (cadr wk_pt1) (cadr wk_pt3))
  52.                )
  53.         wk_pt3 (list (max (car wk_pt1) (car wk_pt3))
  54.                      (max (cadr wk_pt1) (cadr wk_pt3))
  55.                )
  56.         wk_pt1 wk_ptn
  57.   )
  58.   (setq        ptax (car wk_pt1)
  59.         ptay (cadr wk_pt1)
  60.         ptbx (car wk_pt3)
  61.         ptby (cadr wk_pt3)
  62.   )
  63.   (setq        wk_pt2 (list ptax ptby)
  64.         wk_pt4 (list ptbx ptay)
  65.   )
  66.   (if (/= wk_kd 0)
  67.     (progn
  68.       (setq nk_pt1
  69.              (polar wk_pt1
  70.                     (/ pi 4)
  71.                     (* wk_kd (* 2 (sqrt 2)))
  72.              )
  73.       )
  74.       (setq nk_pt3
  75.              (polar wk_pt3
  76.                     (/ (* pi 5) 4)
  77.                     (* wk_kd (* 2 (sqrt 2)))
  78.              )
  79.       )
  80.       (setq ptax (car nk_pt1)
  81.             ptay (cadr nk_pt1)
  82.             ptbx (car nk_pt3)
  83.             ptby (cadr nk_pt3)
  84.       )
  85.       (setq nk_pt2 (list ptax ptby)
  86.             nk_pt4 (list ptbx ptay)
  87.       )
  88.     )
  89.     (setq nk_pt1 wk_pt1
  90.           nk_pt2 wk_pt2
  91.           nk_pt3 wk_pt3
  92.           nk_pt4 wk_pt4
  93.     )
  94.   )
  95.   (setq        l_pt1_pt4   (distance nk_pt1 nk_pt4)
  96.         l_pt1_pt2   (distance nk_pt1 nk_pt2)       
  97.         ang_pt1_pt4 (angle nk_pt1 nk_pt4)
  98.         l_n            (/ l_pt1_pt4 nk_n)
  99.   )
  100.   (if (< oldos 16384)
  101.     (setvar "osmode" (+ oldos 16384))
  102.   )
  103.   (if (/= wk_kd 0)
  104.     (progn
  105.       (command "_.rectang" wk_pt1 wk_pt3)
  106.       (setvar "clayer" "nk_line")
  107.       (command "_.rectang" nk_pt1 nk_pt3)
  108.     )
  109.     (progn (command "_.rectang" nk_pt1 nk_pt3)
  110.            (setvar "clayer" "nk_line")
  111.     )
  112.   )
  113.   (setq        n_pt1 nk_pt1
  114.         n_pt2 nk_pt2
  115.   )
  116.   (repeat (- nk_n 1)
  117.     (setq n_pt3        (polar n_pt1 ang_pt1_pt4 l_n)
  118.           n_pt4        (polar n_pt3 (+ ang_pt1_pt4 (/ pi 2.0)) l_pt1_pt2)
  119.     )
  120.     (command "_.line" n_pt1 n_pt4 n_pt3 n_pt2 "")
  121.     (setq n_pt1        n_pt3
  122.           n_pt2        n_pt4
  123.     )
  124.   )
  125.   (command "_.line" n_pt1 nk_pt3 "")
  126.   (command "_.line" nk_pt4 n_pt2 "")
  127.   (setvar "osmode" oldos)
  128.   (setvar "cmdecho" oldcmd)
  129.   (setvar "clayer" oldlay)
  130.   (setvar "LUPREC" oldlup)
  131.   (setvar "LUNITS" oldlun)
  132.   (princ)
  133. )
 楼主| 发表于 2011-6-25 17:52:52 | 显示全部楼层
本帖最后由 daidong013 于 2011-6-25 18:09 编辑

回复 zhynt 的帖子

现在好了,不错不错!~二合为一!~~感谢!~~
只不过只能识别一个方向的等分,不是识别长边为基础!~~
这样竖向画的时候就有问题!~~

发表于 2011-6-25 21:09:44 | 显示全部楼层
7楼和13楼的可竖画。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-5-28 01:54 , Processed in 0.171012 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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