homasa Posted August 16, 2012 Share Posted August 16, 2012 Hello PPL I need to optimize my work and i have a lot of blocks to count so i decided to give lisp a try (i am a nneewwwbbiieee). How can i select "blocks made of attribute entities" or "plain attributes entities"? Real life example: 1) prompt the user to give a name and a number ( name of entity/block and a number ) 2) by using what the user prompt I wanna it to select a set of blocks or entities ( the best solution you consider ) that match: a) Tag ( name) b) value ( number) sorry for my english, am i making any sense at all??? regards Quote Link to comment Share on other sites More sharing options...
David Bethel Posted August 16, 2012 Share Posted August 16, 2012 Since you cannot ssget filter for ATTRIButes, you must step thru all of the INSERTS that have sequential ATTRIButes. [b][color=BLACK]([/color][/b]defun c:findaval [b][color=FUCHSIA]([/color][/b]/ tag val ss en ed an ad at av[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]while [b][color=NAVY]([/color][/b]or [b][color=MAROON]([/color][/b]not tag[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]not [b][color=GREEN]([/color][/b]snvalid tag[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]setq tag [b][color=MAROON]([/color][/b]strcase [b][color=GREEN]([/color][/b]getstring [color=#2f4f4f]"\nTag Name: "[/color][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]setq val [b][color=NAVY]([/color][/b]getstring t [color=#2f4f4f]"\nAttribute Value: "[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]setq ss [b][color=MAROON]([/color][/b]ssget [color=#2f4f4f]"X"[/color] '[b][color=GREEN]([/color][/b][b][color=BLUE]([/color][/b]0 . [color=#2f4f4f]"INSERT"[/color][b][color=BLUE])[/color][/b][b][color=BLUE]([/color][/b]66 . 1[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 is [b][color=MAROON]([/color][/b]ssadd[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]setq en [b][color=GREEN]([/color][/b]ssname ss 0[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq ed [b][color=GREEN]([/color][/b]entget en[b][color=GREEN])[/color][/b] an [b][color=GREEN]([/color][/b]entnext en[b][color=GREEN])[/color][/b] ad [b][color=GREEN]([/color][/b]entget an[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]while [b][color=GREEN]([/color][/b]= [color=#2f4f4f]"ATTRIB"[/color] [b][color=BLUE]([/color][/b]cdr [b][color=RED]([/color][/b]assoc 0 ad[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]setq av [b][color=BLUE]([/color][/b]cdr [b][color=RED]([/color][/b]assoc 1 ad[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] at [b][color=BLUE]([/color][/b]cdr [b][color=RED]([/color][/b]assoc 2 ad[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]and [b][color=BLUE]([/color][/b]= [b][color=RED]([/color][/b]strcase at[b][color=RED])[/color][/b] tag[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]= [b][color=RED]([/color][/b]strcase av[b][color=RED])[/color][/b] val[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]not [b][color=RED]([/color][/b]ssmemb en is[b][color=RED])[/color][/b][b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]ssadd en is[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]setq an [b][color=BLUE]([/color][/b]entnext an[b][color=BLUE])[/color][/b] ad [b][color=BLUE]([/color][/b]entget an[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]ssdel en ss[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]prin1 [b][color=NAVY]([/color][/b]sslength is[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] The PICKSET is contains the ename(s) of the matching entities. HTH -David Quote Link to comment Share on other sites More sharing options...
homasa Posted August 16, 2012 Author Share Posted August 16, 2012 Hello David, thx for the reply this routine gives me the number of blocks that have that attributes, correct ?? i am sorry because i induced you in error because i wanna count them visually ..... by that i mean that it select all them containing these values.. sorry by the way i found that using this code works if the attdef isnt a block yet... (defun c:teste () (sssetfirst nil (ssget "_X" '((0 . "ATTDEF")(2 . "QPP3")(1 . "201")))) (princ) ) this is simplier than your code, can it be done with blocks also or i do have to do as you say???? sorry i am really newbie at lisp.. regards Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 16, 2012 Share Posted August 16, 2012 This ... ? (defun c:Test (/ n v ss s in sn nx e) ;;; Tharwat 16. Aug. 2012 ;;; (if (and (not (eq (setq n (getstring "\n Name of Attributed Block :")) "") ) (not (eq (setq v (getstring "\n Attribute Value :")) "")) (setq ss (ssget "_x" (list '(0 . "INSERT") '(66 . 1) (cons 2 n)))) (setq s (ssadd)) ) (repeat (setq in (sslength ss)) (setq sn (ssname ss (setq in (1- in)))) (setq nx (entnext sn)) (while (not (eq (cdr (assoc 0 (setq e (entget nx)))) "SEQEND" ) ) (if (eq (cdr (assoc 1 e)) v) (ssadd sn s) ) (setq nx (entnext nx)) ) ) (cond ((not n) (princ "\n Error .. cancel by the user !!")) ((not v) (princ "\n Error .. cancel by the user !!")) (t (princ "\n Couldn't find and any block !!")) ) ) (if (and s (> (sslength s) 0)) (sssetfirst nil s) (princ "\n Nothing matched your inputs !!") ) (princ) ) Quote Link to comment Share on other sites More sharing options...
homasa Posted August 16, 2012 Author Share Posted August 16, 2012 David, Tharwat Thx you guys very much for the input. I really thought it was much simple .... Thx alot again regards p.s. still have a lot, a lot to learn ... hehe Quote Link to comment Share on other sites More sharing options...
homasa Posted August 16, 2012 Author Share Posted August 16, 2012 Hello , i am trying to also inform the user that there are X number of blocks found but this gives me error...."; error: bad argument type: stringp 1" why? (defun c:Test (/ n v ss s in sn nx e h) ;;; Tharwat 16. Aug. 2012 ;;; (if (and (not (eq (setq n (getstring "\n Name of Attributed Block :")) "") ) (not (eq (setq v (getstring "\n Attribute Value :")) "")) (setq ss (ssget "_x" (list '(0 . "INSERT") '(66 . 1) (cons 2 n)))) (setq s (ssadd)) ) (repeat (setq in (sslength ss)) (setq sn (ssname ss (setq in (1- in)))) (setq nx (entnext sn)) (while (not (eq (cdr (assoc 0 (setq e (entget nx)))) "SEQEND" ) ) (if (eq (cdr (assoc 1 e)) v) (ssadd sn s) ) (setq nx (entnext nx)) ) ) (cond ((not n) (princ "\n Error .. cancel by the user !!")) ((not v) (princ "\n Error .. cancel by the user !!")) (t (princ "\n Couldn't find and any block !!")) ) ) (if (and s (> (sslength s) 0)) (sssetfirst nil s) (princ "\n Nothing matched your inputs !!") ) (setq h (sslength s)) (alert (strcat "\nNumber of Blocks Found = " h)) (princ) ) thx in advanced Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 16, 2012 Share Posted August 16, 2012 untested , try it like this .... (if (and s (> (sslength s) 0)) (progn (sssetfirst nil s) (alert (strcat "\nNumber of Blocks Found = " " < " (sslength s) " > ")) ) (princ "\n Nothing matched your inputs !!") ) (princ) ) Quote Link to comment Share on other sites More sharing options...
homasa Posted August 16, 2012 Author Share Posted August 16, 2012 gives me the same error: bad argument type: stringp 1 Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 16, 2012 Share Posted August 16, 2012 (defun c:Test (/ n v ss s in sn nx e) ;;; Tharwat 16. Aug. 2012 ;;; (if (and (not (eq (setq n (getstring "\n Name of Attributed Block :")) "") ) (not (eq (setq v (getstring "\n Attribute Value :")) "")) (setq ss (ssget "_x" (list '(0 . "INSERT") '(66 . 1) (cons 2 n)))) (setq s (ssadd)) ) (repeat (setq in (sslength ss)) (setq sn (ssname ss (setq in (1- in)))) (setq nx (entnext sn)) (while (not (eq (cdr (assoc 0 (setq e (entget nx)))) "SEQEND" ) ) (if (eq (cdr (assoc 1 e)) v) (ssadd sn s) ) (setq nx (entnext nx)) ) ) (cond ((not n) (princ "\n Error .. cancel by the user !!")) ((not v) (princ "\n Error .. cancel by the user !!")) (t (princ "\n Couldn't find and any block !!")) ) ) (if (and s (> (sslength s) 0)) (progn (sssetfirst nil s) (alert (strcat "\nNumber of Blocks Found = " " < " (itoa (sslength s)) " > " ) ) ) (princ "\n Nothing matched your inputs !!") ) (princ) ) Quote Link to comment Share on other sites More sharing options...
homasa Posted August 16, 2012 Author Share Posted August 16, 2012 Thx a Lot Tharwat that works great this will help me very much hehehe now i am trying to change a script (txt2att) that will create those blocks like take a piece of text and then convert to att and to block.. if i cant do it i will return to the forum. Thx very much again regards Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 16, 2012 Share Posted August 16, 2012 You're welcome anytime homasa . Tharwat Quote Link to comment Share on other sites More sharing options...
homasa Posted August 17, 2012 Author Share Posted August 17, 2012 hello again Tharwat in fact i need just one more thing : this searches all of the blocks inside the drawing correct? is this possible to narrow the search to selected items, like the qselect does??? or explaining better select a bunch of objects ( including text) and then it only verifies on that selection....??? can this be done?? thx in advanced Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 17, 2012 Share Posted August 17, 2012 Just remove the "_x" from the code . if you need the code to select texts also , you should add more codes to obtain that . (setq ss (ssget [color=red][b]"_x"[/b][/color] (list '(0 . "INSERT") '(66 . 1) (cons 2 n)))) Quote Link to comment Share on other sites More sharing options...
homasa Posted August 17, 2012 Author Share Posted August 17, 2012 sorry Tharwat i was with my mind in another thing....no select text but blocks. please excuse me. but after a bit of research of what you said instead of removing "_x" i substituted for "_w" and now it works like i wanna him to. Thx alot you save my day .. again Just remove the "_x" from the code . if you need the code to select texts also , you should add more codes to obtain that . (setq ss (ssget [color=red][b]"_x"[/b][/color] (list '(0 . "INSERT") '(66 . 1) (cons 2 n)))) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 17, 2012 Share Posted August 17, 2012 Not a problem . Quote Link to comment Share on other sites More sharing options...
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.