View Full Version : Changing Only Attributes That Haven't Been Changed
stusic
2008-02-20, 10:00 PM
Hey All,
I'm trying to figure out how to add 1 to the value of attributes in a drawing, but not ones that have already been changed. Some kind of list that doesn't loop or something.
I've got a bunch of attributes in sequential order, but if I add one to the middle, it messes up my numbering. So what I'd like to do is when I add the attributed block to the middle, run a lisp that prompts me for a number, and it adds 1 to every instance of that block that is a higher value.
So... how do I go about: 1.) restricting the changes to only attributes that are higher than the prompted amount, and 2.) keep it from looping around adding 1 to an instance that's already been modified?
Thanks for all of your help! :)
T.Willey
2008-02-20, 10:59 PM
Shouldn't be too hard. Ask the user for a number to start at (integer). Then get the block name, and the tag name to change. Use ssget to get the blocks. Then loop through the selection set of blocks, and then go through the attributes for each block. When you find the tag that matches the tag to change, check to see what the value is (change the string to an integer for easier comparison). If it's higher, or equal, then add one (or another amount if you want) to the attribute, and change the attribute (entmod) and update the display (entupd). You will only go through the selection set once, so you won't have to worry about changing an attribute more than once.
T.Willey
2008-02-21, 12:32 AM
Had a minute.
(defun c:Test (/ ActDoc Num Sel EntData TagStr BlkName tempNum Amnt)
(setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)))
(vla-EndUndoMark ActDoc)
(vla-StartUndoMark ActDoc)
(if
(and
(setq Amnt
(cond
((getint "\n Enter amount to add to tag string <1>: "))
(t 1)
)
)
(setq Num (getint (strcat "\n Select number to add " (itoa Amnt) " to if equal or greater: ")))
(setq Sel (nentsel "\n Select desired attribute within block to adjust: "))
(setq EntData (entget (car Sel)))
(= (cdr (assoc 0 EntData)) "ATTRIB")
(setq TagStr (cdr (assoc 2 EntData)))
(setq BlkName (cdr (assoc 2 (entget (cdr (assoc 330 EntData))))))
(ssget (list (cons 0 "INSERT") (cons 2 BlkName)))
)
(vlax-for blk (vla-get-ActiveSelectionSet ActDoc)
(foreach att (vlax-invoke blk 'GetAttributes)
(if
(and
(= (vla-get-TagString att) TagStr)
(<= Num (setq tempNum (atoi (vla-get-TextString att))))
)
(vla-put-TextString att (itoa (+ Amnt tempNum)))
)
)
)
)
(vla-EndUndoMark ActDoc)
(princ)
)
irneb
2008-02-21, 05:41 AM
You might think of using extended data to point to each next block in the list, the last value just having nil. Then you'll just have some code to "insert" a block in between or "add" to the end, incrementing the value any later blocks in the list.
Otherwise you could of course setup the value of an attribute using a field adding 1 to the value of the attrib in the previous block. Although to get each pointing to the previous would also require some lisp, it's just too cumbersome to do it manually.
stusic
2008-02-21, 02:52 PM
Had a minute.
Wow, thanks :) I couldn't quite get it to work though...
I enter how much I want to add (although I only need to add one ever), and I input the number I want to add one to (in the attached example, it's 4). But after I do that, I go to select my block and it only changes the attribute I selected, instead of all the "greater" attributes. Does it make a difference that I've got to select the attribute twice? I've attached an example drawing, where the attribute 50 has been inserted in between 3 and 4.
Thanks for your help Tim!
You might think of using extended data to point to each next block in the list, the last value just having nil. Then you'll just have some code to "insert" a block in between or "add" to the end, incrementing the value any later blocks in the list.
Otherwise you could of course setup the value of an attribute using a field adding 1 to the value of the attrib in the previous block. Although to get each pointing to the previous would also require some lisp, it's just too cumbersome to do it manually.
That's waaay over my head. It sounds good, but I have no idea how to code that. :shock:
T.Willey
2008-02-21, 05:02 PM
Wow, thanks :) I couldn't quite get it to work though...
I enter how much I want to add (although I only need to add one ever), and I input the number I want to add one to (in the attached example, it's 4). But after I do that, I go to select my block and it only changes the attribute I selected, instead of all the "greater" attributes. Does it make a difference that I've got to select the attribute twice? I've attached an example drawing, where the attribute 50 has been inserted in between 3 and 4.
Thanks for your help Tim!
I don't see any attachment in your post. It makes a difference if the block you are using is a dynamic block, and the properties have been changed, because it will make it an anomalous block, so there won't be any matching names. If that is the case we can change it a little and all will be good again.
stusic
2008-02-21, 05:39 PM
Yep, you're right, I forgot the attachment... :roll:
It's not a DB, just plain-jane blocks...
T.Willey
2008-02-21, 05:46 PM
Everything worked here. You have to select the attribute once so the program knows which block and tag to change. You then select again which blocks you want to change, this step can be taken out of you want the program to select all and change them. If that is the case, then you need to change this line
(ssget (list (cons 0 "INSERT") (cons 2 BlkName)))
to
(ssget "x" (list (cons 0 "INSERT") (cons 2 BlkName)))
stusic
2008-02-21, 06:00 PM
Great! It works now! I did replace the line as offered (this attribute is unique to this block, and the only one I'll need to change like this). Thanks oodles. :)
I think what I was doing was selecting the "50"; since there weren't any numbers above 50, it's the only one that changed. Sheesh, I sooo don't pay attention sometimes. :roll:
Hey look! A kitten!
T.Willey
2008-02-21, 06:09 PM
You're welcome. Glad it works for you.
An FYI.... If you enter a negative number for the number to add, it will subtract so that if you remove a note from the middle you can use the same program to subtract numbers.
stusic
2008-02-21, 08:44 PM
You're welcome. Glad it works for you.
An FYI.... If you enter a negative number for the number to add, it will subtract so that if you remove a note from the middle you can use the same program to subtract numbers.
Sweet! I had actually thought that the removal of a number might be handy also, so this is great news. Thanks again. :)
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.