明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 490|回复: 4

[提问] 怎么给一个图元增加扩展属性

[复制链接]
发表于 2024-7-29 22:06:06 | 显示全部楼层 |阅读模式
各位大神,请教一下如何给一个图元增加扩展属性,代码应该怎么写?
发表于 2024-7-30 08:33:14 | 显示全部楼层
(entmod elist)
发表于 2024-7-30 09:19:57 | 显示全部楼层
;; | ----------------------------------------------------------------------------
;; | XD_WriteX
;; | ----------------------------------------------------------------------------
;; | Function : Writes extended entity into an entity
;; | Argument : [e]       - entity name
;; |            [xdLst]   - list of data
;; |            [AppName] - Application Name (must be already registered)
;; | Return   : complete entity list is returned if (XD_WriteX ...) is successful,
;; |            else nil is returned
;; | Updated  : August 11, 1998
;; | Comment  : - Program can detect data types (STR, REAL,INT, LIST).
;; |            - Entitiy handles must be prefixed by a "#" sign
;; |              (eg. (XD_WriteX e (list "300XLCU" "#5DE")).
;; |            - 1010 group stores points, which is a list of 3 reals
;; |            - If you want to store a nested list, it should have {}
;; |            - as the first element of the list
;; | e-mail   : rakesh.rao@4d-technologies.com
;; | Web      : www.4d-technologies.com
;; | ----------------------------------------------------------------------------


(defun XD_WriteX (ename xdLst AppName / entl xd)

(setq
        xd   (reverse (XD_WriteX@ xdLst))
        xd   (list -3 (cons AppName xd))
        entl (append (entget ename) (list xd))
)
(entmod entl)
entl
)

)
(defun XD_WriteX@ (xdLst / xd xd1 itm)

(setq xd '())
(foreach itm xdLst
        (cond
                ((and (= (type itm) 'LIST) (= (car itm) "{}"))
                        (setq
                                xd1 (cons (cons 1002 "}") (XD_WriteX@ (cdr itm)))
                                xd1 (append xd1 (list (cons 1002 "{")))
                                xd (append xd1 xd)
                        )
                )
                ((and (= (type itm) 'LIST) (= (length itm) 3))
                        (setq xd (cons (cons 1010 itm) xd))
                )
                ((and (= (type itm) 'STR) (= (substr itm 1 1) "#"))
                        (setq xd (cons (cons 1005 (substr itm 2)) xd))
                )
                ((= (type itm) 'STR)
                        (setq xd (cons (cons 1000 itm) xd))
                )
                ((= (type itm) 'INT)
                        (setq xd (cons (cons 1070 itm) xd))
                )
                ((= (type itm) 'REAL)
                        (setq xd (cons (cons 1040 itm) xd))
                )
        )
)
xd
)
发表于 2024-7-31 14:52:42 | 显示全部楼层
  1. ;语法:
  2. ;(ax:PUTXData Obj DATA)
  3. ;参数:
  4. ;obj:图元名
  5. ;XDATA:扩展数据
  6. ;如:  (("south" (1000 . "204201") (1040 . 1.0))
  7. ;       ("AAAA" (1041 . 562.307)  (1000 . "aaaaa"))
  8. ;       ("BBBB" (1000 . "bbbbbbb"))
  9. ;       ("CCCC" (1041 . 752.569))
  10. ;      )
  11. ;示例:
  12. ;(BF-PutXData myVlaObj '(("south" (1000 . "204201") (1040 . 1.0))))
  13. ;说明:
  14. ;对于图元上已经有的相同注册程序名的XDATA数据会覆盖
  15. ;功能:把扩展数据附着到ACAD图元上
  16. ;函数代码:
  17. (defun BF-PutXData (Obj Data / dxf n i data_i temp1 appid)
  18.   (setq dxf  (entget obj)
  19.    N      (LENgth data)
  20. i      0
  21. data_i '(-3)
  22.   )
  23.   (repeat n
  24.     (setq temp1  (nth i data)
  25.    appid (car temp1)
  26.    data_i (append data_i (list temp1))
  27.    i  (1+ i)
  28.     )
  29.     (regapp appid)
  30.     (entmod (append dxf (list data_i)))
  31.   )

  32. )


发表于 2024-7-31 14:59:47 来自手机 | 显示全部楼层
感谢各位分享,研究一下
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-9-24 11:25 , Processed in 0.211546 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表