如何在块中查找文本
我想在块中获取文本。。最后我会变成这样。。。(setq a’(“2”“ABC”))
你可以理解,如果你看到我的附加文件。。。
cadtutor问题。图纸 你可以从这样的事情开始。。。。
(vlax-for block
(vla-get-blocks
(vla-get-activedocument
(vlax-get-acad-object)
)
)
(vlax-for obj block
(if (and (eq "AcDbText" (vla-get-objectname obj))
(eq (vla-get-TextString obj) "abc")
)
;;;;;;;; ....................
;;;;;;;;;;;;;;;;;; ............................
;;;;;;;;;;;;;; ..SO ON .....
Tharwat 谢谢Tharwat
我试着理解….^^ 不客气,阿林。 另一个详细示例演示了一般概念:
(defun GetBlockText
( blockcollection blockname / _GetIteminCollection _GetItemsinCollectionIf blockdef )
(defun _GetIteminCollection ( collection item / result )
(if
(not
(vl-catch-all-error-p
(setq result
(vl-catch-all-apply 'vla-item (list collection item))
)
)
)
result
)
)
(defun _GetItemsinCollectionIf ( collection condition / result )
(
(lambda ( condition )
(vlax-for item collection
(if (condition item) (setq result (cons item result)))
)
(reverse result)
)
(eval condition)
)
)
(if (setq blockdef (_GetItemInCollection blockcollection blockname))
(mapcar 'vla-get-textstring
(_GetItemsinCollectionIf blockdef
'(lambda ( x ) (wcmatch (vla-get-objectname x) "AcDb*Text"))
)
)
)
)
(vl-load-com)
(defun c:test nil
(GetBlockText
(vla-get-blocks
(vla-get-activedocument (vlax-get-acad-object))
)
(getstring "\nSpecify Block Name: ")
)
)
谢谢李。
这就是我想要的….^ 是否有可能在块中的块中获取文本。。或者在块中的块中获取文本?
T T 是的,使用递归:
(defun GetBlockText ( blockcollection blockname / _GetIteminCollection blockdef result )
(defun _GetIteminCollection ( collection item / result )
(if
(not
(vl-catch-all-error-p
(setq result
(vl-catch-all-apply 'vla-item (list collection item))
)
)
)
result
)
)
(if (setq blockdef (_GetIteminCollection blockcollection blockname))
(vlax-for item blockdef
(cond
( (eq "AcDbBlockReference" (vla-get-objectname item))
(setq result (append (GetBlockText blockcollection (vla-get-name item)) result))
)
( (wcmatch (vla-get-objectname item) "AcDb*Text")
(setq result (cons (vla-get-textstring item) result))
)
)
)
)
(reverse result)
)
(vl-load-com)
(defun c:test nil
(GetBlockText
(vla-get-blocks
(vla-get-activedocument (vlax-get-acad-object))
)
(getstring "\nSpecify Block Name: ")
)
) 你这个天才。。。。非常感谢…^^这个资料对我的工作很有用。 不客气,阿林!
页:
[1]
2