TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: CADaver on March 18, 2004, 09:44:48 AM

Title: Cross layout attribute editting
Post by: CADaver on March 18, 2004, 09:44:48 AM
Let's say I have DRAWN-BY as an attirbute in a block called TITLE.  How do I go about changing that attribute from whatever it is now (could be anything) to "CADaver" (or whatever I key in as a response to NEW VALUE?) in every layout?
Title: Cross layout attribute editting
Post by: hudster on March 18, 2004, 10:41:14 AM
you could write a script to do it.

I done this with 250 drawings changed all from tender to Building warrant without having to do each one individually.

Code: [Select]
;;;EDIT TITLE BLOCK;;;
-ATTEDIT
NO
NO
TITLE                      ;;Block I want to change
DRAWING-STATUS    ;;;Attribute I want to change
TENDER                   ;;;Current attribute value
TENDER                   ;;;Value I wish to change
BUILDING WARRANT ;;;New attribute value


Saved me about 2 hours work
Title: Cross layout attribute editting
Post by: CADaver on March 18, 2004, 10:52:53 AM
I was looking for something a little different, I'm quite aware of -attedit N N and use it frequently.  

I have a little function that promts the user for some info and changes the attributes accordingly.  Unfortunatly, it only changes the first layout tab.  I was looking for some direction in automating the manipulation of all matching attribute tags, regardless of "tab" location.
Title: Cross layout attribute editting
Post by: daron on March 18, 2004, 11:35:22 AM
This is by no means a finished idea. Maybe as a group we can build it, if anybody's interested.
Code: [Select]

(defun attribute-list (x)
     (vlax-safearray->list
 (vlax-variant-value
      (vla-GetAttributes x)
 )
     )
)

(defun each-attribute (x string newval)
     (if (= (vlax-get-property x 'TagString) string)
 (vlax-put-property
      x
      'TextString
      (vlax-make-variant newval vlax-vbstring)
 )
     )
)

;;; FUNCTION
;;; Create a LIST of VLA-OBJECTS from a SELECTION SET
;;; Does not verify SELECTION SET or LIST
;;;
;;; ARGUMENTS
;;; ss = valid selection set
;;; lst = nil or valid list
;;;
;;; USAGE
;;; (setq ss (ssget))
;;; (setq vl-objs (ss->vla-list ss nil)
;;;
;;; add to the previous list of VLA-OBJECTS
;;; (setq ss (ssget))
;;; (setq vl-objs (ss->vla-list ss vl-objs))
;;;
;;; PLATFORMS
;;; 2000+
;;;
;;; AUTHOR
;;; Copyright© 2003 Mark S. Thomas
;;; mark.thomas@theswamp.org
;;;
;;; VERSION
;;; 1.0 Fri Nov 21, 2003
(defun ss->vla-list (ss lst)
  (cond ((ssname ss 0)
    (setq lst (append (list
      (vlax-ename->vla-object (ssname ss 0))) lst))
     (ss->vla-list (ssdel (ssname ss 0) ss) lst)); 1st cond
    ((null (ssname ss 0)) lst); 2nd cond
    ); cond
  )

(defun blocksel (bname)
     (ss->vla-list (ssget "x" (list (cons 2 bname))))
)


(foreach item (blocksel "addblocknamehere")
 (setq att-list (attribute-list item))
 (foreach att att-list
      (each-attribute att "tagnamehere" "newvaluehere")
 )
     )


attribute-list function added to work with the foreach portion above. Sorry about not adding it before. I actually had it in, but didn't see it in any other code, so I erased it. P.S. All the above code is in pieces and parts. You'll need to work out how to put it all together. There might be more to it that you need. Also, Mark's part of it is just the ss->vla-list function and YES, it is a sweet function.
Title: Cross layout attribute editting
Post by: CADaver on March 18, 2004, 01:26:27 PM
I'm getting an error with ss->vla-list   ; error: too few arguments

I'm assuming that ss->vla-list is some bit of magic cooked up by some magician floating around here?  cuz' I can't find any help on it.
Title: Cross layout attribute editting
Post by: ronjonp on March 18, 2004, 01:27:09 PM
Cadaver,

You have express tools? If so, Global Attribute edit will do what you want. (gatte)

HTH

Ron
Title: Cross layout attribute editting
Post by: ELOQUINTET on March 18, 2004, 01:32:32 PM
yeah that's what i was thinking gatte does that. if you don't have express check out trevs global attribute editor in show your stuff. i think it's actually better than the express one.
Title: Cross layout attribute editting
Post by: CADaver on March 18, 2004, 01:33:58 PM
Quote from: ronjonp
Cadaver,You have express tools? If so, Global Attribute edit will do what you want. (gatte)


Sorta, I was looking for something a little more automatic.  Key-in a command reply with user name and boom, the block is modified for current date, time, user name, etc. without having to edit each one.
Title: Cross layout attribute editting
Post by: CADaver on March 18, 2004, 01:38:50 PM
Quote from: eloquintet
check out trevs global attribute editor in show your stuff. i think it's actually better than the express one.


I use that quite often, slick tool.  I was looking for something a little more idiot-proof for the 150 users around here.  What I've been using only works on the first block it finds, and ignores the blocks in subsequent layout tabs.

I'm really intriged by daron's post of Mark's routine.  Ifn' I kin figger it out.
Title: Cross layout attribute editting
Post by: daron on March 18, 2004, 01:49:09 PM
My first post has been updated. Check notes at the bottom.
Title: Cross layout attribute editting
Post by: SMadsen on March 18, 2004, 01:53:11 PM
A simple approach:

Code: [Select]
(defun changeAtt (ent tag val / entl ins)
  (setq ins ent)
  (while (and ent
           (/= "SEQEND" (cdr (assoc 0 (setq entl (entget ent))))))
    (if (and (= (cdr (assoc 0 entl)) "ATTRIB")
             (= (cdr (assoc 2 entl)) tag))
      (entmod (subst (cons 1 val) (assoc 1 entl) entl)))
    (setq ent (entnext ent)))
  (entupd ins)
)

(defun C:CADaver ()
  (cond ((setq sset (ssget "X" '((2 . "TITLE") (66 . 1))))
         (setq a 0)
         (repeat (sslength sset)
           (setq ent (ssname sset a)
                 a   (1+ a)
           )
           (changeAtt ent "DRAWN-BY" "CADaver") ;<- change value
         )
        )
  )
  (princ)
)
Title: Cross layout attribute editting
Post by: daron on March 18, 2004, 02:26:02 PM
Fine. Just give it to him. I see how it is.






Nah, I would've if I had more time. All that stuff was previously written.
Title: Cross layout attribute editting
Post by: CADaver on March 18, 2004, 02:32:34 PM
Thanks guys, I appreciate the steering.  I think I now have enough hammers to beat this into submission.  I'll let you know how it works out.
Title: Cross layout attribute editting
Post by: SMadsen on March 18, 2004, 02:33:28 PM
Hey, you're not allowed to hog CADaver by having him spend time on thinking about how to write lisp. I need him to keep my favorite subject alive in Lagniappe :)

.. and that stuff was previously written anyway
Title: Cross layout attribute editting
Post by: CADaver on March 18, 2004, 02:37:17 PM
Quote from: Daron
Fine. Just give it to him. I see how it is.
Come on, cut 'em some slack, everyone knows how lisp-challenged I am.

I'm still looking at that bit of code you've posted.  That has potential for even more mayhem than I was originally looking for...  :twisted: ... hee hee hee.  Thanks.

Man I gotta learn this stuff.
Title: Cross layout attribute editting
Post by: CADaver on March 18, 2004, 02:41:01 PM
Quote from: SMadsen
Hey, you're not allowed to hog CADaver by having him spend time on thinking about how to write lisp. I need him to keep my favorite subject alive in Lagniappe :)

.. and that stuff was previously written anyway


 :D That "one" over there makes my head hurt.  It's been 2 years since I left university and I'm having to re-research ('cuz I'm old, can't remember) a lot of the data about current constructs. :horror:
Title: Cross layout attribute editting
Post by: ronjonp on March 18, 2004, 02:42:11 PM
Quote
Man I gotta learn this stuff.


I hear ya there.....

 :D
Title: Cross layout attribute editting
Post by: CADaver on March 18, 2004, 05:57:45 PM
Thanks for the help guys.  Here's what I wound up with (until I can get my head around the code daron posted)

Code: [Select]
;;
;;Stamp block editor, with a lotta help from
;;the guys at The Swamp -
;;Mark Thomas, Stig Madsen, and
;;Daron the postin’ fool over
;;
;;18-Mar-04
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun changeAtt (ent tag val / entl ins)
  (setq ins ent)
  (while (and ent
           (/= "SEQEND" (cdr (assoc 0 (setq entl (entget ent))))))
    (if (and (= (cdr (assoc 0 entl)) "ATTRIB")
             (= (cdr (assoc 2 entl)) tag))
      (entmod (subst (cons 1 val) (assoc 1 entl) entl)))
    (setq ent (entnext ent)))
  (entupd ins)
)
(defun C:STAMP ()
(setq userid (getstring "\nEnter User Initials: "))
(setq pldate (menucmd "m=$(edtime, $(getvar, date),dd-mon-yy hh:mmam/pm)"))
  (cond ((setq sset (ssget "x" '((2 . "mat*") (66 . 1))))
         (setq a 0)
         (repeat (sslength sset)
           (setq ent (ssname sset a)
                 a   (1+ a)
           )
           (if (/= userid "")
           (changeAtt ent "LAST" userid) ;<- change value
           )
           (changeAtt ent "PLOT" pldate) ;<- change value
         )
        )
  )
  (princ)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


Thanks agian.