PDA

View Full Version : I'm after ideas on a lisp for updating a single atrribute


pedread
18-11-2004, 01:06 AM
For our Title blocks, the Revision is a Attribute ( on it's own, not inside a block ). We are after a way to update this attrib using lisp.
Say from A to B...B to C e.t.c.
would like it to be able to recognise what the attribute currently is, then update it to the next letter, without any user input.

Reason being, so that we can run the lisp from a batch file program, over a number of drawings, where each drawing may have a different revision than the next.

Cheers for any help/ideas
Dan

CarLB
18-11-2004, 01:56 AM
OK here's some off the cuff code...FWIW. You will want to add some error checking..

(defun AttUpdate ()
(setq AttList '("A" "B" "C" ......etc "Z"))
(setq BlockSet (ssget "X" '((0 . "BLOCK") (2 . "BlockNameHere"))))
(setq Blockname (ssname BlockSet 0))
(setq Attname (entnext BlockName))
(setq Attdata (entget Attname))
(setq AttVal (cdr (assoc 1 Attdata)))
(if (member AttVal AttList)
(setq AttVal (cadr (member AttVal AttList)))
)
(setq Attdata (subst (cons 1 AttVal) (assoc 1 Attdata) Attdata))
(entmod Attdata)
(entupd Blockname)
)

pedread
18-11-2004, 10:12 PM
Cheers,
I have written in exactly as you have said...but it's coming up with "; error: bad argument type: lselsetp nil" as soon as you try to run it?
I'm new to lisp...and not sure what that means....I've been getting the same error on some of my own attempts.
And....I was wrong...the attribute IS inside a block containing other attributes.

thanks again.


(defun c:AttUpdate ()
(setq AttList '("A" "B" "C" "D" "E" "F" "G" "H" "I"
"J" "K" "L" "M" "N" "O" "P" "Q" "R"
"S" "T" "U" "V" "W" "X" "Y" "Z"
)
)
(setq BlockSet (ssget "X" '((0 . "BLOCK") (2 . "a1sht-H"))))
(setq Blockname (ssname BlockSet 0))
(setq Attname (entnext BlockName))
(setq Attdata (entget Attname))
(setq AttVal (cdr (assoc 1 Attdata)))
(if (member AttVal AttList)
(setq AttVal (cadr (member AttVal AttList)))
)
(setq Attdata (subst (cons 1 AttVal) (assoc 1 Attdata) Attdata))
(entmod Attdata)
(entupd Blockname)
)

CarLB
18-11-2004, 10:42 PM
Oops, sorry Dan,

...one of the problems with untested code ...boo boos.

Change "BLOCK" to "INSERT". And if the revision attribute isn't the first attribute in the block, we'll have to make a modification to step through the attributes until a matching tag is found.

pedread
18-11-2004, 10:54 PM
Awesome....that's working...just not with the right attribute.
The revision attribute is the 5th one in the list when modifying manually.

CarLB
18-11-2004, 11:08 PM
Great! Now if it's alway' the 5th attribute I think the following code will step to it:

after
(setq Attname (entnext BlockName))

insert these lines:
(repeat 4
(setq AttName (entnext AttName))
)

pedread
18-11-2004, 11:13 PM
how easy was that!
now to just add some error control for if you try and run the program once it gets to the end of it's list.....
I would like to give that a go myself....see if I can figure it out...lol
but will check back with you if it's causing my head to explode!

Thanks heaps for that routine!