【问题标题】:AutoCAD: Edit object attribute table automaticallyAutoCAD:自动编辑对象属性表
【发布时间】:2018-08-09 05:20:57
【问题描述】:

我在 AutoCAD 绘图中有几个(许多)对象,每个对象的首选项中都有相同的属性字段。现在我想用一个数字填充这个属性字段(对象一 - 数字 1,对象二 - 数字 2 等等)。手动输入数字非常耗时,因此我想请问您是否有自动化的方法来解决这个问题。

提前非常感谢!

【问题讨论】:

  • 找到解决方案:ALTEXT 可以解决问题。

标签: automation attributes label autocad


【解决方案1】:

一个例子

以下程序是一个非常简单的示例,它会提示您输入要编号的属性标签和开始编号的整数,然后会不断提示您选择要编号的属性块引用,并递增编号每个有效选择加一:

(defun c:attnum ( / ent enx num tag )
    (if (/= "" (setq tag (strcase (getstring "\nSpecify attribute tag <exit>: "))))
        (progn
            (setq num (cond ((getint "\nSpecify starting number <1>: ")) (1)))
            (while
                (not
                    (progn
                        (setvar 'errno 0)
                        (setq ent (car (entsel (strcat "\nSelect block number " (itoa num) " <exit>: "))))
                        (cond
                            (   (= 7 (getvar 'errno))
                                (prompt "\nMissed, try again.")
                            )
                            (   (null ent))
                            (   (/= "INSERT" (cdr (assoc 0 (setq enx (entget ent)))))
                                (prompt "\nThe selected object is not a block.")
                            )
                            (   (/= 1 (cdr (assoc 66 enx)))
                                (prompt "\nThe selected block is not attributed.")
                            )
                            (   (progn
                                    (setq ent (entnext ent)
                                          enx (entget  ent)
                                    )
                                    (while
                                        (and
                                            (= "ATTRIB" (cdr (assoc 0 enx)))
                                            (/= tag (strcase (cdr (assoc 2 enx))))
                                        )
                                        (setq ent (entnext ent)
                                              enx (entget  ent)
                                        )
                                    )
                                    (/= "ATTRIB" (cdr (assoc 0 enx)))
                                )
                                (prompt (strcat "\nThe selected block does not contain the attribute \"" tag "\"."))
                            )
                            (   (entmod (subst (cons 1 (itoa num)) (assoc 1 enx) enx))
                                (entupd ent)
                                (setq num (1+ num))
                                nil
                            )
                            (   (prompt "\nUnable to edit attribute value."))
                        )
                    )
                )
            )
        )
    )
    (princ)
)

如何加载和运行上述内容

  • 打开 Windows 记事本。
  • 将上述代码复制并粘贴到记事本中。
  • 使用您选择的文件名保存文件,文件扩展名为 .lsp确保将 Save As Type 设置为 All Files (*.*))。
  • 在新的或现有的图形中打开 AutoCAD。
  • 在 AutoCAD 命令行中键入 APPLOAD
  • 浏览并选择上面保存的文件,然后点击Load加载程序。
  • 关闭APPLOAD 对话框。
  • 在 AutoCAD 命令行中键入 ATTNUM 以运行程序。

在我的 How to Run an AutoLISP Program 教程中可以找到类似的说明。

如果您希望为在 AutoCAD 中打开的每个新图形或现有图形自动加载程序,请参阅我在 Loading Programs Automatically 上的教程。


其他现有解决方案

除了上述之外,您可能还对以下程序感兴趣:

  • 我的Incremental Numbering Suite 应用程序将提供更广泛的选项集,允许您自定义编号格式,允许前缀和后缀、多个递增部分和字母数字递增。

    您可以使用此应用程序对现有的属性块参照进行编号,方法是在对象放置期间在 AutoCAD 命令行中键入“R”或“r”以进入替换模式

  • 我的Incremental Array 应用程序将允许您在排列属性块引用(或其他对象)时自动增加属性值。

【讨论】:

  • 这就是一切!简单明了,但又如此有效。非常感谢!
【解决方案2】:

此 lsp 可帮助您为任何块属性添加前缀或后缀,但同时对所有块,我有类似的情况,因此我将上述 attnum.lsp 与此 Presuf.lsp 结合起来。

首先使用 attnum 将标签字段设置为递增数字 1,2,3,4 等。然后隔离对象并运行presuf,指明是添加后缀还是前缀,指明需要的值,然后选择所有对象。

(defun c:presuf ( / as el en i ss str typ )

 (initget "Prefix Suffix")
 (setq typ (cond ((getkword "\nAdd Prefix or Suffix? [Prefix/Suffix] <Prefix>: ")) ("Prefix")))
 (setq str (getstring t (strcat typ " to Add: ")))

 (if (setq ss (ssget '((0 . "INSERT") (66 . 1))))
     (repeat (setq i (sslength ss))
         (setq en (ssname ss (setq i (1- i))))
         (while (eq "ATTRIB" (cdr (assoc 0 (setq el (entget (setq en (entnext en)))))))
             (setq as (cdr (assoc 1 el)))
             (if (eq "Prefix" typ)
                 (if (not (wcmatch as (strcat str "*")))
                     (entmod (subst (cons 1 (strcat str as)) (assoc 1 el) el))
                 )
                 (if (not (wcmatch as (strcat "*" str)))
                     (entmod (subst (cons 1 (strcat as str)) (assoc 1 el) el))
                 )
             )
         )
     )
 )
 (princ)
)

【讨论】:

    【解决方案3】:

    如果我有属性标签或块名称,我可以尝试使用自定义解决方案回答您的问题,但是,我相信您可以找到所需的一切 hereBFindGlobal Attribute Extractor & Editor) .

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-12
      • 1970-01-01
      • 1970-01-01
      • 2012-09-13
      • 1970-01-01
      • 1970-01-01
      • 2013-10-17
      • 1970-01-01
      相关资源
      最近更新 更多