将两个LISP合并为一个
嗨,我需要帮助。我想从现有的两个LISP中找到新的LISP。第一个交付选择集(根据属性值),第二个应使用该选择集(更改选定对象的层)。
我认为这很琐碎,但我不知道怎么做。我在谷歌上花了一些时间,但什么也没学到。
我不喜欢在执行过程中选择任何东西。
稍后我将在代码中自己更改层名称(这是我对许多相同属性(具有不同的特定属性值)的全局层更改想法的第一步)。
1.
(defun c:attselect ( / ss2 ss tag val n na)
(setq ss2 (ssadd))
(sssetfirst nil nil)
(princ "\nSelect blocks containing attributes.")
(if (setq ss (ssget '((0 . "INSERT") (66 . 1))))
(progn
(setq tag "COLOR"
val "OR (1)"
);setq
(if (equal tag "")
(setq tag "*")
);if
(if (equal val "")
(setq val "*")
);if
(setq n 0)
(repeat (sslength ss)
(setq na (ssname ss n))
(if (sample_att_match na tag val)
(setq ss2 (ssadd na ss2))
);if
(setq n (+ n 1));setq
);repeat
(if (equal (getvar "cmdnames")"")
(sssetfirst ss2 ss2)
(command ss2)
);if
);progn then
);if
(princ)
);defun c:attselect
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun sample_att_match ( na tag val / e1 a b flag)
(while (and (setq na (entnext na))
(setq e1 (entget na))
(not (equal (cdr (assoc 0 e1)) "SEQEND"))
(not flag)
);and
(if (equal (cdr (assoc 0 e1)) "ATTRIB")
(progn
(setq a (cdr (assoc 2 e1)) ;2 is tag
b (cdr (assoc 1 e1)) ;1 is value
);setq
(if (and a
(wcmatch a tag)
b
(wcmatch b val)
);and
(setq flag T);then jump out of the loop
);if
);progn then attrib
);if
);while
flag
);defun sample_att_match
(princ "\nType ATTSELECT to run")
(princ)
我对我在某处找到的原始代码(标记“COLOR”,val“OR(1)”)进行了更改。
2.
; Changes selected objects to Layer PL1
(defun c:setpl1 ()
(tolayer
(ssget "_:L") ;;selection
"PL1" ;;Layer
)
(princ)
)
(defun tolayer ( ss lay / i e )
;;; ss - pickset
;;; lay -layer name
(repeat (setq i (sslength ss))
(entmod
(subst
(cons 8 lay)
(assoc 8 (entget (setq e (ssname ss (setq i (1- i))))))
(entget e)
)
)
)
)
此代码可在此论坛上找到:http://www.cadtutor.net/forum/showthread.php?67438-LISP-to-move-selected-objects-to-a-specified-layer
VVA出版。
Thanx他,第一个代码的创建者(未知)。
Thanx未来的“合路器” 你能不能把这个添加到你的第一个Lisp程序的末尾,在
(C:setpl1) 几个变化
not tested
(defun c:attselect ( / ss2 tag val n na) ss has been removed so makes it a global variable
ignore setpl1
(defun c:test ()
(c:attselect)
(setq lay "PL1")
(defun tolayer ( ss lay / i e ) ;ignore setpl1
)
隐马尔可夫模型。。我没有成功地执行你的建议。我缺乏知识。我一直在尝试,添加,置换,实验,我一直在阅读AlfaLISP,JeffryLISP。。。找不到与“合并”相关的主题。我不理解在一个代码(在一个*.lsp中)中执行不同函数的一般逻辑。
拜托,你能帮我做吗?我会努力从中获取知识,而不仅仅是使用它 嗨,我决定先读一本书。我确实学到了一些东西,现在很多事情都更清楚了。。。我让代码工作。请记住,我是LISP的初学者,现在我很高兴代码能够正常工作。
在我看来,变量ss2应该是全局的,因为我需要tolayer函数中的选择集。这样就行了。
我需要进一步的帮助,每一条评论都很有帮助。我觉得自己又像个学生了(没有人对这个话题做准备就无法得到教授的咨询)。
我附上了示例1。dwg以便于测试。
请看代码中的注释。
代码如下:
;|combining attselect and layer change.
c:test- it works!
- at the end should do this: select all blocks in drawing, filter it by attribute value "OR (1)", change layer of those to PURPLE
- main command that combines two of those:
c:attselect - selects all blocks in layer GREEN with attribute value "OR (1)"
c:tolay - it changes selection layer to PURPLE
idea1: I wish that I dont need to select manualy whole drawing with mouse. I wish LISP do it without me.
idea2: Later... :-) |;
;final combining command
(defun c:test ()
(c:attselect)
(c:tolay)
)
;makes selection (only blocks within layer GREEN)
(defun c:attselect ( / ss tag val n na)
(setq ss2 (ssget "all" '((8 . "GREEN")(0 . "INSERT"))))
;|
comment for line above
this is original line in original command: (setq ss2 (ssadd))
I'm trying to make this selection automatic (without mouse input of selecting all
I don't know how!!!
|;
(sssetfirst nil nil)
(princ "\nSelect blocks containing attributes.")
(if (setq ss (ssget '((0 . "INSERT") (66 . 1))))
(progn
(setq tag "COLOR"
val "OR (1)"
);setq
(if (equal tag "")
(setq tag "*")
);if
(if (equal val "")
(setq val "*")
);if
(setq n 0)
(repeat (sslength ss)
(setq na (ssname ss n))
(if (sample_att_match na tag val)
(setq ss2 (ssadd na ss2))
);if
(setq n (+ n 1));setq
);repeat
(if (equal (getvar "cmdnames")"")
(sssetfirst ss2 ss2)
(command ss2)
);if
);progn then
);if
(princ)
);defun c:attselect
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun sample_att_match ( na tag val / e1 a b flag)
(while (and (setq na (entnext na))
(setq e1 (entget na))
(not (equal (cdr (assoc 0 e1)) "SEQEND"))
(not flag)
);and
(if (equal (cdr (assoc 0 e1)) "ATTRIB")
(progn
(setq a (cdr (assoc 2 e1)) ;2 is tag
b (cdr (assoc 1 e1)) ;1 is value
);setq
(if (and a
(wcmatch a tag)
b
(wcmatch b val)
);and
(setq flag T);then jump out of the loop
);if
);progn then attrib
);if
);while
flag
);defun sample_att_match
(princ "\nType ATTSELECT to run")
(princ)
; changes layer of selection provided by attselect
(defun c:tolay ()
(command "_.chprop" (eval ss2) "" "_layer" "PURPLE" "")
)
理想1:尝试ssget“X”查找ssget的帮助,您可以做围栏、点、多边形内等X=全部,再加上其他。
页:
[1]