乐筑天下

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

[编程交流] 多弧圆角?

[复制链接]

6

主题

122

帖子

118

银币

初来乍到

Rank: 1

铜币
30
发表于 2022-7-6 09:40:50 | 显示全部楼层
我也一直在等待一个例程,从现有的弧创建相切弧。
附加的例程执行此操作,但它使用grreead方法,因此无法输入指定半径。
 
DTA启动
 
  1. ;*************************************************************
  2. ;* DTanArc.lsp                        (c) 2010  Lloyd Beachy *
  3. ;*                                    questecheng2@gmail.com *
  4. ;* --------------------------------------------------------- *
  5. ;* A routine to draw a tangent arc from the endpoint of an   *
  6. ;* existing line or arc.  The tangency point can be adjusted *
  7. ;* dynamically with the "+" & "-" keys.                      *
  8. ;*************************************************************
  9. ;main function
  10. (defun C:DTA (/ osm osm2 cmd ent sel_pt _type end1 end2 pt1 _cen _rad _ang1 _ang2 _quit mpt arc)
  11. (setq osm(getvar "osmode")                        ;record original settings
  12. osm2(find_osm osm)
  13. cmd(getvar "cmdecho"))
  14. (setvar "osmode" 0)
  15. (setvar "cmdecho" 0)
  16. (setq ent(val_entsel "\nSelect a line or arc:  " 0 "LINE,ARC");filtered entsel
  17. sel_pt(cadr ent)                        ;selection point
  18. ent(entget(car ent))                        ;entity data
  19. _type(cdr(assoc 0 ent))                        ;entity type
  20. end3(cadr(grread t 1 0)))                ;endpoint of new arc
  21. (cond((= _type "LINE"); --------------------------------------------- LINE
  22. (setq end1(cdr(assoc 11 ent))                ;endpoint1
  23.       end2(cdr(assoc 10 ent)))                ;endpoint2
  24. (if(<(distance end2 sel_pt)(distance end1 sel_pt));if end2 is closest to sel_pt...
  25.   (setq pt1 end2 end2 end1 end1 pt1))        ;reverse endpoints
  26. (setq ang(angle end2 end1))                ;tangency angle of new arc
  27. (while(null _quit)(dta_grread))                ;enter preview loop
  28. );end "LINE" cond
  29.       ((= _type "ARC"); ---------------------------------------------- ARC
  30. (setq _cen(cdr(assoc 10 ent))                ;center point
  31.       _rad(cdr(assoc 40 ent))                ;radius
  32.       _ang1(assoc 50 ent)                ;start angle
  33.       _ang2(assoc 51 ent)                ;end angle
  34.       end1(polar _cen(cdr _ang1)_rad)        ;endpoint1
  35.       end2(polar _cen(cdr _ang2)_rad))        ;endpoint2
  36. (if(<(distance end2 sel_pt)(distance end1 sel_pt));if end2 is closest to sel_pt...
  37.   (setq end1 end2 _ang1 _ang2 ang(+(cdr _ang1)(* pi 0.5)));reverse points then find tangency angle of new arc
  38.   (setq ang(+(cdr _ang1)(* pi 1.5))))        ;find tangency angle of new arc
  39. (while(null _quit)(dta_grread))                ;enter preview loop
  40. ));end entity type cond
  41. (command ".draworder" (ssadd(cdr(assoc -1 arc))(ssadd(cdr(assoc -1 ent)))) "" "front");move new arc and selected entity to front
  42. (redraw)
  43. (setvar "osmode" osm)                                ;restore settings...
  44. (setvar "cmdecho" cmd)
  45. (princ)
  46. );end C:DTA
  47. (defun dta_grread (/ val end3 _end3 dist)
  48. (setq val(grread t 3 0))                        ;read user action
  49. (cond((= 5(car val));------------------------------------------------ Cursor moved
  50. (if arc(entmod(subst(cons 40 0.01)(assoc 40 arc)arc)));change preview arc to not interfere with osnap point
  51. (setq _end3(osnap(cadr val)osm2)        ;find osnap point
  52.       end3(if _end3 _end3(cadr val)))        ;use osnap point if defined, otherwise, use actual point
  53. (if arc(entmod arc))                        ;restore preview arc
  54. );end move cond
  55.       ((= 2(car val));------------------------------------------------ Key pressed
  56. (setq dist(*(getvar "viewsize")0.008))        ;incrimental distance
  57. (if(= 45(cadr val))                        ;if "-" was pressed...
  58.   (setq dist(* dist -1))                ;set dist to negative
  59.   (if(= 13(cadr val))                        ;if "Enter" was pressed...
  60.     (setq dist nil _quit t)                ;set flag to exit loop
  61.     (if(/= 43(cadr val))                ;if "+" was not pressed...
  62.       (setq dist nil)                        ;clear dist value
  63.     );end "+" if
  64.   );end "Enter" if
  65. );end "-" if
  66. (if dist                                ;if dist is still set...
  67.   (cond((= _type "LINE");---Original entity was a line
  68.         (setq end1(polar end1 ang dist)        ;new line endpoint
  69.               ent(subst(cons 10 end1)(assoc 10 ent)ent);update endpoint1
  70.               ent(entmod(subst(cons 11 end2)(assoc 11 ent)ent)));update endpoint2 & update original line
  71.        );end "LINE" cond
  72.        ((= _type "ARC");---Original entity was an arc
  73.         (if(= 51(car _ang1))                ;update variables based on original arc's direction
  74.           (setq _ang1(cons 51(+(cdr _ang1)(/ dist _rad)));new ending angle
  75.                 end1(polar _cen(cdr _ang1)_rad);new endpoint
  76.                 ang(+(cdr _ang1)(* pi 0.5));new tangency angle
  77.                 ent(entmod(subst _ang1(assoc 51 ent)ent)));update original arc
  78.           (setq _ang1(cons 50(-(cdr _ang1)(/ dist _rad)));new ending angle
  79.                 end1(polar _cen(cdr _ang1)_rad);new endpoint
  80.                 ang(+(cdr _ang1)(* pi 1.5));new tangency angle
  81.                 ent(entmod(subst _ang1(assoc 50 ent)ent)));update original arc
  82.         )
  83.    ));end "ARC" cond
  84. );end dist if
  85.       );end key cond
  86.       ((= 3(car val));------------------------------------------------ Point selected
  87. (if arc(entmod(subst(cons 40 0.01)(assoc 40 arc)arc)));change preview arc to not interfere with osnap point
  88. (setq _end3(osnap(cadr val)osm2)        ;find osnap point
  89.       end3(if _end3 _end3(cadr val))        ;use osnap point if defined, otherwise, use actual point
  90.       _quit t)                                ;set _quit flag
  91. (if arc(entmod arc))                        ;restore preview arc
  92.       );end point cond
  93. );end cond
  94. (if end3                                        ;if end3 is defined,
  95.    (if(and(null(equal ang(angle end3 end1)0.001));both endpoints are not in-line with tangency angle, and
  96.    (/= 0.0(distance end1 end3)))        ;endpoints are not identical...
  97.      (dta_preview end1 ang end3)                ;then, update preview arc
  98.    );end if
  99. );end end3 if
  100. );end dta_grread
  101. ;build string value that matches "osmode" value (for use with "osnap" function)
  102. (defun find_osm (osm / osm2)
  103. (setq osm2 "")
  104. (if(< osm 16384)
  105.    (foreach _code '((8192 "par")(4096 "ext")(2048 "app")(1024 "")(512 "nea")(256 "tan")(128 "per")(64 "ins")(32 "int")(16 "qua")(8 "nod")(4 "cen")(2 "mid")(1 "end"))
  106.      (if(>= osm(car _code))
  107. (setq osm(- osm(car _code))
  108.       osm2(strcat osm2(if(and(/= osm2 "")(/= (cadr _code)""))"," "")(cadr _code)))
  109.      );end if
  110.    );end foreach
  111. );end if
  112. osm2                                                ;return string value
  113. );end find_osm
  114. ;modify preview arc to match supplied endpoints and tangency angle
  115. (defun dta_preview (end1 ang end3 / mpt cen ang1 ang2 ang3 rad pt1 pt2)
  116. (redraw)
  117. (setq ang1(angle end1 end3)                        ;cord angle
  118. mpt(polar end1 ang1(/(distance end1 end3)2.0));cord midpoint
  119. cen(inters end1 (polar end1(+ ang(* pi 0.5))1.0) mpt (polar mpt(+ ang1(* pi 0.5))1)nil);arc centerpoint
  120. ang1(angle cen end1)                        ;start angle of arc
  121. ang2(angle cen end3)                        ;end angle of arc
  122. rad(distance cen end1)                        ;arc radius
  123. pt1(polar end1 ang 1.0)                        ;1st check point (to test arc direction)
  124. pt2(polar cen (- ang1 0.0001) rad))        ;2nd check point (to test arc direction)
  125. (if(> 1.0(distance pt1 pt2))                        ;if arc direction is reversed...
  126.    (setq ang3 ang1 ang1 ang2 ang2 ang3))        ;reverse starting and ending angles
  127. (grdraw end1(polar end1(angle end1 cen)(*(getvar "viewsize")0.04))6 1);show tangency reference line
  128. (if(null arc)                                        ;if new arc does not exist...
  129.    (setq arc(command ".arc" "c" cen (polar cen ang1 rad)(polar cen ang2 rad));draw new arc
  130.   arc(entget(ssname(ssget "l")0)))        ;new arc entity data
  131.    (setq arc(subst(cons 10 cen)(assoc 10 arc)arc);update data with new centerpoint
  132.   arc(subst(cons 40 rad)(assoc 40 arc)arc);update data with new radius
  133.   arc(subst(cons 50 ang1)(assoc 50 arc)arc);update data with new start angle
  134.   arc(entmod(subst(cons 51 ang2)(assoc 51 arc)arc)));update data with new end angle & update arc
  135. );end arc if
  136. );end dta_preview
  137. ;Select an entity with a validation requirement.                                  ;
  138. ; -> function requires these arguments: (val_entsel "prompt" group_code value)    ;
  139. ;The following examples will allow selection of a specific type(s) or color       ;
  140. ;  (val_entsel "\nSelect a line, arc or polyline:  " 0 "LWPOLYLINE,LINE,ARC")     ;
  141. ;  (val_entsel "\nSelect a red object:  " 62 1)                                   ;
  142. (defun val_entsel (_prompt _code _value / ent _type)
  143. (while(null ent)
  144.    (setq ent(entsel _prompt))
  145.    (if ent                        ;if object was selected...
  146.      (progn                        ;check against validation argument
  147. (setq _type(cdr(assoc _code(entget(car ent)))))
  148. (if(=(type _type)'STR)        ;if not valid, set ent nil
  149.   (if(null(vl-remove-if-not '(lambda(item)(if(= _code(car item))(if(wcmatch(strcase(cdr item))(strcase _value))t)))(entget(car ent))))
  150.     (setq ent nil)
  151.     );end if
  152.   (if(/= _type _value)(setq ent nil))
  153. );end if
  154. (if(null ent)                ;print warning if ent was not valid
  155.   (princ "\nObject was not a valid type")
  156. );end if
  157.      );end progn
  158.      (princ "No object selected!")
  159.    );end if
  160. );end while
  161. ent                                ;return entity name and selection point
  162. );end val_entsel
回复

使用道具 举报

6

主题

122

帖子

118

银币

初来乍到

Rank: 1

铜币
30
发表于 2022-7-6 09:47:25 | 显示全部楼层
这是我在Cadalyst的网站上找到的一个。我只把其中3个提示改成了英语。。。
  1. ;;; CADALYST 05/08  www.cadalyst.com/code
  2. ;;; Tip 2290: Arctodo.LSP        Tangent Arc Generators, File 1 of 5  (c) 2008 Rogelio Bravo
  3. ;; ARCTODO draws an arc tangent to any kind of object
  4. ;; picking any other point as end point of arc
  5. ;; written by Rogelio Bravo, Spain
  6. (defun C:arctodo ()
  7.   (graphscr)
  8. (vl-load-com)
  9. (setq obj (car (entsel "\nPick base entity for arc:")))
  10. (setq ref (getvar "osmode"));almacena valor inicial de osmode
  11. (command "_osnap"  "_end,_nea");establece nuevos refent
  12. (setq ptan (getpoint "\nPick, on entity, initial point of arc:"))
  13. (setvar "osmode" ref);restablece valores iniciales de osmode
  14. (setq pam (vlax-curve-getParamAtPoint obj ptan))
  15. (setq vtr (vlax-curve-getFirstDeriv obj pam));;obtengo el vector de la tangente
  16. (setq ang (angle '(0 0 0) vtr)); angulo recta
  17. ;;(setq ref (getvar "osmode"));almacena valor inicial de osmode
  18. ;;(command "_osnap"  "_end,_nea");establece nuevos refent
  19. ;;(setvar "osmode" ref);restablece valores iniciales de osmode
  20. (setq pt4 (getpoint "\nSelect arc endpoint: "))
  21. (command "_arc" ptan "_e" pt4 "_d" (/ (* 180.0 ang) pi))
  22. (initget 6 "Y N")
  23. (if (null (setq resp (getkword "\nIs arc oriented correctly? (Y/N)<Y>:" )))
  24.      (setq resp "Y")
  25. )
  26. (while (/= resp "Y")
  27.   (setq ang (+ ang  pi))
  28.   (command "_erase" "_l" "")
  29.   (command "_arc" ptan "_e" pt4 "_d"  (/ (* 180.0 ang) pi))
  30.   (initget 6 "Si No")
  31.   (if (null (setq resp (getkword "\nIs arc oriented correctly? (Y/N)<Y>:" )))
  32.      (setq resp "Y")
  33.   )
  34. );end while
  35. )
回复

使用道具 举报

16

主题

47

帖子

31

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
80
发表于 2022-7-6 09:51:18 | 显示全部楼层
不错的程序,但它们都要求您指定切线。我希望autocad为我做到这一点。哈哈。
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-6 09:53:39 | 显示全部楼层
有一个几何解,将所有3个弧中心连接起来,使边的三角形长度为R1+R3 R2+R2 3rd centpt centpt,我只使用ttr,可能有一天没有足够的需求来编写lisp。请注意,尽管这个问题有多达4种解决方案,但我知道我们的其他民用软件可以根据您的需要解决这个问题。
 
快速绘制两条弧,通过圆ttr添加第三条弧,然后添加连接所有3个中心。新弧的中心点的解决方案是rad1+newrad与rad2+newrad相交,有两个解决方案,绘制几个圆,很容易看到如何实现。现在去找时间。
 
快到了,但现在是一个时钟,所以也许其他人会来接
 
  1. (vl-load-com)
  2. (setq oAcad (vlax-get-acad-object)
  3. oDoc (vla-get-activedocument oAcad)
  4. )
  5. (setq pickobj (entsel "\nPick arc 1 :"))
  6. (setq obj1 (vlax-ename->vla-object (car pickobj)))
  7. (setq pickpt1 (cadr pickobj))
  8. (setq cenpt1 (vla-get-center obj1)) ; returns variant center pt
  9. (setq rad1 (vla-get-radius obj1))   ; returns rad
  10. (setq pickobj (entsel "\nPick arc 2 :"))
  11. (setq obj2 (vlax-ename->vla-object (car pickobj)))
  12. (setq pickpt2 (cadr pickobj))
  13. (setq cenpt2 (vla-get-center obj2) )
  14. (setq rad2 (vla-get-radius obj2))
  15. (setq newrad (getreal "\nEnter radius of extra arc " ))
  16. (setq rad3 (+ rad1 newrad))
  17. (setq rad4 (+ rad2 newrad))
  18. (setq CircleObject (vla-addCircle
  19. (vla-get-ModelSpace oDoc)
  20. cenpt1 rad4 )
  21. )
  22. ;(command "Circle" cenpt1 rad4)
  23. (setq obj3 (vlax-ename->vla-object (entlast)))
  24. (setq CircleObject (vla-addCircle
  25. (vla-get-ModelSpace oDoc)
  26. cenpt2 rad3                           
  27. )
  28. )
  29. ;(command "Circle" cenpt2 rad3)
  30. (setq obj4 (vlax-ename->vla-object (entlast)))
  31. (setq intpt1 (vlax-invoke obj4 'intersectWith obj3 acExtendThisEntity)) ; returns two soloutions
  32. ;(entdel obj4)
  33. ;(entdel obj3)
  34. (setq xy1 (list (nth 0 intpt1)(nth 1 intpt1)))
  35. (setq xy2 (list (nth 3 intpt1)(nth 4 intpt1)))
  36. (command "Line" xy1 xy2 "")
  37. (command "line" cenpt1 cenpt2 xy1 cenpt1 "")
  38. (command "line" cenpt1 cenpt2 xy2 cenpt1 "")
  39. (princ)
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-7-7 20:26 , Processed in 0.709636 second(s), 69 queries .

© 2020-2025 乐筑天下

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