明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 480|回复: 0

[提问] (求助)批量对单个或多个CAD对象扩展数据的读写。谢谢!

[复制链接]
发表于 2022-4-14 23:46 | 显示全部楼层 |阅读模式
求帮忙,让它能实现
①对象扩展数据的读取时,对象有内容时显示原内容,多个对象时,相同则显示内容,不同显示为*
②对多个对象时,批量写入

;;查看/增加/编辑扩展数据
(defun C:ccc ( / allexdata dcl_id editlabel entdata entgrp  exdata m n ss
                                                                                 newallexdata newexdata fn result val_lst value entname tmp
                                                                         )
  (defun getentdxf (ent dxf)
    (cdr (assoc dxf (entget ent '("*"))))
  )
  (defun add_dclrow (dstr) (if dstr (setq val_lst (cons dstr val_lst))))
  (defun getdclvalue ()
    (setq n 1)
    (setq newallexdata '())
    (foreach exdata allexdata
      (setq newexdata '())
      (repeat (length (cdr exdata))
        (setq newexdata (append (list (cons 1000 (get_tile (strcat "eb" (itoa n))))) newexdata))
        (setq n (1+ n))
      )
      (setq newallexdata (append (list (cons (car exdata) (reverse newexdata))) newallexdata))
    )
    (setq newallexdata (cons -3 (reverse newallexdata)))
  )
       
                (setq val_lst nil)
        ;;Dcl文件
                (setq editlabel (strcat (getenv "temp") "\\editlabel.dcl"))
    (add_dclrow "editlabel:dialog{label=\"编辑扩展数据\";")
    (add_dclrow ":row{")
                (add_dclrow (strcat ":boxed_column{label=\"XData" "\";"))
                (add_dclrow (strcat ":edit_box{label=\"编号" "\";key=\"eb1\" ;width=30;}"))
                (add_dclrow (strcat ":edit_box{label=\"名称" "\";key=\"eb2\" ;width=30;}"))
                (add_dclrow (strcat ":edit_box{label=\"规格"  "\";key=\"eb3\" ;width=30;}"))
                (add_dclrow (strcat ":edit_box{label=\"备注"  "\";key=\"eb4\";width=30;}"))
                (add_dclrow "}")
    (add_dclrow "}ok_cancel;}")
    (setq fn (open editlabel "w"))
    (foreach n (reverse val_lst) (write-line n fn))
    (close fn)
    (if (< (setq dcl_id (load_dialog editlabel))
                                        0
        )
      (exit)
    )
    (if (not (new_dialog "editlabel" dcl_id))
      (exit)
    )
       
        (setq n 1)
        (foreach exdata allexdata
                (setq m 1)
                (repeat (length (cdr exdata))
                        (if (= (type (cdr (nth (1- m) (cdr exdata)))) 'STR)
                                (setq value (cdr (nth (1- m) (cdr exdata))))
                                (setq value (rtos (cdr (nth (1- m) (cdr exdata)))))
                        )
                        (set_tile (strcat "eb" (itoa n)) value)
                        (setq m (1+ m))
                        (setq n (1+ n))
                )
        )
        (action_tile "accept" "(done_dialog 1)")
        (action_tile "cancel" "(done_dialog 0)")
        (setq result (start_dialog))
        (cond
                ((= 1 result)
                        (if (setq ss (LM:ssget "\n 选取扩展数据对象" nil ))
                                (while (setq entname (ssname ss 0))
                                        (setq ss (ssdel entname ss))
                                        (getdclvalue)
                                        (if (getentdxf entname -3)
                                                (setq allexdata (getentdxf entname -3))
                                                (progn
                                                        (regapp "XData")
                                                        (setq allexdata '(("XData" (1000 . "")(1000 . "")(1000 . "")(1000 . ""))))
                                                )
                                        )                                       
                                        (setq entdata (entget entname '("*")))
                                        (if (getentdxf entname -3)
                                                (entmod (subst newallexdata (assoc -3 entdata) entdata))
                                                (entmod (append entdata  (list newallexdata)))
                                        )
                                )   
                        )
                )
        )
        (princ)
)
"觉得好,就打赏"
还没有人打赏,支持一下
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-4-26 15:00 , Processed in 0.308502 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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