Arin9916 Posted May 24, 2011 Posted May 24, 2011 i want get text in a block.. finally. i wnat get like this... (setq a '("2" "ABC")) you can understand if you see my attached file... cadtutor-question.dwg Quote
Tharwat Posted May 24, 2011 Posted May 24, 2011 You can start with something like this .... (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 Quote
Arin9916 Posted May 24, 2011 Author Posted May 24, 2011 thanks Tharwat i try to understang.. ^^ Quote
Lee Mac Posted May 24, 2011 Posted May 24, 2011 Another, verbose example demonstrating the general concept: ([color=BLUE]defun[/color] GetBlockText ( blockcollection blockname [color=BLUE]/[/color] _GetIteminCollection _GetItemsinCollectionIf blockdef ) ([color=BLUE]defun[/color] _GetIteminCollection ( collection item [color=BLUE]/[/color] result ) ([color=BLUE]if[/color] ([color=BLUE]not[/color] ([color=BLUE]vl-catch-all-error-p[/color] ([color=BLUE]setq[/color] result ([color=BLUE]vl-catch-all-apply[/color] '[color=BLUE]vla-item[/color] ([color=BLUE]list[/color] collection item)) ) ) ) result ) ) ([color=BLUE]defun[/color] _GetItemsinCollectionIf ( collection condition [color=BLUE]/[/color] result ) ( ([color=BLUE]lambda[/color] ( condition ) ([color=BLUE]vlax-for[/color] item collection ([color=BLUE]if[/color] (condition item) ([color=BLUE]setq[/color] result ([color=BLUE]cons[/color] item result))) ) ([color=BLUE]reverse[/color] result) ) ([color=BLUE]eval[/color] condition) ) ) ([color=BLUE]if[/color] ([color=BLUE]setq[/color] blockdef (_GetItemInCollection blockcollection blockname)) ([color=BLUE]mapcar[/color] '[color=BLUE]vla-get-textstring[/color] (_GetItemsinCollectionIf blockdef '([color=BLUE]lambda[/color] ( x ) ([color=BLUE]wcmatch[/color] ([color=BLUE]vla-get-objectname[/color] x) [color=MAROON]"AcDb*Text"[/color])) ) ) ) ) ([color=blue]vl-load-com[/color]) ([color=BLUE]defun[/color] c:test [color=BLUE]nil[/color] (GetBlockText ([color=BLUE]vla-get-blocks[/color] ([color=BLUE]vla-get-activedocument[/color] ([color=BLUE]vlax-get-acad-object[/color])) ) ([color=BLUE]getstring[/color] [color=MAROON]"\nSpecify Block Name: "[/color]) ) ) Quote
Arin9916 Posted May 24, 2011 Author Posted May 24, 2011 is it possible that Get the text in block in block.. or get text in block in block in block? T T Quote
Lee Mac Posted May 24, 2011 Posted May 24, 2011 Yes, using recursion: (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: ") ) ) Quote
Arin9916 Posted May 24, 2011 Author Posted May 24, 2011 you genius.... Thank you so much...^^ this source useful for my job. Quote
Arin9916 Posted May 24, 2011 Author Posted May 24, 2011 I need to help again... I`m sorry.....but it`s last...; There are attext in block.. in block... I try to revise myself.... but i can`t not understand use souce... i need to have a time....TT Quote
Lee Mac Posted May 24, 2011 Posted May 24, 2011 Attribute text is accessed from the Block Reference (Insert) not the Block Definition. Examples here: http://lee-mac.com/attributefunctions.html Quote
Hickoz_bro Posted July 14, 2011 Posted July 14, 2011 Lee, Following on from Arin's query. I'm looking to search a particular block, for a particular string. From what I can gather vlax-for requires a collection, and if I'm not mistaken, you cannot create your own collection, so using vlax-for means I search all blocks on the drawing, or nothing. So, Instead of using vlax-for, How would I iterate through a selection set containing blocks to check each block for my string? And don't spoil it for me... just a few keywords would be great, I want to figure this out myself (as much as possible).... Cheers Quote
Lee Mac Posted July 14, 2011 Posted July 14, 2011 You needn't iterate through the whole Block Collection using vlax-for, but rather use vla-item to retrieve a specific block definition. This block definition is itself a collection of all objects that make it up, so you can then use vlax-for on the block definition. A complete example of this method can be found in post#5 of this thread. Quote
Hickoz_bro Posted July 15, 2011 Posted July 15, 2011 Lee, Where would I find help on the vla-item command? Or any of the vla- commands for that matter? The AutoCAD help doesn't show them, but I'm sure I've seen them somewhere before... Quote
Lee Mac Posted July 15, 2011 Posted July 15, 2011 Lee, Where would I find help on the vla-item command? Or any of the vla- commands for that matter? The AutoCAD help doesn't show them, but I'm sure I've seen them somewhere before... There was never any specific Visual LISP documentation for the vla-* commands, since these functions are merely properties and methods of the ActiveX Object Model, exposed by the relevant type library (tlb). In versions up to 2010, VBA documentation was provided for these properties and methods, however, since VBA is no longer supported, this documentation was unfortunately removed from 2011 onwards. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.