Cat 发表于 2022-7-6 09:46:31

lisp可以用来强制

大家好,
我不知道这是否可以做到,因为我对编写lisp例程非常了解,但我整天都在编写和运行脚本,试图在一个项目结束时“清理”一个巨大的烂摊子,该项目在不同国家的几个部门之间被分割,几乎没有或根本没有协调任何相关部门之间的一致性@#$@$#@
 
无论如何,我已经介绍了很多使用查找和替换的脚本,但我已经到了一个点,我需要替换的信息是通用的,以使用查找和替换功能。标记对于所有图形都是通用的,我希望能够使用一个脚本执行lisp,该脚本可以找到该标记并将标记的值更改为我需要的值。
 
我希望我的胡言乱语没有给任何能够帮助我解决这个问题的人带来混乱。如果是这样,那就归咎于项目经理。

David Bethel 发表于 2022-7-6 09:50:40

看看我是否理解:
在一次调用中更改具有指定标记名的所有插入中的1个属性值
 
如果是这样:
 

(defun c:chg1att (/ tagname new_val i ss en ch an ad)

(setq tagname (strcase (getstring "\nATTRIB TagName:")))
(setq new_val (getstring t "\nNew ATTRIB Value:"))

(and (setq i -1 ss (ssget "X" '((0 . "INSERT")(66 . 1))))
      (while (setq en (ssname ss (setq i (1+ i))))
             (setq ch nil
                   an (entnext en)
                   ad (entget an))
             (while (= "ATTRIB" (cdr (assoc 0 ad)))
                  (and (= (cdr (assoc 2 ad)) tagname)
                         (entmod (subst (cons 1 new_val)
                                        (assoc 1 ad) ad))
                         (setq ch T))
                  (setq an (entnext an)
                        ad (entget an)))
             (if ch (entupd en))))
(prin1))

 
-大卫

Cat 发表于 2022-7-6 09:54:38

谢谢你,大卫。你能澄清一下在lisp中我将把标记名和新值放在哪里吗?我必须先输入旧值,然后输入新值吗?
例如:
标记名类似于:Code_4
我需要替换的值是:48
新值将为:实际描述。。。。比如说。。。。。见现场跑步
对不起,我是Lisp程序的文盲。

David Bethel 发表于 2022-7-6 09:58:35

这会更改属性值,而不考虑旧值。这是一个问题吗?
 

(defun c:chg1att (/ tagname new_val i ss en ch an ad)

(setq tagname "CODE_4")
(setq new_val "See Spot Run")

(and (setq i -1 ss (ssget "X" '((0 . "INSERT")(66 . 1))))
      (while (setq en (ssname ss (setq i (1+ i))))
             (setq ch nil
                   an (entnext en)
                   ad (entget an))
             (while (= "ATTRIB" (cdr (assoc 0 ad)))
                  (and (= (strcase (cdr (assoc 2 ad)))
                            (strcase tagname))
                         (entmod (subst (cons 1 new_val)
                                        (assoc 1 ad) ad))
                         (setq ch T))
                  (setq an (entnext an)
                        ad (entget an)))
             (if ch (entupd en))))
(prin1))

 
 
-大卫

Cat 发表于 2022-7-6 10:01:17

不,大卫,这应该很好用。我周末休假,但星期一早上第一件事就是试试。我知道,对于未来的应用程序,我可以多次复制代码来替换多个标记值吗?

David Bethel 发表于 2022-7-6 10:04:20

是的,你可以复制多次。
 
如果需要处理1000个插入,则可以提高例程的效率,但使用今天的硬件,只需几秒钟即可完成-大卫

Cat 发表于 2022-7-6 10:07:02

再次感谢你,大卫。我真的很感激。我会告诉你事情的进展。

Cat 发表于 2022-7-6 10:11:26

大卫,
我只是想让你知道Lisp程序很有效。我真的很感谢你的帮助。
将lisp修改为当前属性值到新属性值的查找和替换有多困难?

David Bethel 发表于 2022-7-6 10:14:07

非常简单:
 

;;;Change 1 Known ATTRIBute Value With a New Value
(defun c:chg1kat (/ tagname old_val new_val i ss en ch an ad)

(setq tagname "CODE_4")
(setq old_val "See Jane Run")
(setq new_val "See Spot Run")

(and (setq i -1 ss (ssget "X" '((0 . "INSERT")(66 . 1))))
      (while (setq en (ssname ss (setq i (1+ i))))
             (setq ch nil
                   an (entnext en)
                   ad (entget an))
             (while (= "ATTRIB" (cdr (assoc 0 ad)))
                  (and (= (strcase (cdr (assoc 2 ad)))
                            (strcase tagname))
                         (= (strcase old_val)
                            (strcase (cdr (assoc 1 ad))))
                         (entmod (subst (cons 1 new_val)
                                        (assoc 1 ad) ad))
                         (setq ch T))
                  (setq an (entnext an)
                        ad (entget an)))
             (if ch (entupd en))))
(prin1))

 
 
这些值不区分大小写
 
就比较而言,简和简是平等的。
 
-大卫

Cat 发表于 2022-7-6 10:15:53

大卫,你太棒了。
还有一个问题。如果我想在lisp中执行多个值,是否需要每个值复制整个代码?
页: [1] 2
查看完整版本: lisp可以用来强制