HI All,
I did some searching and can't seem to find what I'm looking for, so I apologize if it exists somewhere and I missed it. If I did miss the information if you could kindly direct me to the specific thread I would appreciate it.
Ok, so what I'm trying to do is find a specific copy of a block, the block I'm trying to find is used multiple times in 1 drawing as part of the bill of material. I know the value of 1 attribute in the block, which in this case is a part number, now I want to be able to modify the value of a different attribute in the block based on finding it by the value of the part number. How would I go about figuring out which block is the one that I want to modify?
Solved! Go to Solution.
Solved by Gary_J_Orr. Go to Solution.
I think if the there is not much duplication happens among attribute values under different attribute tags, you can just Find and Replace.
Otherwise you can try attached ALTEXT.vlx and set the "Start from" and "End at" to the same value, as the example settings below.
Input a new text in "New text" box, or add a number to existing figures by filling in "Increment" box.
Hi 3wood,
It sounds like this is something that the user of the program would have to use. I want to make it so that the user won't have to use anything like that to change the quantity(which is the value that I want to change)
Here is a very simple attribute find & replace function - it will simply iterate over all attributed blocks in all layouts of the drawing, and if the first supplied value is found, it will be replaced with the second supplied value:
(defun replace-att-value ( old new / a e i s x ) (setq old (strcase old) new (cons 1 new) ) (if (setq s (ssget "_X" '((0 . "INSERT") (66 . 1)))) (repeat (setq i (sslength s)) (setq e (entnext (ssname s (setq i (1- i)))) x (entget e) ) (while (= "ATTRIB" (cdr (assoc 0 x))) (if (= old (strcase (cdr (setq a (assoc 1 (reverse x)))))) (entmod (subst new a x)) ) (setq e (entnext e) x (entget e) ) ) ) ) (princ) )
Call the above with the find & replace strings:
(replace-att-value "abc" "123")
The 'find' string is not case-sensitive.
The function is very generic, but could easily be modified to search only blocks of a specific name, or on a particular layer etc.
@AR12 wrote:HI All,
I did some searching and can't seem to find what I'm looking for, so I apologize if it exists somewhere and I missed it. If I did miss the information if you could kindly direct me to the specific thread I would appreciate it.
Ok, so what I'm trying to do is find a specific copy of a block, the block I'm trying to find is used multiple times in 1 drawing as part of the bill of material. I know the value of 1 attribute in the block, which in this case is a part number, now I want to be able to modify the value of a different attribute in the block based on finding it by the value of the part number. How would I go about figuring out which block is the one that I want to modify?
Methinks that some of the other replies have missed your main goal (as highlighted above)...
Try this (it will return a selection set of blocks on your current layout tab that match a given block name, with a given Attribute Name, and a given value for that attribute):
;returns a selection set of all blocks matching requested values ;call with something like: ;(setq Blkset (GetBlksByAttVal "Block Name" "Attribute Name" "Attribute Value")) (defun GetBlksByAttVal (BlkName AttName AttVal / ss ReturnSS Ctr InsEnt Att AttList) (setq ss (ssget "_X" (list '(0 . "INSERT") (cons 2 BlkName) '(66 . 1) (cons 410 (getvar "ctab")) ))) (setq ReturnSS (ssadd)) (setq Ctr 0) (while (< Ctr (sslength ss)) (setq InsEnt (ssname ss Ctr)) (setq Att (entnext InsEnt)) (setq AttList (entget Att)) (while (= "ATTRIB" (cdr (assoc 0 Attlist))) (if (and (= (strcase AttName) (strcase (cdr (assoc 2 Attlist)))) (= (strcase AttVal) (strcase (cdr (assoc 1 Attlist)))) ) (ssadd InsEnt ReturnSS) );if the correct attribute (setq Att (entnext Att)) (setq AttList (entget Att)) );while attributes (setq Ctr (1+ Ctr)) );while ss members (if (> (sslength ReturnSS) 0) ReturnSS nil ) );defun
Happy Lisping
-Gary
Gary,
Thanks, I will try that and see if I can make that work for what I'm trying to do.
Lee,
While this sounds like it could possibly work, the issue I have is the value that I want to change could potentially be the same in multiple spots of the same block name which is why I need to be able to find the value of a different attribute in the block.
Hi Gary,
I'm not sure if I'm making a mistake with how I'm trying to use the function but I pasted it into Visual LISP and Loaded the Function. Then in the console I tried to use the function and I'm getting a Error: bad SSGET list value. I've attached the screenshots to this post so you can see the Attribute edit box which you can see the Block Name, Attribute Name and the current value and I've also attached a screenshot of the Console in Visual LISP so you can see what I input.
Hi Gary,
Thanks. Now that I put those items in parentheses the function worked. Now that I see how the function worked I'll see if I can utilize it for what I'm looking to do.
Thanks for the Help Gary,
That function allowed me to be able to accomplish what I needed to do. Once I remembered how to do what I was trying to do that is.
@AR12 wrote:Thanks for the Help Gary,
That function allowed me to be able to accomplish what I needed to do. Once I remembered how to do what I was trying to do that is.
Remembering where you were going in the first place is often the toughest part after getting sidetracked with some other....
...shiney...
oops, sorry, now where was I?
Oh well... *ReallyBigGrin*
Glad I could help
-Gary