ted Posted February 6, 2012 Posted February 6, 2012 Dear Sir, DWG files as attachments with the property automatically changes the contents of the block to obtain a lisp. Drawing on one of several properties, which blocks one hundred and twelve: but change is hard. Usually, if the limit on the things around 1000-2000. Please help. Thanks, Ted attribute change.dwg Quote
irneb Posted February 7, 2012 Posted February 7, 2012 Straight AutoLisp (no VLisp used): (defun c:GTC-PART-Layer (/ ss n en ed an ad s) (if (setq ss (ssget '((0 . "INSERT") (2 . "GTC-PART")))) (progn (setq n (sslength ss)) (while (> (setq n (1- n)) -1) (setq en (ssname ss n) ed (entget en) an (entnext en)) (while (and (setq ad (entget an)) (eq (cdr (assoc 0 ad)) "ATTRIB") (not (eq (cdr (assoc 2 ad)) "PARTNO"))) (setq an (entnext an)) ) (if (eq (cdr (assoc 2 ad)) "PARTNO") (progn (setq s (cdr (assoc 1 ad))) (while (wcmatch s "*-*") (setq s (substr s 1 (1- (strlen s))))) (setq s (strcat s "-" (cdr (assoc 8 ed)))) (entmod (subst (cons 1 s) (assoc 1 ad) ad)) ) ) ) ) ) (princ) ) Quote
pBe Posted February 7, 2012 Posted February 7, 2012 Geez Irneb ... how'd you come up with that? you figure thats what the OP wants? I read the request half a dozen times and i still cant understand what the OP is trying to say.. Reminder: entmod and annotative TEXT?MTEXT/ATTDEF doesnt work well together Quote
irneb Posted February 7, 2012 Posted February 7, 2012 Geez Irneb ... how'd you come up with that? you figure thats what the OP wants? I read the request half a dozen times and i still cant understand what the OP is trying to say.. Reminder: entmod and annotative TEXT?MTEXT/ATTDEF doesnt work well together That's afaikt what his DWG is showing. The post is a bit confusing yes. There's a "sarcastic" saying in my mother tongue, which directly translates in English: "Half an understanding requires a good explanation". It's actually meant to mean the opposite . As for entmod on annotative stuff, yes you're correct. Usually I'd not use entmod here, but the OP's is so specific (if I read it correctly) I didn't mind doing it on these non-dynamic, non-annotative block. You'll note the code has the block & attrib names hard-coded. Anyhow, here's the VLisp version to ease the possible problems with entmod: (defun c:GTC-PART-Layer1 (/ ss s) (if (and (ssget '((0 . "INSERT") (2 . "GTC-PART"))) (setq ss (vla-get-ActiveSelectionSet (vla-get-ActiveDocument (vlax-get-acad-object)))) ) (progn (vlax-for eo ss (foreach ao (vlax-safearray->list (vlax-variant-value (vla-GetAttributes eo))) (if (eq (vla-get-TagString ao) "PARTNO") (progn (setq s (vla-get-TextString ao)) (while (wcmatch s "*-*") (setq s (substr s 1 (1- (strlen s))))) (setq s (strcat s "-" (vla-get-Layer eo))) (vla-put-TextString ao s) ) ) ) ) (vla-Delete ss) ) ) (princ) ) Quote
pBe Posted February 7, 2012 Posted February 7, 2012 As for entmod on annotative stuff, yes you're correct. Usually I'd not use entmod here, but the OP's is so specific (if I read it correctly) I didn't mind doing it on these non-dynamic, non-annotative block. You'll note the code has the block & attrib names hard-coded. I concur Anyhow, here's the VLisp version to ease the possible problems with entmod (defun c:GTC-PART-Layer1 (/ ss s) ... While you're at it, might as well check for "EffectiveName" to go with your VL code. you'll never know, someday they might decide to use Dynamic Blocks (just saying) Quote
irneb Posted February 7, 2012 Posted February 7, 2012 While you're at it, might as well check for "EffectiveName" to go with your VL code. you'll never know, someday they might decide to use Dynamic Blocks (just saying) Well, then this should do:(defun c:GTC-PART-Layer2 (/ ss s) (if (and (ssget '((0 . "INSERT"))) (setq ss (vla-get-ActiveSelectionSet (vla-get-ActiveDocument (vlax-get-acad-object)))) ) (progn (if (eq (vla-get-EffectiveName eo) "GTC-PART") (vlax-for eo ss (foreach ao (vlax-safearray->list (vlax-variant-value (vla-GetAttributes eo))) (if (eq (vla-get-TagString ao) "PARTNO") (progn (setq s (vla-get-TextString ao)) (while (wcmatch s "*-*") (setq s (substr s 1 (1- (strlen s))))) (setq s (strcat s "-" (vla-get-Layer eo))) (vla-put-TextString ao s) ) ) ) ) ) (vla-Delete ss) ) ) (princ) ) And then just to be funny: Make this into a "general-purpose" one where you can pick which block/tag to be altered how, and rather than simply setting the value insert a field-code. That way you could have changed the layer of selected blocks and after a regen the values are updated. Which actually shows you could have accomplished this simply by placing the same fieldcode inside the block def's default value for that AttDef. To have all existing block references updated to suit, rename the AttDef in the block editor, bclose, AttSync. No need for lisp realy 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.