Cat Posted February 17, 2011 Posted February 17, 2011 Good Morning Lispers, I'm using the below lisp to target two attribute tags in some drawings, but I need to be able to choose which blocks are targeted because it's a common tag throughout the drawing. I appreciate it more than you know. (defun c:chgnonc (/ tagname new_val i ss en ch an ad) (setq tagname "TERM01") (setq new_val "3") (and (setq i -1 ss (ssget "X" '((0 . "INSERT")(66 . 1)))) (while (setq en (ssname ss (setq i (1+ i)))) (setq ch nil an (entnext en) ad (entget an)) (while (= "ATTRIB" (cdr (assoc 0 ad))) (and (= (strcase (cdr (assoc 2 ad))) (strcase tagname)) (entmod (subst (cons 1 new_val) (assoc 1 ad) ad)) (setq ch T)) (setq an (entnext an) ad (entget an))) (if ch (entupd en)))) (setq tagname "TERM02") (setq new_val "4") (and (setq i -1 ss (ssget "X" '((0 . "INSERT")(66 . 1)))) (while (setq en (ssname ss (setq i (1+ i)))) (setq ch nil an (entnext en) ad (entget an)) (while (= "ATTRIB" (cdr (assoc 0 ad))) (and (= (strcase (cdr (assoc 2 ad))) (strcase tagname)) (entmod (subst (cons 1 new_val) (assoc 1 ad) ad)) (setq ch T)) (setq an (entnext an) ad (entget an))) (if ch (entupd en)))) (prin1)) Quote
David Bethel Posted February 17, 2011 Posted February 17, 2011 By removing the "X" parameter from the (ssget) call, you now have to select the INSERTs You can add BLOCK name filtering in the (2 . "*") field. Edit the "*" value with block names or patterns "BLK1,BLK2" or "BLK*" or leave as "*" for all blocks. It accepts wildcard string searches. By making an associative list ( ev ) of edit values, you only have to go thru the set once. Add or remove atoms in the list as needed. But do keep the proper ( dotted pairs in this case) [b][color=BLACK]([/color][/b]defun chmultag [b][color=FUCHSIA]([/color][/b]/ ev ss en ch an ad tn[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq ev '[b][color=NAVY]([/color][/b][b][color=MAROON]([/color][/b][color=#2f4f4f]"TERM01"[/color] . [color=#2f4f4f]"3"[/color][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b][color=#2f4f4f]"TERM02"[/color] . [color=#2f4f4f]"4"[/color][b][color=MAROON])[/color][/b][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 '[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]2 . [color=#2f4f4f]"*"[/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]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 ch nil 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 tn [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]assoc tn ev[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]setq ch T[b][color=BLUE])[/color][/b] [b][color=BLUE]([/color][/b]entmod [b][color=RED]([/color][/b]subst [b][color=PURPLE]([/color][/b]cons 1 [b][color=TEAL]([/color][/b]cdr [b][color=OLIVE]([/color][/b]assoc tn ev[b][color=OLIVE])[/color][/b][b][color=TEAL])[/color][/b][b][color=PURPLE])[/color][/b] [b][color=PURPLE]([/color][/b]assoc 1 ad[b][color=PURPLE])[/color][/b] ad[b][color=RED])[/color][/b][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]and ch [b][color=GREEN]([/color][/b]entupd en[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=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] Pretty well untested. Have fun! -David Quote
Cat Posted February 17, 2011 Author Posted February 17, 2011 Thanks David. I was hoping to be able to use the old lisp (since I'm the lisp village idiot) and be able to get user input to pick the blocks with a crossing or window. The blocks aren't consistent, but relflect NO or NC contact states for different devices), but that may be a tall order. Quote
David Bethel Posted February 17, 2011 Posted February 17, 2011 Simply remove the "X" from the ( ssget ) calls. That will force a user input. As to NO & NC, do the blocks have unique names? -David Quote
Cat Posted February 17, 2011 Author Posted February 17, 2011 As to NO & NC, do the blocks have unique names? Not consistent David. I'll give it another shot. Either way, I appreciate it. Quote
BIGAL Posted February 18, 2011 Posted February 18, 2011 You can add extra "mode" to ssget check help for options P L I W C X WP CP etc so you get say your crossing window as default pick method as well as the filtering. 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.