乐筑天下

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

[编程交流] 请给我一些帮助-怎么可能

[复制链接]

7

主题

39

帖子

32

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 17:32:42 | 显示全部楼层 |阅读模式
大家好!
 
我为这些例程编写的上一篇文章的标题不再合适。
 
对于如何使代码更高效,如有任何帮助,我们将不胜感激。例行程序只做他们应该做的。附加的图片应该有助于传达这些例程的功能。
 
插入块:
183244f1j2822az62jaljr.png
 
通过“缩放”命令将圆的直径更改为与现有圆相同的直径:
183245ulxjj77llgl53djo.png
 
通过“拉伸”命令在垂直和水平方向上将圆移动得更近:
183246puhlu6l6ll1zcluu.png
 
  1. ;; Test Program  -  Lee Mac
  2. ;;;(defun c:interset ( / sel )
  3. ;;;    (if (setq sel (ssget))
  4. ;;;        (foreach pnt (LM:intersectionsinset sel)
  5. ;;;            (entmake (list '(0 . "POINT") (cons 10 pnt)))
  6. ;;;        )
  7. ;;;    )
  8. ;;;    (princ)
  9. ;;
  10. ;;;(vl-load-com) (princ)
  11. (defun c:interset (/ sel)
  12. (setvar "cmdecho" 0)
  13. (setq cc1 (ssget "_X" '((0 . "CIRCLE"))))
  14. (command "-insert" "*clover chain.dwg" pause 1 "")
  15. (setq circle (ssname cc1 0))
  16. (setq rad (cdr (assoc 40 (entget circle))))
  17. (setq newrad (/ rad 0.5))
  18. (setq sel (ssget "X" '((0 . "CIRCLE,LINE") (8 . "daisy chain"))))
  19. (LM:intersectionsinset2 sel)
  20. (command "._erase" (ssget "X" '((0 . "LINE") (8 . "daisy chain"))) "")
  21. (setq z 0)
  22. (setq ss (ssget "X" '((0 . "CIRCLE") (8 . "daisy chain"))))
  23. (repeat (sslength ss)
  24.    (setq ename (ssname ss z)
  25.   circen (cons (list (cdr (assoc 10 (entget ename)))) circen)
  26.   z (1+ z)
  27.    )   
  28. )
  29. (setq circen (reverse circen))
  30. (setq cpt1 (nth 0 (nth 0 circen)))
  31. (setq cpt2 (nth 0 (nth 1 circen)))
  32. (setq cpt3 (nth 0 (nth 2 circen)))
  33. (setq cpt4 (nth 0 (nth 3 circen)))
  34. (setq dist (distance cpt1 cpt2))
  35. (setq stretchdist (/ (- (- dist (* 2 rad)) 1) 2))
  36. (setq cpt1move (strcat "@" (rtos stretchdist) "," (rtos stretchdist)))
  37. (setq cpt2move (strcat "@" (rtos (- stretchdist)) "," (rtos stretchdist)))
  38. (setq cpt3move (strcat "@" (rtos stretchdist) "," (rtos (- stretchdist))))
  39. (setq cpt4move (strcat "@" (rtos (- stretchdist)) "," (rtos (- stretchdist))))
  40. (setq atomx (nth 0 cpt1))
  41. (setq atomy (nth 1 cpt1))
  42. (setq cpt1x (+ (- rad) atomx))
  43. (setq cpt1y (+ (- rad) atomy))
  44. (setq ll (list cpt1x cpt1y))
  45. (setq cpt1x (+ rad atomx))
  46. (setq cpt1y (+ rad atomy))
  47. (setq ur (list cpt1x cpt1y))
  48. (command "stretch" "C" ll ur "" cpt1 cpt1move)
  49. (setq atomx (nth 0 cpt2))
  50. (setq atomy (nth 1 cpt2))
  51. (setq cpt2x (+ (- rad) atomx))
  52. (setq cpt2y (+ (- rad) atomy))
  53. (setq ll (list cpt2x cpt2y))
  54. (setq cpt2x (+ rad atomx))
  55. (setq cpt2y (+ rad atomy))
  56. (setq ur (list cpt2x cpt2y))
  57. (command "stretch" "C" ll ur "" cpt2 cpt2move)
  58. (setq atomx (nth 0 cpt3))
  59. (setq atomy (nth 1 cpt3))
  60. (setq cpt3x (+ (- rad) atomx))
  61. (setq cpt3y (+ (- rad) atomy))
  62. (setq ll (list cpt3x cpt3y))
  63. (setq cpt3x (+ rad atomx))
  64. (setq cpt3y (+ rad atomy))
  65. (setq ur (list cpt3x cpt3y))
  66. (command "stretch" "C" ll ur "" cpt3 cpt3move)
  67. (setq atomx (nth 0 cpt4))
  68. (setq atomy (nth 1 cpt4))
  69. (setq cpt4x (+ (- rad) atomx))
  70. (setq cpt4y (+ (- rad) atomy))
  71. (setq ll (list cpt4x cpt4y))
  72. (setq cpt4x (+ rad atomx))
  73. (setq cpt4y (+ rad atomy))
  74. (setq ur (list cpt4x cpt4y))
  75. (command "stretch" "C" ll ur "" cpt4 cpt4move)
  76. (setvar "cmdecho" 1)
  77. (princ)
  78. )
  79. (vl-load-com)
  80. (princ)

 
它附带了几个子程序,都是从李的网站上获得的。
 
  1. ;; Intersections  -  Lee Mac
  2. ;; Returns a list of all points of intersection between two objects
  3. ;; for the given intersection mode.
  4. ;; ob1,ob2 - [vla] VLA-Objects
  5. ;;     mod - [int] acextendoption enum of intersectwith method
  6. (defun LM:intersections        (ob1 ob2 mod / lst rtn int)
  7. (setq lst (vlax-invoke ob1 'intersectwith ob2 mod))
  8. (repeat (/ (length lst) 3)
  9.    (setq rtn (cons (list (car lst)
  10.                   (cadr lst)
  11.                   (caddr lst)
  12.             )
  13.             rtn
  14.       )
  15.   int (vlax-3d-point lst)
  16.    )
  17.    (vla-ScaleEntity ob1 int newrad)
  18. )
  19. )

 
还有一个。。。
 
  1. ;; Intersections in Set  -  Lee Mac
  2. ;; Returns a list of all points of intersection between all objects in a supplied selection set.
  3. ;; sel - [sel] Selection Set
  4. (defun LM:intersectionsinset2 (sel / id1 id2 ob1 ob2 rtn)
  5. (repeat (setq id1 (sslength sel))
  6.    (setq ob1 (vlax-ename->vla-object (ssname sel (setq id1 (1- id1)))))
  7.    (if        (= (setq ob1type (vla-get-ObjectName ob1)) "AcDbLine")
  8.      (princ)
  9.      (progn
  10. (setq sslist (cons (ssname sel id1) sslist))
  11. (repeat        (setq id2 id1)
  12.   (setq        ob2 (vlax-ename->vla-object
  13.               (ssname sel (setq id2 (1- id2)))
  14.             )
  15.   )
  16.   (if (= (setq ob2type (vla-get-ObjectName ob2)) "AcDbCircle")
  17.     (princ)
  18.     (LM:intersections ob1 ob2 acextendnone)
  19.   )                                ;end if
  20. )                                ;end repeat
  21.      )                                        ;progn
  22.    )                                        ;end if
  23. )                                        ;end repeat
  24.                                 ;(apply 'append (reverse rtn))  
  25. )

 
如果需要任何澄清,请告诉我。
 
非常感谢。
 
起草人Joe
 
(另外,我还想知道在发布帖子时如何使用“标签”以及它们何时合适?)
回复

使用道具 举报

18

主题

1529

帖子

973

银币

中流砥柱

Rank: 25

铜币
649
发表于 2022-7-5 17:58:02 | 显示全部楼层
为什么你从“错误”的区块开始?
你考虑过使用动态块吗?
回复

使用道具 举报

18

主题

1529

帖子

973

银币

中流砥柱

Rank: 25

铜币
649
发表于 2022-7-5 18:10:47 | 显示全部楼层
... 顺便说一句:似乎两个LM:*函数都已修改。
回复

使用道具 举报

7

主题

39

帖子

32

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 18:26:12 | 显示全部楼层
你好
 
每次插入块时,圆将需要新的直径,每个直径相同,并且始终距每个边缘1“。
 
我以前没有使用过动态块,我将研究它们。
 
非常感谢。
回复

使用道具 举报

7

主题

39

帖子

32

银币

初来乍到

Rank: 1

铜币
35
发表于 2022-7-5 18:44:03 | 显示全部楼层
对人们只是“寻找”直线和圆的交点。这加快了调试时间。大套路中的一大块将转移到另一个套路。我只是碰巧开始在那里编码,当时我想我不会添加太多。
 
谢谢你的提问!
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-13 05:33 , Processed in 0.401709 second(s), 65 queries .

© 2020-2025 乐筑天下

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