jaylo23 Posted December 11, 2009 Posted December 11, 2009 Hello all, did a search and couldnt quite find what i need so thought i would ask, forgive me if what i asked for already has been posted. I have a drawing that has some 400 blocks in it. Most of the blocks have different names, however they all have the same attribute tags (SUPPORTTYPE, SUPPORTNO, LINENO, & PKGNO). What i am looking for is a lisp wherby the user specifies which attribute tag they would like to search by, based on a particular value. In a perfect world the lisp would ask the user what attribute tag they wanted to do a search of (the user could input ST for SUPPORTTYPE, SN for SUPPORTNO, etc.) and then ask the user the value of the specific tag they wanted to do a search for and then select it. Any help would be greatly appreciated and sorry if this has already been posted, if so please point me in the right direction. I have a very primitive understanding of lisp so if anyone could give me the basics of the code i might be able to fill out all the particular details. Thanks all for your help! Quote
David Bethel Posted December 11, 2009 Posted December 11, 2009 This should get you started: [color=#8b4513];;;CREATE A SELECTION BASED ON AN ATTRIBUTE TAG NAME AND IT VALUE[/color] [color=#8b4513];;;ssa is global[/color] [b][color=BLACK]([/color][/b]defun c:tagset [b][color=FUCHSIA]([/color][/b]/ tagn tagv ss i en mb ed[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq ss [b][color=NAVY]([/color][/b]ssget [color=#2f4f4f]"X"[/color] [b][color=MAROON]([/color][/b]list [b][color=GREEN]([/color][/b]cons 0 [color=#2f4f4f]"INSERT"[/color][b][color=GREEN])[/color][/b][b][color=GREEN]([/color][/b]cons 66 1[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]if ss [b][color=NAVY]([/color][/b]progn [b][color=MAROON]([/color][/b]while [b][color=GREEN]([/color][/b]or [b][color=BLUE]([/color][/b]not tagn[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]not [b][color=RED]([/color][/b]snvalid tagn[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]setq tagn [b][color=BLUE]([/color][/b]strcase [b][color=RED]([/color][/b]getstring [color=#2f4f4f]"\nATTRIB Tag Name String: "[/color][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq tagv [b][color=GREEN]([/color][/b]strcase [b][color=BLUE]([/color][/b]getstring [color=#2f4f4f]"\nATTRIB Tag Value String: "[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq ssa [b][color=GREEN]([/color][/b]ssadd[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq i [b][color=GREEN]([/color][/b]sslength ss[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]while [b][color=GREEN]([/color][/b]not [b][color=BLUE]([/color][/b]minusp [b][color=RED]([/color][/b]setq i [b][color=PURPLE]([/color][/b]1- i[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]setq en [b][color=BLUE]([/color][/b]ssname ss i[b][color=BLUE])[/color][/b] mb en[b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]while [b][color=BLUE]([/color][/b]/= [color=#2f4f4f]"SEQEND"[/color] [b][color=RED]([/color][/b]cdr [b][color=PURPLE]([/color][/b]assoc 0 [b][color=TEAL]([/color][/b]entget en[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]setq en [b][color=RED]([/color][/b]entnext en[b][color=RED])[/color][/b] ed [b][color=RED]([/color][/b]entget en[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]and [b][color=RED]([/color][/b]= [color=#2f4f4f]"ATTRIB"[/color] [b][color=PURPLE]([/color][/b]cdr [b][color=TEAL]([/color][/b]assoc 0 ed[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b]= tagn [b][color=PURPLE]([/color][/b]cdr [b][color=TEAL]([/color][/b]assoc 2 ed[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b]= tagv [b][color=PURPLE]([/color][/b]cdr [b][color=TEAL]([/color][/b]assoc 1 ed[b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b]not [b][color=PURPLE]([/color][/b]ssmemb mb ssa[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b]ssadd mb ssa[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]if [b][color=GREEN]([/color][/b]not [b][color=BLUE]([/color][/b]zerop [b][color=RED]([/color][/b]sslength ssa[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]princ [color=#2f4f4f]"\nSelection Set ssa contians these blocks"[/color][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]princ [color=#2f4f4f]"\nNo INSERTS Found"[/color][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]princ [color=#2f4f4f]"\nNo ATTRIB INSERTs Found"[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] -David Quote
jaylo23 Posted December 11, 2009 Author Posted December 11, 2009 From the looks of it that seems to be exactly what i was looking for, ill play around with it, hopefully not do to much damage to it. Thank you for your quick response! Quote
David Bethel Posted December 11, 2009 Posted December 11, 2009 No problem. It is a modification of an older routine. ( initget ) and ( getkword ) can limit the tag name input. Just watch out for string cases for the comparison ( = ) tests. I normally force everything uppercase. -David Quote
jaylo23 Posted December 11, 2009 Author Posted December 11, 2009 David only problem im having right know is having it select it so it can show all the grips associated with the block using pselect(this is for visual purposes as our models are HUGE and some of these blocks are extremely small), and i want to be able to modify the block through the properties box, any ideas? Quote
Lee Mac Posted December 11, 2009 Posted December 11, 2009 Jaylo, Investigate the sssetfirst function Quote
jaylo23 Posted December 11, 2009 Author Posted December 11, 2009 Thats did the trick Lee Mac, thanks, and thank you David for getting me on the right track. Quote
Lee Mac Posted December 11, 2009 Posted December 11, 2009 Thats did the trick Lee Mac, thanks, and thank you David for getting me on the right track. You're welcome Quote
David Bethel Posted December 11, 2009 Posted December 11, 2009 I had a little time this PM so I took another look at it: [color=#8b4513];;;CREATE A SELECTION BASED ON AN ATTRIBUTE TAG NAME AND VALUE[/color] [color=#8b4513];;;ssa is global[/color] [color=#8b4513];;;Revised 12-11-2009[/color] [b][color=BLACK]([/color][/b]defun c:tagset [b][color=FUCHSIA]([/color][/b]/ tagn tagv ss i en mb ed[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]cond [b][color=NAVY]([/color][/b][b][color=MAROON]([/color][/b]not [b][color=GREEN]([/color][/b]setq ss [b][color=BLUE]([/color][/b]ssget [color=#2f4f4f]"X"[/color] [b][color=RED]([/color][/b]list [b][color=PURPLE]([/color][/b]cons 0 [color=#2f4f4f]"INSERT"[/color][b][color=PURPLE])[/color][/b][b][color=PURPLE]([/color][/b]cons 66 1[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]alert [color=#2f4f4f]"\nNo Attribute INSERTs Found - Aborting"[/color][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]exit[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]initget 1 [color=#2f4f4f]"supporttyPe supportNo Lineno pKgno"[/color][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq tagn [b][color=NAVY]([/color][/b]strcase [b][color=MAROON]([/color][/b]getkword [color=#2f4f4f]"\nATTRIB Tag Name - supporttyPe/supportNo/Lineno/pKgno: "[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq tagv [b][color=NAVY]([/color][/b]strcase [b][color=MAROON]([/color][/b]getstring t [color=#2f4f4f]"\nATTRIB Tag Value String: "[/color][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq i [b][color=NAVY]([/color][/b]sslength ss[b][color=NAVY])[/color][/b] ssa [b][color=NAVY]([/color][/b]ssadd[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]not [b][color=MAROON]([/color][/b]minusp [b][color=GREEN]([/color][/b]setq i [b][color=BLUE]([/color][/b]1- i[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]setq mb [b][color=MAROON]([/color][/b]ssname ss i[b][color=MAROON])[/color][/b] en [b][color=MAROON]([/color][/b]entnext mb[b][color=MAROON])[/color][/b] ed [b][color=MAROON]([/color][/b]entget en[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]= [color=#2f4f4f]"ATTRIB"[/color] [b][color=GREEN]([/color][/b]cdr [b][color=BLUE]([/color][/b]assoc 0 ed[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]and [b][color=GREEN]([/color][/b]= tagn [b][color=BLUE]([/color][/b]cdr [b][color=RED]([/color][/b]assoc 2 ed[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]= tagv [b][color=BLUE]([/color][/b]cdr [b][color=RED]([/color][/b]assoc 1 ed[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]not [b][color=BLUE]([/color][/b]ssmemb mb ssa[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]ssadd mb ssa[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq en [b][color=GREEN]([/color][/b]entnext en[b][color=GREEN])[/color][/b] ed [b][color=GREEN]([/color][/b]entget en[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]if [b][color=NAVY]([/color][/b]not [b][color=MAROON]([/color][/b]zerop [b][color=GREEN]([/color][/b]sslength ssa[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]princ [b][color=MAROON]([/color][/b]strcat [color=#2f4f4f]"\nSelection Set ssa - "[/color] [b][color=GREEN]([/color][/b]rtos [b][color=BLUE]([/color][/b]sslength ssa[b][color=BLUE])[/color][/b] 2 0[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]alert [color=#2f4f4f]"\nNo INSERTS Were Found Matching This Criteria"[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] I'll have to look up and see if getkword can use mnenonics that are separated by other letters. -David Quote
jaylo23 Posted January 4, 2010 Author Posted January 4, 2010 Okay the lisp routine that Lee Mac and David helped me with works perfectly, but i tried to add to the lisp. What i am trying to do is after a block is selected using the lisp, it then zooms to the block and either keeps it slected or reselects it. I have no problem getting it to zoom to the block, but it seems to bomb out after that. Here is the code im using: (sssetfirst nil ssa) (if (zerop (sslength ssa))(alert "No supports meet your criteria.")) (cond ((= #ATT "supportno")((COMMAND "ZOOM" "OBJECT")(sssetfirst nil ssa)))) ) Any suggestions or reasoning why it is bombing out? Quote
Lee Mac Posted January 4, 2010 Posted January 4, 2010 You had a few too many brackets on the COND (if (zerop (sslength ssa)) (alert "No supports meet your criteria.") (cond ((= #ATT "supportno") (COMMAND "_.ZOOM" "_OBJECT") (sssetfirst nil ssa))) ) ;; IF Quote
jaylo23 Posted January 4, 2010 Author Posted January 4, 2010 It still doesnt select the block it just zooms to it and shows "(nil )" at the command line. Quote
Lee Mac Posted January 4, 2010 Posted January 4, 2010 I haven't got much to go on, but using David's code: ;;;CREATE A SELECTION BASED ON AN ATTRIBUTE TAG NAME AND VALUE ;;;ssa is global ;;;Revised 12-11-2009 (defun c:tagset (/ tagn tagv ss i en mb ed) (cond ((not (setq ss (ssget "X" (list (cons 0 "INSERT")(cons 66 1))))) (alert "\nNo Attribute INSERTs Found - Aborting") (exit))) (initget 1 "supporttyPe supportNo Lineno pKgno") (setq tagn (strcase (getkword "\nATTRIB Tag Name - supporttyPe/supportNo/Lineno/pKgno: "))) (setq tagv (strcase (getstring t "\nATTRIB Tag Value String: "))) (setq i (sslength ss) ssa (ssadd)) (while (not (minusp (setq i (1- i)))) (setq mb (ssname ss i) en (entnext mb) ed (entget en)) (while (= "ATTRIB" (cdr (assoc 0 ed))) (and (= tagn (cdr (assoc 2 ed))) (= tagv (cdr (assoc 1 ed))) (not (ssmemb mb ssa)) (ssadd mb ssa)) (setq en (entnext en) ed (entget en)))) (if (not (zerop (sslength ssa))) (alert "\nNo INSERTS Were Found Matching This Criteria") (cond ( (= "supportNo" tagn) (command "_.zoom" "object" ssa "") (sssetfirst nil ssa)))) (prin1)) Quote
jaylo23 Posted January 4, 2010 Author Posted January 4, 2010 After adding "(command "_.zoom" "object" ssa "") (sssetfirst nil ssa)))) it worked perfectly, thanks again Lee Mac, i spent the better part of 2 days trying to figure that one out! Quote
Lee Mac Posted January 4, 2010 Posted January 4, 2010 After adding "(command "_.zoom" "object" ssa "") (sssetfirst nil ssa)))) it worked perfectly, thanks again Lee Mac, i spent the better part of 2 days trying to figure that one out! You're welcome mate Quote
pnkysin Posted August 23, 2012 Posted August 23, 2012 Hello all, I read this thread and it really help me too, now im very new at visual lisp, and what im trying to do is to find a block but using three different tags instead of just one. I tried using the code that you built, but im not really good at it, if you can help me i will be very happy, thank you Quote
BIGAL Posted August 23, 2012 Posted August 23, 2012 pnkysin better off starting a new post for your question, but pretty simple to do need a nested IF If 1st tag and if 2nd tag and if 3rd tag do something Example for 1 attribute not complete code (setq ss1 (ssget "x" (list (cons 0 "INSERT")))) (setq len (sslength ss1)) (setq x 0) (repeat len (foreach att (vlax-invoke (vlax-ename->vla-object (ssname SS1 x )) 'getattributes) (if (= oldtag1 (strcase (vla-get-tagstring att))) ;(vla-put-textstring att newstr1) (princ oldtag) ) (setq x (+ x 1)) ) I am sure someone will help me and change to check 3 tags with ands rather tahn multiple IF's 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.