乐筑天下

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

[编程交流] 如何使用Att插入块

[复制链接]
Lui

1

主题

2

帖子

1

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 18:45:15 | 显示全部楼层 |阅读模式
大家好,
 
最近我开始用auto lisp编写代码,但由于我的知识还处于非常基础的水平,我一直无法完成我认为很容易的任务。
 
我一直在尝试做的是一个自动lisp,插入一个包含两个链接到多段线的属性的块,这些属性将显示链接到的对象的面积和层名称;因此,如果将此对象更改为其他图层或用户修改多段线,它将自动更新。
 
目前,我已经能够写出以下几行,但我达到了一个点,那就是我无法理解如何覆盖att参数来重新定义与之相关的ID对象名。
 
 
  1. ;DESCRIPTION
  2. ;
  3. ;This lisp places a block with ATTs of "AREA" and "LAYER NAME" that are filled automatically and are related to an specific polyline or hatch defined by the user.
  4. ;
  5. ;NOTES: The block and its ATTs must be defined in the drawing prior to execute this routine.
  6. ;
  7. ;Definition of the lisp and its local variables
  8. (defun c:prueba ()
  9.        
  10. ;Requests the user to select a polyline or hatch and stores the selection into a variable.
  11. (setq OBJ_REF (car (entsel "\n Selecciona una polilinea o un hatch: ")))
  12. ;Shows in the command line the entity name of the selected object.
  13. (print OBJ_REF)(terpri)
  14. ;Shows in the command line the layer name of the selected object.
  15. (princ (strcat "\n El layer del objeto es: "(cdr (assoc 8 (entget OBJ_REF)))))
  16. ;Requests the user to select the point where the block will be inserted and stores it into a variable.
  17. (setq INS_PNT (getpoint "\n Indica el punto de insercion del bloque:"))
  18. ;Inserts the block in the position previously indicated by the user.
  19. (command "._insert" "MA_Tag_Areas" INS_PNT "" "" "")
  20. ;Selects the last entity inserted in the drawing and store its name into a variable.
  21. (setq BLK_NAM (entlast))
  22. (princ "\n El nombre del bloque es: ")(terpri)
  23. (princ BLK_NAM)
  24. (princ "\n ")
  25. Obtains the DXF group doted pairs and stores it into a variable.
  26. (setq BLK_LIST (entget BLK_NAM))
  27. (princ "\n El contenido del bloque es: ")(terpri)
  28. (princ BLK_LIST)
  29. (princ "\n ")
  30. ;Avoids to finish the routine with the text "nill" shown at the command line
  31. (princ)
  32. )

 
 
任何帮助都将不胜感激。
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 19:10:51 | 显示全部楼层
在此处搜索更多Pline区域有许多标记Pline和在Pline改变形状时自动更新区域等的示例。他们使用字段来提供信息。很确定一个真正好的是由GP_。也看看http://www.lee-mac.com
回复

使用道具 举报

4

主题

2143

帖子

2197

银币

限制会员

铜币
-24
发表于 2022-7-5 19:21:38 | 显示全部楼层
请阅读代码发布指南并编辑您的帖子,将代码包含在代码标签中。
回复

使用道具 举报

Lui

1

主题

2

帖子

1

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 19:31:11 | 显示全部楼层
比加尔,
 
感谢您的快速回复。
 
我已经在很多网站上搜索过了,比如李·麦克、AfraLISP、CADnotes等等。问题是,即使我找到了如何编辑属性,我也找不到如何在块内编辑这些属性,以便它们与对象保持链接,或者至少不使用AutoLisp。我已经看到了一些可以使用VisualLisp的解决方案,但实际上我不知道如何在VisualLisp中编码,我不想只是复制/粘贴代码,因为我正在尝试学习,我想完全理解代码。
 
我会继续在这个论坛内搜索,正如你建议的“普林地区”。
 
当心,
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 19:52:51 | 显示全部楼层
这是一个很好的全科医生_
 
  1. ;;   Write the area of the selected polylines in the position of   ;;
  2. ;;   maximum inscribed circle.                                     ;;
  3. ;;                                                                 ;;
  4. ;;   19.01.2013 - Gian Paolo Cattaneo                              ;;
  5. (defun c:arpoly (/ sel poly POLY_vl Dx Dy Lp List_vert_poly list_p_int P_center dist step1 step2)
  6.    (prompt "\nSelect Polyline: ")
  7.    (setq sel (ssget '((0 . "LWPOLYLINE"))))
  8.    (if sel
  9.        (progn
  10.            (repeat (setq :n (sslength sel))
  11.                (setq poly (ssname sel (setq :n (1- :n))))
  12.                (setq jjj 0)
  13.                (setq step1 30) ;--> grid_1 density
  14.                (setq step2 10) ;--> grid_2 density
  15.                (setq POLY_vl (vlax-ename->vla-object POLY))
  16.                (setq list_vert_poly (LM:LWPoly->List POLY))
  17.                (grid_1)   
  18.                (Point_int)
  19.                ;(grid+) ;increase accuracy
  20.                (Point_center)
  21.                (if (= jjj 1) (setq p_prov P_center))
  22.               ;(repeat 2 ;increase accuracy
  23.                    (grid_2)
  24.                    (Point_center)
  25.               
  26.                (entmake
  27.                    (list
  28.                        (cons 0 "TEXT")
  29.                        (cons 8 (getvar "clayer"))
  30.                        (cons 7 (getvar "textstyle"))
  31.                        (cons 10 P_center)
  32.                        (cons 11 P_center)
  33.                        (cons 40 (getvar "textsize"))
  34.                        (cons 72 1)
  35.                        (cons 73 2)
  36.                        (cons 1 (rtos (vlax-curve-getArea poly) 2 2))
  37.                    )
  38.                )
  39.            )
  40.            (princ)
  41.        )
  42.        (alert "No selected lwpolyline")
  43.    )
  44. )        
  45. ;; LWPolyline to Point List  -  Lee Mac
  46. ;; Returns a list of points describing the supplied LWPolyline
  47. (defun LM:LWPoly->List ( ent / der di1 di2 inc lst par rad )
  48.    (setq par 0)
  49.    (repeat (cdr (assoc 90 (entget ent)))
  50.        (if (setq der (vlax-curve-getsecondderiv ent par))
  51.            (if (equal der '(0.0 0.0 0.0) 1e-
  52.                (setq lst (cons (vlax-curve-getpointatparam ent par) lst))
  53.                (if
  54.                    (setq rad (distance '(0.0 0.0) (vlax-curve-getfirstderiv ent par))
  55.                          di1 (vlax-curve-getdistatparam ent par)
  56.                          di2 (vlax-curve-getdistatparam ent (1+ par))
  57.                    )
  58.                    (progn
  59.                        (setq inc (/ (- di2 di1) (1+ (fix (* 10 (/ (- di2 di1) rad (+ pi pi)))))))
  60.                        (while (< di1 di2)
  61.                            (setq lst (cons (vlax-curve-getpointatdist ent di1) lst)
  62.                                  di1 (+ di1 inc)
  63.                            )
  64.                        )
  65.                    )
  66.                )
  67.            )
  68.        )
  69.        (setq par (1+ par))
  70.    )
  71.    (setq x lst)
  72.    lst
  73. )
  74. ; Restituisce una griglia di punti all'interno del getboundingbox della poly selezionata
  75. ; Returns a grid of points within the BoundingBox of the selected poly
  76. (defun grid_1 (/ P1_ P2_ n P> )
  77.    (vla-getboundingbox POLY_vl 'p1 'p2)
  78.    (setq P1_ (vlax-safearray->list p1))
  79.    (setq P2_ (vlax-safearray->list p2))
  80.    (setq P1_ (list (car P1_) (cadr P1_)))
  81.    (setq P2_ (list (car P2_) (cadr P2_)))
  82.    (setq Dx (/ (- (car P2_) (car P1_)) step1))
  83.    (setq Dy (/ (- (cadr P2_) (cadr P1_)) step1))
  84.    (setq n 0)
  85.    (setq P> P1_)
  86.    (setq Lp (list P1_))
  87.    (repeat (* (1+ step1) step1)
  88.        (setq P> (list (+ (car P>) Dx) (cadr P>)))
  89.        (setq Lp (cons P> Lp))
  90.        (setq n (1+ n))
  91.        (if (= n step1)
  92.            (progn
  93.                (setq n 0)
  94.                (setq P1_ (list (car P1_) (+ (cadr P1_) Dy)))
  95.                (setq P> P1_)
  96.                (setq Lp (cons P> Lp))
  97.            )
  98.        )
  99.    )
  100.    (setq Lp (cdr Lp))
  101.    (setq a Lp)
  102. )
  103.   
  104. ; Restituisce una griglia di punti intorno al punto centrale (provvisorio)
  105. ; Returns a grid of points around the center point (provisional)
  106. (defun grid_2 (/ P1_  P> n)
  107.    (setq list_p_int nil)
  108.    (setq P1_ (list (- (car P_center) (* Dx 2)) (- (cadr P_center) (* Dy 2))))
  109.    (setq Dx (/ (* 4 Dx) step2))
  110.    (setq Dy (/ (* 4 Dy) step2))
  111.    (setq n 0)
  112.    (setq P> P1_)
  113.    (setq list_p_int (list P1_))
  114.    (repeat (* (1+ step2) step2)
  115.        (setq P> (list (+ (car P>) Dx) (cadr P>)))
  116.        (setq list_p_int (cons P> list_p_int))
  117.        (setq n (1+ n))
  118.        (if (= n step2)
  119.            (progn
  120.                (setq n 0)
  121.                (setq P1_ (list (car P1_) (+ (cadr P1_) Dy)))
  122.                (setq P> P1_)
  123.                (setq list_p_int (cons P> list_p_int))
  124.            )
  125.        )
  126.    )
  127.    (setq d  list_p_int)
  128. )
  129.    
  130. ; restituisce la lista dei punti interni ad un poligono
  131. ; dati:  - lista coordinate dei punti -> Lp
  132. ;        - lista coordinate vertici poligono -> list_vert_poly
  133. ; Returns the list of inside points
  134. (defun Point_int (/ P_distant n Pr cont attr p# Pa Pa_ Pb )
  135.    (setq P_distant (list (car (getvar "extmax")) (* 2 (cadr (getvar "extmax")))))   
  136.    (setq list_p_int nil)
  137.    (foreach Pr Lp
  138.        (setq cont -1)
  139.        (setq attr 0)
  140.        (setq p# nil)
  141.        (setq Pa (nth (setq cont (1+ cont)) list_vert_poly))
  142.        (setq Pa_ Pa)
  143.        (repeat (length list_vert_poly)
  144.            (setq Pb (nth (setq cont (1+ cont)) list_vert_poly))
  145.            (if (= cont (length list_vert_poly)) (setq Pb Pa_))
  146.            (setq P# (inters Pa Pb Pr P_distant))
  147.            (if (/= P# nil) (setq attr (1+ attr)))
  148.            (setq Pa Pb)
  149.        )
  150.        (if (> (rem attr 2) 0) (setq list_p_int (cons Pr list_p_int)))      
  151.    )
  152.    (setq b list_p_int)
  153. )
  154. ; Infittisce la griglia inserendo altri punti
  155. ; nel centro delle diagonali tra i punti interni
  156. ; Increases the grid density
  157. (defun grid+ (/ G+)
  158.    (setq G+
  159.        (mapcar '(lambda ( x ) (list (+ (car x) (/ Dx 2)) (+ (cadr x) (/ Dy 2)))) list_p_int)
  160.    )
  161.    (setq list_p_int (append G+ list_p_int))
  162.    (setq c list_p_int)
  163. )
  164. ; Da una lista di punti restituisce quello più lontano da un oggetto
  165. ; dati:  - lista dei punti -> list_p_int
  166. ;        - oggetto -> POLY_vl
  167. ; Returns the farthest point from the polyline
  168. (defun Point_center (/ Pa n Pvic)
  169.    (setq Dist 0.0000001)
  170.    (setq P_center nil)
  171.    (foreach Pa list_p_int
  172. (setq Pvic (vlax-curve-getClosestPointTo POLY_vl Pa))
  173.        (if (> (distance Pa Pvic) Dist)
  174.            (progn
  175.                (setq P_center Pa)
  176.                (setq Dist (distance Pa Pvic))
  177.            )
  178.        )
  179.    )
  180.    (setq jjj (1+ jjj))
  181.    (setq pc P_center)
  182. )
  183. (vl-load-com)
  184. (prompt "\n ") (prompt "\n ") (prompt "\n ")
  185. (princ "\nType "ARPOLY" to invoke")
  186. (princ)
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-7-3 20:25 , Processed in 1.322042 second(s), 62 queries .

© 2020-2025 乐筑天下

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