重命名多个块
您好,我有一块门、窗和家具,我想通过删除“mm”之后的所有字符和前缀以“M”开头的方式对它们进行一次性重命名例如:“M_单冲-0915 x 2134mm-180048-1级”至单冲-0915 x 2134mm
还有窗户和家具
我附上了一个非常简单的图纸,任何人都可以为我测试。
更具体地说:
1-我想通过选择或整个图形“X”一次性重命名上述所有块
2-我想有可能添加列表(自定义),比如删除单词“Breuer”后的字符,大小写与“mm”相同
小Lisp程序(复制),但缺少我上面提到的功能:
(defun c:test (/ DATA I NEW OLD SS)
(if (and (setq ss (ssget "_+.:E:S" '((0 . "INSERT"))));; select single insert
(setq data (entget (ssname ss 0)));; object definition data
(setq old (cdr (assoc 2 data)));; block name
(not (assoc 1 (tblsearch "BLOCK" old)));; not Xref
(setq i (vl-string-search "mm" old));; mm position
(setq new (substr old 1 (+ i 2)));; new name
(not (tblsearch "BLOCK" new));; search if name exists
);; and
(command "._rename" "_block" old new)
);; if
(princ)
);; test
谢谢
样品图纸 欢迎来到CADTutor shehab10!
这些代码行提醒了我一些事情。。。
问题是,块通常具有相同的名称,不包括ID和标高,AutoCAD不允许具有相同名称的块,
一种可能的方法是只从块名中删除级别部分,如果合适的话,如下所示
(defun c:test (/ DATA I N NEW OLD SS)
(if (setq ss(ssget "_X" '((0 . "INSERT"))));; select insert
(progn
(setq n (sslength ss));; sets n with the selection set lenght
(while (not (minusp (setq n (1- n))));; while n not negative, set n -1
(if (and (setq data (entget (ssname ss n)));; object definition data
(setq old (cdr (assoc 2 data)));; block name
(not (assoc 1 (tblsearch "BLOCK" old)));; not Xref
(setq i (vl-string-search "Level" old));; Level position
(setq i (1- i));; - before Level
(setq new (substr old 1 i));; new name removing the level
(not (tblsearch "BLOCK" new));; search if name exists, and if not
);; and
(command "._rename" "_block" old new);; rename the block
);; if
);; while
);; progn
);; if
(princ)
);; test
希望有帮助
亨里克 Yope-hmsilva这让我想起了你在其他地方,我的块不会具有相同的名称,因为revit不允许两个族(块)具有相同的名称。此外,我希望lisp将具有跳过两个具有相同名称或异常的对象中的一个的功能,以消除处理两个与可以在lisp中编写的例程具有相同名称的块(请原谅,我只是猜测我对lisp不太了解)。
我实验了m而不是level,它确实删除了mm(我可能只需要它来识别单元,但是如果在lisp中它很乏味,那么它就不那么重要了)
我在“m”之外添加了单词“Breuer”作为泛型词的列表,以删除后面的字符,但无论如何它都不起作用!
另外,你能给我添加一行代码,可以添加到上述代码中,以删除前缀M_(我将使用它作为缩写我的块名的额外选项)?
Henrique,您已经在函数ssget之前添加了模式字符串 接得好,塔瓦
已经修好了,昨天,我几乎睡着了。。。 如果在前缀“M_”之前有什么东西,我想删除它和它之前的任何东西,那该怎么办?
也许是这样的
(defun c:test (/ DATA I II N NEW OLD SS)
(if (setq ss (ssget "_X" '((0 . "INSERT"))));; select insert
(progn
(setq n (sslength ss));; sets n with the selection set lenght
(while (not (minusp (setq n (1- n))));; while n not negative, set n -1
(if (and (setq data (entget (ssname ss n)));; object definition data
(setq old (cdr (assoc 2 data)));; block name
(not (assoc 1 (tblsearch "BLOCK" old)));; not Xref
(setq i (vl-string-search "Level" old));; Level position
(setq i (1- i));; - before Level
(if (setq ii (vl-string-search "M_" old));; M_ position
(setq ii (+ ii 3));; after M_ position
(setq ii 1);;if not M_ position
);; if
(setq new (substr old ii i));; new name removing the level
(not (tblsearch "BLOCK" new));; search if name exists, and if not
);; and
(command "._rename" "_block" old new);; rename the block
);; if
);; while
);; progn
);; if
(princ)
);; test
亨里克
页:
[1]