乐筑天下

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

[编程交流] 插入块-高级

[复制链接]

66

主题

1552

帖子

1514

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
325
发表于 2022-7-5 18:28:15 | 显示全部楼层 |阅读模式
你好
我需要在线(表示网格)的交点处放置一个块(表示柱)。
我还需要在每个线段的中点放置另一个块(代表梁)。
CONTRU 2010。图纸
回复

使用道具 举报

11

主题

93

帖子

82

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
55
发表于 2022-7-5 19:08:55 | 显示全部楼层
 
捕捉模式打开,正交模式打开。
设置捕捉模式中点并选择垂直)如果块基点位于腹板的精确中点,则该选项应有效。
 
另一种实现方法是将其插入图形中的任何位置,并使用基点进行复制,如果按上述方式设置捕捉模式,则在需要的地方进行粘贴
 
HTH公司
 
r
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
325
发表于 2022-7-5 19:35:26 | 显示全部楼层
我在网上找到了类似的代码来满足我的需要。
部分解决了列问题(我对其进行了严重修改):
 
  1. (vl-load-com)
  2. ;; Place block on intersection of lines
  3. ;; credits: Bill Kramer
  4. ;; Find all intersections between objects in
  5. ;; the selection set SS.
  6. ;;
  7. ;; ---------------------------------------------- BEGIN LISTING 1
  8. ;;
  9. (defun get_all_inters_in_SS (SS /
  10.                      SSL ;length of SS
  11.                      PTS ;returning list
  12.                      aObj1 ;Object 1
  13.                      aObj2 ;Object 2
  14.                      N1  ;Loop counter
  15.                      N2  ;Loop counter
  16.                      iPts ;intersects
  17.                          C1 C2 C3
  18.                      )
  19. (defun iL->L (iPts / Pts) ; convert coordlist -> pointlist
  20. (while (> (length iPts) 0)
  21. (setq Pts (cons (list        (car iPts)
  22.                                         (cadr iPts)
  23.                                         (caddr iPts))
  24.                                 Pts)
  25.     iPts (cdddr iPts)))
  26. Pts
  27. )
  28. (defun iL2->L (iPts / Pts) ; convert coordlist -> pointlist 2D
  29. (while (> (length iPts) 0)
  30. (setq Pts (cons (list        (car iPts)
  31.                                         (cadr iPts)
  32.                                         '0.0)
  33.                                 Pts)
  34.     iPts (cddr iPts)))
  35. Pts
  36. )
  37. (defun DelDup ( l / x r ) ; remove duplicates
  38.    (while l
  39.        (setq x (car l)
  40.              l (vl-remove x (cdr l))
  41.              r (cons x r)
  42.        )
  43.    )
  44.    (reverse r)
  45. )
  46. (setq N1 0 ;index for outer loop
  47. SSL (sslength SS))
  48. ; Outer loop, first through second to last
  49. (while (< N1 (1- SSL)) ;  nebo <= ?
  50.    ; Get object 1, convert to VLA object type
  51.    (setq aObj1 (ssname SS N1)
  52.   aObj1 (vlax-ename->vla-object aObj1)
  53.   N2 (1+ N1)) ;index for inner loop
  54.   ; self-intersections:
  55. (if (vlax-property-available-p aObj1 'Coordinates)(progn ; is it a curve? LWPOLY
  56.         (setq C1 (iL2->L (vlax-get aObj1 'Coordinates)))
  57.         (setq C2 (iL->L (vlax-invoke aObj1 'IntersectWith aObj1 0)))
  58.         (setq C3 (vl-remove-if '(lambda ( x ) (member x C1)) C2))
  59. ;                (PRINT C1)(PRINT C2)(PRINT C3)
  60.         (if C3 (foreach x C3 (setq Pts (cons x Pts)))) ; add selfs
  61. ))
  62. (if (= (vlax-get aObj1 'ObjectName) "AcDbSpline")(progn ; SPLINE
  63.         (setq C1 (iL->L (vlax-invoke aObj1 'IntersectWith aObj1 0)))
  64. ;                (PRINT C1)
  65.         (if C1 (foreach x C1 (setq Pts (cons x Pts)))) ; add selfs
  66. ))
  67.    ; Inner loop, go through remaining objects
  68.    (while (< N2 SSL) ; innser loop
  69.      ; Get object 2, convert to VLA object
  70.      (setq aObj2 (ssname SS N2)
  71.     aObj2 (vlax-ename->vla-object aObj2)
  72.     ; Find intersections of Objects
  73.     iPts (vla-intersectwith aObj1
  74.            aObj2 0)
  75.     ; variant result
  76.     iPts (vlax-variant-value iPts))
  77.      ; Variant array has values?
  78.      (if (> (vlax-safearray-get-u-bound iPts 1)
  79.      0)
  80. (progn ;array holds values, convert it
  81.   (setq iPts ;to a list.
  82.          (vlax-safearray->list iPts))
  83.   ;Loop through list constructing points
  84. ;          (setq Pts (iL->L iPts)) ; must be global
  85. ;(if (> (length iPts) 3)(PRINT iPts)) --- LIST DUPLICATE INTERSECTIONS - THE RED/GREEN CASE GIVES TWO INTERSECTIONS !
  86.   (while (> (length iPts) 0)
  87.     (setq Pts (cons (list (car iPts)
  88.                           (cadr iPts)
  89.                           (caddr iPts))
  90.                     Pts)
  91.           iPts (cdddr iPts))
  92.         (if ILSIMPLEMODE (setq iPts nil))  ; ILSIMPLEMODE - take only the first intersection
  93.   )
  94. ))
  95.      (setq N2 (1+ N2))) ;inner loop end
  96.    (setq N1 (1+ N1))) ;outer loop end
  97. Pts) ;return list of points found
  98. ;;-----------------------------------------------   END LISTING 1
  99. ;;
  100. ;; Remaining lines of code for download version, used to demonstrate and test the utility in Listing 1.
  101. ;;
  102. ;; Process - Create drawing with intersecting lines and lwpolylines.
  103. ;;           Load function set
  104. ;;           Run command function INTLINES
  105. ;;           Intersections are marked with POINT objects on current layer
  106. ;;
  107. (defun C:block-on-intersections ( / SS1 RRD PT ptl oldos)
  108. (princ "Select intersecting lines \n")
  109. (setq SS1 (ssget);(ssget "_X");(get_all_lines_as_SS)
  110. PTS (get_all_inters_in_ss SS1)
  111.        )
  112. (setq RRD(car (entsel "\n Select a block :")))
  113. (eq (cdr (assoc 0 (entget RRD))) "INSERT")
  114. (setq ptl (length PTS)   PTS (deldup PTS)) ; duplicates - shouldn't be any
  115. (if (> ptl (length PTS)) (princ (strcat "\n" (itoa (- (length PTS) ptl)) " duplicates removed")))
  116. (vla-startundomark (vla-get-activedocument (vlax-get-acad-object)))
  117. (setvar "CMDECHO" 0)
  118. (setq oldos (getvar "OSMODE"))(setvar "OSMODE" 0)
  119. (foreach PT PTS ;;Loop through list of points
  120.    (command "_INSERT" RRD PT "1" "1" "0" )) ;;Create point object (you can also use INSERT, CIRCLE, etc. here)
  121. ;  (setvar "PDMODE" 34) ;;display points so you can see them
  122. (command "_REGEN")
  123. (setvar "OSMODE" oldos)
  124. (vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
  125. (princ (strcat (itoa (length PTS)) " intersections found."))
  126. (princ)
  127. )
  128. ;;
  129. ;;-----------------------------------------------
  130. ;;  Get all lines and lwpolyline objects in the
  131. ;;  drawing and return as a selection set.
  132. ;;
  133. (defun get_all_Lines_as_SS ()
  134. (ssget "_X" '((0 . "LINE,LWPOLYLINE"))))
  135. ;;
  136. (princ "\n(get_all_inters_in_SS) function and INTLINES command loaded.")
  137. (prin1)
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-12 20:14 , Processed in 0.488720 second(s), 69 queries .

© 2020-2025 乐筑天下

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