Author Topic: Global Attribute Update?  (Read 6076 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Global Attribute Update?
« Reply #15 on: February 23, 2005, 11:57:39 PM »
... and then there's the complimentary routine :
Code: [Select]

(defun GetAttVals (oBlockref)
 (mapcar
 '(lambda (Attrib)
   (cons (vla-get-TagString Attrib)
         (vla-get-TextString Attrib)
   )
  )
  (vlax-invoke oBlockref 'GetAttributes)
 )
)


Used like this [ note the ":S" for single selection ]
Code: [Select]
(if (setq sset (ssget ":S" '((2 . "TITLE") (66 . 1))))
  (GetAttVals (vlax-ename->vla-object (ssname sset 0)))
)

Returns ALL the attribute tags, and their values
( ("DWG" . "TEST-001")("REVISION" . "P1") ("DRAWN-BY" . "ME") ("DATE" . "TODAY") )
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

--> Donate to theSwamp<--

Jeff_M

  • King Gator
  • Posts: 3945
  • C3D user & customizer
Global Attribute Update?
« Reply #16 on: February 24, 2005, 01:15:13 AM »
Well I don't know how I missed this thread until now. And just my luck that Kerry has posted something quite similar (read "nearly identical")  to what I use. But I will post what I use just because.....  :D
Code: [Select]

;; Function to synchronize attributes of a given block, only those included in
;; the list will be updated
;; usage- (global_atts "myblock" *att_list*)
;; *att_list* as returned (or in the same form as) by the second routine,
;; "make_att_list"
;; Author: Jeff Mishler
;; Date 1/11/05
(defun global_atts (bname attlist)
  (if (setq ss (ssget "x" (list '(0 . "INSERT")(cons 2 bname)'(66 . 1))))
    (progn
      (setq count -1)
      (while (< (setq count (1+ count)) (sslength ss))
(setq blk (vlax-ename->vla-object (ssname ss count))
     atts2 (vlax-invoke blk "getattributes")
     )
(foreach att2 atts2
 (foreach att1 attlist
   (if (= (car att1)(vla-get-tagstring att2))
     (progn
(vla-put-textstring att2 (cdr att1))
(vla-update att2)
     )
   )
 )
(vla-update blk)
)
      )
    )
  )

  ;; for use with the global_atts function above
(defun make_att_list (/ ent obj atts)
  (and (setq ent (car (entsel "\nSelect block to log attributes for: ")))
       (setq obj (vlax-ename->vla-object ent))
       (if (and (vlax-property-available-p obj 'hasattributes)
(eq (vla-get-hasattributes obj) :vlax-true))
(progn
  (setq atts (vlax-invoke obj 'getattributes))
  (foreach att atts
    (setq *att_list* (cons
(cons
 (vla-get-tagstring att)
 (vla-get-textstring att)
 )
*att_list*
)
  )
    )
  )
)
       )
  )
 

Jeff_M

  • King Gator
  • Posts: 3945
  • C3D user & customizer
Global Attribute Update?
« Reply #17 on: February 24, 2005, 01:16:56 PM »
I knew I shouldn't be posting at the end of a 16 hour day. I tried to fing the following lisp to post and just couldn't locate it. Now, this moning, I found it right off the bat.

This one fills out the sheet name, sheet number and total number of sheets, based on the Layout tab names. I know it works with my title block, but it wouldn't take much to tweak it to yours.....
Code: [Select]

;|Insert a title block into all PaperSpace Layout Tabs,
  all at 0,0,0 & 0 deg. rotation, use attlist for filling
  attribute values. attlist format:
  (("tagstring" . "value")("tagstring" . "value"))
  Routine will automagically input values for attributes of a
  Title block that contains attributes with tagstrings of
  "NO", "SHEETS" & "SHEET_NAME" by using the Tab order number
  for the "NO" (sheet number), the total number of tabs minus 1 (the
  Model tab) for "SHEETS" (number of sheets), and the Tab name for the
  "SHEET_NAME". By including a listing in the attlist for any, or all,
  of these you can overwrite what is placed there.
  by Jeff Mishler, April 2004
|;

(defun title2tabs (bname attlist / lays blk newblk tag)
  (setq lays (vla-get-layouts
      (vla-get-activedocument
(vlax-get-acad-object)))
)
  (if (not (tblsearch "block" bname))
    (progn
      (princ "\nBlock not found, please select block: ")
      (setq bname
    (getfiled "Block Selection for Tab Insert" bname "dwg" 0))
      )
    )
  (vlax-for x lays
    (if (not (or (= "Model" (vla-get-name x))
(= (getvar "CTAB") (vla-get-name x)))
    )
      (progn
(setq blk (vla-get-block x))
(setq newblk nil)
(vlax-for ent blk
 (if (and (eq (vla-get-objectname ent) "AcDbBlockReference")
  (eq (vla-get-name ent) bname)
  )
   (setq newblk ent)
   )
 )
(if (not newblk)
 (setq newblk (vlax-invoke-method
      blk
      'insertblock
      (vlax-3d-point
'(0.0 0.0 0.0))
      bname 1.0 1.0 1.0 0.0)
     )
 )
 (if (= (vla-get-hasattributes newblk) :vlax-true)
   (progn
     (setq atts (vlax-safearray->list
  (vlax-variant-value
    (vla-getattributes newblk))))
     (foreach att atts
(setq tag (vla-get-tagstring att))
(cond ((= tag "NO")
      (vla-put-textstring att (itoa (vla-get-taborder x))))
     ((= tag "SHEETS")
      (vla-put-textstring att (itoa (1- (vla-get-count lays)))))
     ((= tag "SHEET_NAME")
      (vla-put-textstring att (strcase (stripstr (vla-get-name x) "-"))))
     ((assoc tag attlist)
      (vla-put-textstring att (cdr (assoc tag attlist))))
     (t ;no default input, add marker text
      (vla-put-textstring att "????")
 )
)
     )
   )
)
      )
      )
    )
  (princ)
  )

;;following code to help facilitate creating attlist for use in title2tabs
(defun make_attlist (bname / taglist str)
  (vlax-for x (vla-item (vla-get-blocks *doc*) bname)
    (if (= (vla-get-objectname x) "AcDbAttributeDefinition")
      (setq taglist (cons (vla-get-tagstring x) taglist))
      )
    )
  (foreach x taglist
    (setq str (getstring t (strcat "\nValue to use for attribute tag \""
  x
  "\": ")))
    (if (not (= str ""))
      (setq attlist (cons (cons x str) attlist))
      )
    )
  attlist
  )
;; or select an existing block
(defun get_attlist (/ ss obj)
  (princ "\nSelect Title block to gather Attribute data from: ")
  (if (setq ss (ssget ":S"'((0 . "INSERT"))))
    (progn
      (setq obj (vlax-ename->vla-object (ssname ss 0)))
      (if (eq :vlax-true (vla-get-hasattributes obj))
(progn
 (foreach att (vlax-invoke obj "getattributes")
   (setq attlist (cons (cons (vla-get-tagstring att)
     (vla-get-textstring att))
attlist))
   )
 )
)
      )
    )
  )

;|code to parse a string....
   (setq str "wp-property")
   (stripstr str "-")
   returns: "property"
 |;
(defun stripstr (str itm / pos)
  (setq pos (vl-string-search itm str))
  (if (not pos) (setq pos -1));set pos incase item looking for not found not found
  ;increment pos by 2, 1 for 0 vs 1 based index, 1 for next character
  (substr str (+ pos 2))
  );

TimSpangler

  • Water Moccasin
  • Posts: 2010
  • CAD Naked!!
Global Attribute Update?
« Reply #18 on: February 24, 2005, 03:01:34 PM »
Thanks Jeff,

I haven't tried it yet but, I have been working on some of the code for the past 2 Night (total of about 1 hrs,  I have a 4 year old :roll:  :wink: )  I have a larger routine in mind for inserting addind, and updating info in the title block so I have alittle work ahead of me.

I truly apprieciate the efforts from everyone, Thanks again
ACA 2015 - Windows 7 Pro
All Comments and Content by TimSpangler, Copyright 2016