乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
楼主: SstennizZ

[编程交流] 自定义旋转/缩放

[复制链接]
CAB

29

主题

781

帖子

430

银币

中流砥柱

Rank: 25

铜币
526
发表于 2022-7-6 17:54:14 | 显示全部楼层
新版本。
  1. (defun c:test2 ()
  2. ;;  CAB version 1.1
  3. ;;  Calling routine to pass a tangent point (p1) & offset distance (od)
  4. ;;  Routine will allow user to stretch outer circle using diameter
  5. ;;  Note if offset distance is a negative number the offset circle
  6. ;;  will be on the outside
  7. ;;
  8. ;;  Returns the 2nd pick point
  9. (defun ghostCircle (p1 od / *error* p2 d1 c1 c2 el1 el2 gr rMin)
  10.    (defun *error* (msg)
  11.      (if (not
  12.            (member msg '("Console break" "Function cancelled" "quit / exit abort" "" nil))
  13.          )
  14.        (princ (strcat "\nError: " msg))
  15.      )
  16.      (and c1 (entdel c1))
  17.      (and c2 (entdel c2))
  18.      (princ)
  19.    )     ; end error function
  20.    
  21.    (setq rMin 0.001)
  22.    (setq c1
  23.           (entmakex (list (cons 0 "CIRCLE")
  24.                           (cons 6 "BYLAYER")
  25.                           (cons 8 "0")
  26.                           (cons 10 p1)
  27.                           (cons 39 0.0)
  28.                           (cons 40 rMin) ; radius
  29.                           (cons 62 256)
  30.                           (cons 210 (list 0.0 0.0 1.0))
  31.                     )
  32.           )
  33.    )
  34.    (setq c2
  35.           (entmakex (list (cons 0 "CIRCLE")
  36.                           (cons 6 "BYLAYER")
  37.                           (cons 8 "0")
  38.                           (cons 10 p1)
  39.                           (cons 39 0.0)
  40.                           (cons 40 rMin) ; radius
  41.                           (cons 62 256)
  42.                           (cons 210 (list 0.0 0.0 1.0))
  43.                     )
  44.           )
  45.    )
  46.    (setq el1 (entget c1)
  47.          el2 (entget c2)
  48.    )
  49.    ;;  p1 is a tangent point
  50.    ;;  p2 is a tangent point with center at mid point of p1 p2
  51.    (while (and (setq gr (grread 5)) (= (car gr) 5))
  52.      (cond
  53.        ((> (setq d1 (distance p1 (setq p2 (cadr gr)))) rMin)
  54.         (setq el1 (subst (cons 40 (setq r1 (/ d1 2.))) (assoc 40 el1) el1))
  55.         (setq el1 (entmod (subst (cons 10 (polar p1 (angle p1 p2) r1)) (assoc 10 el1) el1)))
  56.         (entupd (cdr (assoc -1 el1)))
  57.         (cond
  58.           ((< rMin (- d1 od))
  59.            (setq el2 (subst (cons 40 (- d1 (/ od 2.))) (assoc 40 el2) el2))
  60.            (setq el2 (entmod (subst (assoc 10 el1) (assoc 10 el2) el2)))
  61.            (entupd (cdr (assoc -1 el2)))
  62.           )
  63.           (t ; minimize the inner circle
  64.            (setq el2 (subst (cons 40 rMin) (assoc 40 el2) el2))
  65.            (setq el2 (entmod (subst (assoc 10 el1) (assoc 10 el2) el2)))
  66.            (entupd (cdr (assoc -1 el2)))
  67.           )
  68.         )
  69.        )
  70.        (t ; minimize the outer circle
  71.         (setq el1 (subst (cons 40 rMin) (assoc 40 el1) el1))
  72.         (setq el1 (entmod (subst (cons 10 (polar p1 (angle p1 p2) (/ rMin 2.))) (assoc 10 el1) el1)))
  73.         (entupd (cdr (assoc -1 el1)))
  74.        )
  75.      )
  76.    )
  77.    (entdel c1)
  78.    (entdel c2)
  79.    p2
  80. )
  81. (setq pc (getpoint "\nPick center point."))
  82. (princ "\n Select new radius  ")
  83. (setq rad (ghostcircle pc 850.0))
  84. (princ rad)
  85. (princ)
  86. )
回复

使用道具 举报

2

主题

12

帖子

11

银币

初来乍到

Rank: 1

铜币
15
发表于 2022-7-6 17:56:38 | 显示全部楼层
 
伙计,看起来不错!但是起点必须在外圆上。内圈的偏移量必须保持在850。现在,当我把圆变大时,偏移量也会变大。你可以在日常生活中这样做吗?
最后但并非最不重要的一点是,现在它只显示了圆圈。也可以画吗?谢谢你,伙计!我一个人永远不可能想出那样的套路!
回复

使用道具 举报

CAB

29

主题

781

帖子

430

银币

中流砥柱

Rank: 25

铜币
526
发表于 2022-7-6 18:00:59 | 显示全部楼层
不客气。
 
更改此
  1.     (entdel c1)
  2.    (entdel c2)

为了保持循环
  1.     ; (entdel c1)
  2.    ; (entdel c2)

 
然后改变这个
  1.   (setq rad (ghostcircle pc 850.0))

将点从内圈切换到外圈
  1.   (setq rad (ghostcircle pc -850.0))
回复

使用道具 举报

2

主题

12

帖子

11

银币

初来乍到

Rank: 1

铜币
15
发表于 2022-7-6 18:02:19 | 显示全部楼层
 
好的,entdel部分工作了,但是由于某种原因将850改为-850没有效果。
内圈的偏移量必须保持在850。现在,当我把圆变大时,偏移量也会变大。
回复

使用道具 举报

CAB

29

主题

781

帖子

430

银币

中流砥柱

Rank: 25

铜币
526
发表于 2022-7-6 18:05:35 | 显示全部楼层
哎呀,数学错误修复了。试试1.2版
  1. (defun c:test2 ()
  2. ;;  CAB version 1.2
  3. ;;  Calling routine to pass a tangent point (p1) & offset distance (od)
  4. ;;  Routine will allow user to stretch outer circle using diameter
  5. ;;  Note if offset distance is a negative number the offset circle
  6. ;;  will be on the outside
  7. ;;
  8. ;;  Returns the 2nd pick point
  9. (defun ghostCircle (p1 od / *error* p2 d1 c1 c2 el1 el2 gr rMin)
  10.    (defun *error* (msg)
  11.      (if (not
  12.            (member msg '("Console break" "Function cancelled" "quit / exit abort" "" nil))
  13.          )
  14.        (princ (strcat "\nError: " msg))
  15.      )
  16.      (and c1 (entdel c1))
  17.      (and c2 (entdel c2))
  18.      (princ)
  19.    )     ; end error function
  20.    
  21.    (setq rMin 0.001) ; Minimum Radius allowed
  22.    (setq c1
  23.           (entmakex (list (cons 0 "CIRCLE")
  24.                           (cons 6 "BYLAYER")
  25.                           (cons 8 "0")
  26.                           (cons 10 p1)
  27.                           (cons 39 0.0)
  28.                           (cons 40 rMin) ; radius
  29.                           (cons 62 256)
  30.                           (cons 210 (list 0.0 0.0 1.0))
  31.                     )
  32.           )
  33.    )
  34.    (setq c2
  35.           (entmakex (list (cons 0 "CIRCLE")
  36.                           (cons 6 "BYLAYER")
  37.                           (cons 8 "0")
  38.                           (cons 10 p1)
  39.                           (cons 39 0.0)
  40.                           (cons 40 rMin) ; radius
  41.                           (cons 62 256)
  42.                           (cons 210 (list 0.0 0.0 1.0))
  43.                     )
  44.           )
  45.    )
  46.    (setq el1 (entget c1)
  47.          el2 (entget c2)
  48.    )
  49.    ;;  p1 is a tangent point
  50.    ;;  p2 is a tangent point with center at mid point of p1 p2
  51.    (while (and (setq gr (grread 5)) (= (car gr) 5))
  52.      (cond
  53.        ((> (setq d1 (distance p1 (setq p2 (cadr gr)))) rMin)
  54.         (setq el1 (subst (cons 40 (setq r1 (/ d1 2.))) (assoc 40 el1) el1))
  55.         (setq el1 (entmod (subst (cons 10 (polar p1 (angle p1 p2) r1)) (assoc 10 el1) el1)))
  56.         (entupd (cdr (assoc -1 el1)))
  57.         (cond
  58.           ((< rMin (- d1 (* od 2.)))
  59.            (setq el2 (subst (cons 40 (/ (- d1 (* od 2.)) 2.)) (assoc 40 el2) el2))
  60.            (setq el2 (entmod (subst (assoc 10 el1) (assoc 10 el2) el2)))
  61.            (entupd (cdr (assoc -1 el2)))
  62.           )
  63.           (t ; minimize the inner circle
  64.            (setq el2 (subst (cons 40 rMin) (assoc 40 el2) el2))
  65.            (setq el2 (entmod (subst (assoc 10 el1) (assoc 10 el2) el2)))
  66.            (entupd (cdr (assoc -1 el2)))
  67.           )
  68.         )
  69.        )
  70.        (t ; minimize the outer circle
  71.         (setq el1 (subst (cons 40 rMin) (assoc 40 el1) el1))
  72.         (setq el1 (entmod (subst (cons 10 (polar p1 (angle p1 p2) (/ rMin 2.))) (assoc 10 el1) el1)))
  73.         (entupd (cdr (assoc -1 el1)))
  74.        )
  75.      )
  76.    )
  77.    ;(entdel c1) ; to remove the circle
  78.    ;(entdel c2) ; to remove the circle
  79.    p2
  80. )
  81. (setq pc (getpoint "\nPick center point."))
  82. (princ "\n Select new radius  ")
  83. (setq rad (ghostcircle pc 850.0))
  84. (princ rad)
  85. (princ)
  86. )
回复

使用道具 举报

2

主题

12

帖子

11

银币

初来乍到

Rank: 1

铜币
15
发表于 2022-7-6 18:09:18 | 显示全部楼层
令人惊叹的!
Thanx很多!这太棒了!现在我需要做的就是找出如何使其切换到特定层并返回。
 
为什么我不能捕捉第二个点,第二个点可能是圆的中心吗?我知道我很痛苦,但这是为了更好!
回复

使用道具 举报

CAB

29

主题

781

帖子

430

银币

中流砥柱

Rank: 25

铜币
526
发表于 2022-7-6 18:12:22 | 显示全部楼层
这里有图层。将生成的层不存在。
注意,grread不支持Osnap。
要做到这一点,有一个相当长的程序。
但是我可以添加一个特征来捕捉,而不需要符号。
  1. (defun c:test2 ()
  2. ;;  CAB version 1.3
  3. ;;  Calling routine to pass a tangent point (p1) & offset distance (od)
  4. ;;  Routine will allow user to stretch outer circle using diameter
  5. ;;  Note if offset distance is a negative number the offset circle
  6. ;;  will be on the outside
  7. ;;  LayName if nil will use the curent layer
  8. ;;  Returns the 2nd pick point
  9. (defun ghostCircle (p1 od LayName / *error* p2 d1 c1 c2 el1 el2 gr rMin)
  10.    (defun *error* (msg)
  11.      (if (not
  12.            (member msg '("Console break" "Function cancelled" "quit / exit abort" "" nil))
  13.          )
  14.        (princ (strcat "\nError: " msg))
  15.      )
  16.      (and c1 (entdel c1))
  17.      (and c2 (entdel c2))
  18.      (princ)
  19.    )     ; end error function
  20.    
  21.    (or layName (setq layName (getvar "clayer")))
  22.    (setq rMin 0.001) ; Minimum Radius allowed
  23.    (setq c1
  24.           (entmakex (list (cons 0 "CIRCLE")
  25.                           (cons 6 "BYLAYER")
  26.                           (cons 8 LayName)
  27.                           (cons 10 p1)
  28.                           (cons 39 0.0)
  29.                           (cons 40 rMin) ; radius
  30.                           (cons 62 256)
  31.                           (cons 210 (list 0.0 0.0 1.0))
  32.                     )
  33.           )
  34.    )
  35.    (setq c2
  36.           (entmakex (list (cons 0 "CIRCLE")
  37.                           (cons 6 "BYLAYER")
  38.                           (cons 8 LayName)
  39.                           (cons 10 p1)
  40.                           (cons 39 0.0)
  41.                           (cons 40 rMin) ; radius
  42.                           (cons 62 256)
  43.                           (cons 210 (list 0.0 0.0 1.0))
  44.                     )
  45.           )
  46.    )
  47.    (setq el1 (entget c1)
  48.          el2 (entget c2)
  49.    )
  50.    ;;  p1 is a tangent point
  51.    ;;  p2 is a tangent point with center at mid point of p1 p2
  52.    (while (and (setq gr (grread 5)) (= (car gr) 5))
  53.      (cond
  54.        ((> (setq d1 (distance p1 (setq p2 (cadr gr)))) rMin)
  55.         (setq el1 (subst (cons 40 (setq r1 (/ d1 2.))) (assoc 40 el1) el1))
  56.         (setq el1 (entmod (subst (cons 10 (polar p1 (angle p1 p2) r1)) (assoc 10 el1) el1)))
  57.         (entupd (cdr (assoc -1 el1)))
  58.         (cond
  59.           ((< rMin (- d1 (* od 2.)))
  60.            (setq el2 (subst (cons 40 (/ (- d1 (* od 2.)) 2.)) (assoc 40 el2) el2))
  61.            (setq el2 (entmod (subst (assoc 10 el1) (assoc 10 el2) el2)))
  62.            (entupd (cdr (assoc -1 el2)))
  63.           )
  64.           (t ; minimize the inner circle
  65.            (setq el2 (subst (cons 40 rMin) (assoc 40 el2) el2))
  66.            (setq el2 (entmod (subst (assoc 10 el1) (assoc 10 el2) el2)))
  67.            (entupd (cdr (assoc -1 el2)))
  68.           )
  69.         )
  70.        )
  71.        (t ; minimize the outer circle
  72.         (setq el1 (subst (cons 40 rMin) (assoc 40 el1) el1))
  73.         (setq el1 (entmod (subst (cons 10 (polar p1 (angle p1 p2) (/ rMin 2.))) (assoc 10 el1) el1)))
  74.         (entupd (cdr (assoc -1 el1)))
  75.        )
  76.      )
  77.    )
  78.    ;(entdel c1) ; to remove the circle
  79.    ;(entdel c2) ; to remove the circle
  80.    p2
  81. )
  82. (setq pc (getpoint "\nPick center point."))
  83. (princ "\n Select new radius  ")
  84. (setq rad (ghostcircle pc 850.0 "0")) ; Layer name "0"
  85. (princ rad)
  86. (princ)
  87. )
回复

使用道具 举报

2

主题

12

帖子

11

银币

初来乍到

Rank: 1

铜币
15
发表于 2022-7-6 18:17:29 | 显示全部楼层
那么,如果我希望使用的层是“Hulplijnen”,我需要更改什么?
如果你至少能让它在没有符号的情况下折断,那就太棒了!
是否可以将第二个点从切线更改为圆心?
回复

使用道具 举报

CAB

29

主题

781

帖子

430

银币

中流砥柱

Rank: 25

铜币
526
发表于 2022-7-6 18:19:17 | 显示全部楼层
换成这一行。我更新了上面的代码。
  1.   (setq rad (ghostcircle pc 850.0 "Hulplijnen")) ; Layer name "0"

 
我正在将osnap添加到下一个版本中,但我也在为一个漫长的周末打包&可能在我离开之前不会完成。
回复

使用道具 举报

CAB

29

主题

781

帖子

430

银币

中流砥柱

Rank: 25

铜币
526
发表于 2022-7-6 18:22:05 | 显示全部楼层
很少测试。
  1. (defun c:test4 ()
  2. ;;  CAB version 1.4
  3. ;;  Calling routine to pass a tangent point (p1) & offset distance (od)
  4. ;;  Routine will allow user to stretch outer circle using diameter
  5. ;;  Note if offset distance is a negative number the offset circle
  6. ;;  will be on the outside
  7. ;;  LayName if nil will use the curent layer
  8. ;;  os when true will use the osnap if it is active
  9. ;;  Returns the 2nd pick point
  10. (defun ghostCircle (p1 od layName os / *error* get_osmode p2 d1 c1 c2 el1 el2 gr rMin)
  11.    (defun *error* (msg)
  12.      (if (not
  13.            (member msg '("Console break" "Function cancelled" "quit / exit abort" "" nil))
  14.          )
  15.        (princ (strcat "\nError: " msg))
  16.      )
  17.      (and c1 (entdel c1))
  18.      (and c2 (entdel c2))
  19.      (princ)
  20.    )     ; end error function
  21.    
  22.    ;;  CAB  10/5/2006
  23.    ;;
  24.    ;;  Function to return the current osmode setting in the form of a string
  25.    ;;  If (getvar "osmode") = 175
  26.    ;;  (get_osmode)  returns   "_end,_mid,_cen,_nod,_int,_per"
  27.    ;;  Usage
  28.    ;;  (osnap (getpoint) (get_osmode))
  29.    ;;
  30.    (defun get_osmode (/ cur_mode mode$)
  31.      (setq mode$ "")
  32.      (if (< 0 (setq cur_mode (getvar "osmode")) 16383)
  33.        (mapcar
  34.          '(lambda (x)
  35.             (if (not (zerop (logand cur_mode (car x))))
  36.               (setq mode$ (strcat mode$ (cadr x)))
  37.             ) )
  38.          '((0 "_non,") (1 "_end,") (2 "_mid,") (4 "_cen,") (8 "_nod,") (16 "_qua,")
  39.            (32 "_int,") (64 "_ins,") (128 "_per,") (256 "_tan,") (512 "_nea,")
  40.            (1024 "_qui,") (2048 "_app,") (4096 "_ext,") (8192 "_par") )
  41.        )
  42.      )
  43.      mode$
  44.    )
  45.    (defun CircleUpdate (p1 p2 od rMin el1 el2 / d1 gr c1 c2)
  46.      (cond
  47.        ((> (setq d1 (distance p1 p2)) rMin)
  48.         (setq el1 (subst (cons 40 (setq r1 (/ d1 2.))) (assoc 40 el1) el1))
  49.         (setq el1 (entmod (subst (cons 10 (polar p1 (angle p1 p2) r1)) (assoc 10 el1) el1)))
  50.         (entupd (cdr (assoc -1 el1)))
  51.         (cond
  52.           ((< rMin (- d1 (* od 2.)))
  53.            (setq el2 (subst (cons 40 (/ (- d1 (* od 2.)) 2.)) (assoc 40 el2) el2))
  54.            (setq el2 (entmod (subst (assoc 10 el1) (assoc 10 el2) el2)))
  55.            (entupd (cdr (assoc -1 el2)))
  56.           )
  57.           (t ; minimize the inner circle
  58.            (setq el2 (subst (cons 40 rMin) (assoc 40 el2) el2))
  59.            (setq el2 (entmod (subst (assoc 10 el1) (assoc 10 el2) el2)))
  60.            (entupd (cdr (assoc -1 el2)))
  61.           )
  62.         )
  63.        )
  64.        (t ; minimize the outer circle
  65.         (setq el1 (subst (cons 40 rMin) (assoc 40 el1) el1))
  66.         (setq el1 (entmod (subst (cons 10 (polar p1 (angle p1 p2) (/ rMin 2.))) (assoc 10 el1) el1)))
  67.         (entupd (cdr (assoc -1 el1)))
  68.        )
  69.      )
  70.      p2
  71.    )
  72.    (or layName (setq layName (getvar "clayer")))
  73.    (setq rMin 0.001) ; Minimum Radius allowed
  74.    (setq c1
  75.           (entmakex (list (cons 0 "CIRCLE")
  76.                           (cons 6 "BYLAYER")
  77.                           (cons 8 layName)
  78.                           (cons 10 p1)
  79.                           (cons 39 0.0)
  80.                           (cons 40 rMin) ; radius
  81.                           (cons 62 256)
  82.                           (cons 210 (list 0.0 0.0 1.0))
  83.                     )
  84.           )
  85.    )
  86.    (setq c2
  87.           (entmakex (list (cons 0 "CIRCLE")
  88.                           (cons 6 "BYLAYER")
  89.                           (cons 8 layName)
  90.                           (cons 10 p1)
  91.                           (cons 39 0.0)
  92.                           (cons 40 rMin) ; radius
  93.                           (cons 62 256)
  94.                           (cons 210 (list 0.0 0.0 1.0))
  95.                     )
  96.           )
  97.    )
  98.    (setq el1 (entget c1)
  99.          el2 (entget c2)
  100.    )
  101.    ;;  p1 is a tangent point
  102.    ;;  p2 is a tangent point with center at mid point of p1 p2
  103.    (while (and (setq gr (grread 5)) (= (car gr) 5))
  104.      (setq p2 (CircleUpdate p1 (cadr gr) od rMin el1 el2))
  105.    )
  106.    ;(entdel c1) ; to remove the circle
  107.    ;(entdel c2) ; to remove the circle
  108.    (setq p2 (if os (osnap p2 (get_osmode))p2))
  109.    (or p2 (setq p2 (cadr gr))) ; catch any error with point
  110.    (CircleUpdate p1 p2 od rMin el1 el2)
  111.    p2
  112. )
  113. (setq pc (getpoint "\nPick center point."))
  114. (princ "\n Select new radius  ")
  115. (setq rad (ghostcircle pc 850.0 "0" t)) ; Layer name "0", t= use osmode if on
  116. (princ rad)
  117. (princ)
  118. )
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-4 19:07 , Processed in 0.996037 second(s), 70 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表