Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

(setq a(ssget "X" '((0 . "insert"))

14 REPLIES 14
Reply
Message 1 of 15
Anonymous
1594 Views, 14 Replies

(setq a(ssget "X" '((0 . "insert"))

I have a block comprised of a set of notes that exists in a number of drawings. The problem is that it has been named differently in each drawing. Is there a way I can identify it by a common text string within the block? TIA
14 REPLIES 14
Message 2 of 15
Anonymous
in reply to: Anonymous

Hello,

Is the common string in the block a text object in the block definition 
or is it an attribute value?

Depending on what it is, I can suggest two different solutions:

1. If the common string is a block attribute value, then you can use a 
function called (SS_SSGetBlkAtt...) to make a selection set of blocks 
that have an attribute which matches with a given value. This library 
function (and any other library function that it requires) is available 
for free download from our Tech Center (see free downloads URL below) 
under the Blocks  library. You can use this to build your selection set 
meeting your criteria.

2. If the common text string is part of the  block definition, take a 
look at our GeoTools program (see URL below for a fully functional 
download). The GT_SRCHBLK4TXT command identifies blocks which have a 
particular text string in its definition.

If you need any tweaking, email me for more info.

Regards
Rakesh

coachball8 wrote:
> I have a block comprised of a set of notes that exists in a number of drawings. The problem is that it has been named differently in each drawing. Is there a way I can identify it by a common text string within the block? TIA


-- 

AutoCAD customization for Engineering/Mapping/GIS
Get GeoTools @ http://www.4d-technologies.com/geotools
Build MyGeoTools @ http://www.4d-technologies.com/geotools/my_geotools.htm
FREE downloads : http://www.4d-technologies.com/techcenter
Message 3 of 15
Anonymous
in reply to: Anonymous

(defun BlockSearch4Ent (dxf val / cbl cntf e ) (setq cbl (tblnext "block" T) cntf 0 );setq (while cbl (princ "\nChecking Block Name: ")(princ (cdr (assoc 2 cbl))) (setq e (cdr (assoc -2 cbl))) (while e (setq e (entget e)) ;(if (= (strcase (cdr (assoc 0 e))) "INSERT");*for debugging ; (progn ;*for debugging ; (princ "\ne = ")(prin1 e) ;*for debugging ; );*progn ;*for debugging ; () ;*for debugging ;);*if ;*for debugging (if (and (assoc dxf e) (or (and (= (type val) 'STR) (wcmatch (strcase(cdr (assoc dxf e)))(strcase val)) );and (= (cdr (assoc dxf e)) val) );or );and (progn (princ "\tFound: ")(prin1 dxf)(princ" - ")(prin1 val) (setq cntf (+ cntf 1)) );progn () );if (setq e (entnext (cdr (assoc -1 e)))) );while (setq cbl (tblnext "block")) );while (princ (strcat "\n"val" found count = "(rtos cntf 2 0))) (princ) );defun BlockSearch4Ent "coachball8" wrote in message news:4497596.1079086357860.JavaMail.jive@jiveforum2.autodesk.com... > I have a block comprised of a set of notes that exists in a number of drawings. The problem is that it has been named differently in each drawing. Is there a way I can identify it by a common text string within the block? TIA
Message 4 of 15
Anonymous
in reply to: Anonymous

Thanks Rakesh. I'll check it out.
Message 5 of 15
Anonymous
in reply to: Anonymous

I somehow didn't think it would be quite that complicated. Thanks Martin. Can you tell me where in the code I define the text string that I'm in search of? You see, in the end, if this block is in the drawing, I need to either erase it or remove notes 1 thru 3 (it's actually a legend, so there won't be any renumbering of notes involved in the process). Thanks for the help.
Message 6 of 15
Anonymous
in reply to: Anonymous

(BlockSearch4Ent 1 "text string") Calling the the function with the above arguments will search the block definition for text entites with the text string = "text string" As the function uses wcmatch wild cards may be used. As I wrote this function years ago I'm going from memory. Hope this helps "coachball8" wrote in message news:30482311.1079089941901.JavaMail.jive@jiveforum2.autodesk.com... > I somehow didn't think it would be quite that complicated. Thanks Martin. Can you tell me where in the code I define the text string that I'm in search of? You see, in the end, if this block is in the drawing, I need to either erase it or remove notes 1 thru 3 (it's actually a legend, so there won't be any renumbering of notes involved in the process). Thanks for the help.
Message 7 of 15
Anonymous
in reply to: Anonymous

It helps a ton! Thanks very much.
Message 8 of 15
Anonymous
in reply to: Anonymous

This code works really well Martin, but perhaps you can help me a little more? I tried all day yesterday to get it store a variable for the block that the text string is located in, but to no avail. As I said, I'm searching for a legend on the symbol drawing, and if it's there, I need to delete it. I can't seem to make it happen. could you offer me some insight on that? Thanks again for all your help.
Message 9 of 15
Anonymous
in reply to: Anonymous

(defun BlockSearch4Ent (dxf val / cbl cntf e ) (setq cbl (tblnext "block" T) cntf 0 gBlockList '() ;--------------addition );setq (while cbl (princ "\nChecking Block Name: ")(princ (cdr (assoc 2 cbl))) (setq e (cdr (assoc -2 cbl))) (while e (setq e (entget e)) (if (and (assoc dxf e) (or (and (= (type val) 'STR) (wcmatch (strcase(cdr (assoc dxf e)))(strcase val)) );and (= (cdr (assoc dxf e)) val) );or );and (progn (princ "\tFound: ")(prin1 dxf)(princ" - ")(prin1 val) ;----------addition Starts (if (not (member (cdr (assoc 2 cbl)))) (setq gBlockList (append gBlockList (list (cdr (assoc 2 cbl))))) () );if ;----------addition End (setq cntf (+ cntf 1)) );progn () );if (setq e (entnext (cdr (assoc -1 e)))) );while (setq cbl (tblnext "block")) );while (princ (strcat "\n"val" found count = "(rtos cntf 2 0))) (princ) );defun BlockSearch4Ent In the above code I have labelled the additions. I HAVE NOT TESTED THIS CODE. Sorry for shouting;) The additions initiate an empty list and then adds all block names that match search criteria. I have set this to a global variable but this would not be my prefered method. I find lists in lisp great for returning data. I prefer this to VB as VB is more data type specific. Anyway, I f you would like to return this to another function make these changes as well (defun BlockSearch4Ent (dxf val / cbl cntf e gBlockList ) (setq cbl (tblnext "block" T) .... (princ (strcat "\n"val" found count = "(rtos cntf 2 0))) gBlockList );defun BlockSearch4Ent "coachball8" wrote in message news:3980932.1079167207477.JavaMail.jive@jiveforum1.autodesk.com... > This code works really well Martin, but perhaps you can help me a little more? I tried all day yesterday to get it store a variable for the block that the text string is located in, but to no avail. As I said, I'm searching for a legend on the symbol drawing, and if it's there, I need to delete it. I can't seem to make it happen. could you offer me some insight on that? Thanks again for all your help.
Message 10 of 15
Anonymous
in reply to: Anonymous

Once again, I appreciate all your help. I just couldn't figure out how to store the blocks as a list, but I should be able to get there from here. Thanks again.
Message 11 of 15
Anonymous
in reply to: Anonymous

This returns too few arguments and breaks on error at
(if (not (member (cdr (assoc 2 cbl)))). I haven't been able
to nail down the problem. It still finds the text string, just returns an error. Any ideas?
Message 12 of 15
Anonymous
in reply to: Anonymous

aah the problems of untested code.... should be (if (not (member (cdr (assoc 2 cbl)) gBlockList )) "coachball8" wrote in message news:2507905.1079362389368.JavaMail.jive@jiveforum1.autodesk.com... > This returns too few arguments and breaks on error at > (if (not (member (cdr (assoc 2 cbl)))). I haven't been able > to nail down the problem. It still finds the text string, just returns an error. Any ideas?
Message 13 of 15
Anonymous
in reply to: Anonymous

DUH for me..........that's about the only thing I haven't tried. Thanks Martin. One more quick question, if you don't mind. When I add my function to erase this block, it should be added at the end where it returns the count. Is that correct? Thanks again. You've been a huge help.
Message 14 of 15
Anonymous
in reply to: Anonymous

You can add it there. I would write a separate function and parse the block list to te new function At the risk of more mistakes the code would be something like (foreach val gBlockList (setq ss (ssget "X" (list (cons 2 val)))) (if ss (command ".erase" ss "")()) ) again untested Good luck Martin "coachball8" wrote in message news:24435499.1079431248252.JavaMail.jive@jiveforum1.autodesk.com... > DUH for me..........that's about the only thing I haven't tried. Thanks Martin. One more quick question, if you don't mind. When I add my function to erase this block, it should be added at the end where it returns the count. Is that correct? Thanks again. You've been a huge help.
Message 15 of 15
Anonymous
in reply to: Anonymous

Don't worry about the risk of more mistakes. A lot of them I can figure out for myself. I just got really hung up on that other one. Once again Martin, I appreciate all your help.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost