Author Topic: change Attib value in Block in Multileader?  (Read 9105 times)

0 Members and 1 Guest are viewing this topic.

Amsterdammed

  • Guest
change Attib value in Block in Multileader?
« on: September 07, 2010, 09:19:55 AM »
Hello there,

i have a bunch of multileaders with a block in them and i need to update their attribute value. Does anybody have a clue how i could do that?

Tia

Bernd

Crank

  • Water Moccasin
  • Posts: 1503
Re: change Attib value in Block in Multileader?
« Reply #1 on: September 07, 2010, 01:23:56 PM »
Perhaps with DDEDIT ?
Example:
Code: [Select]
(defun c:ML-label (/ MLS LA s)
(setq LA (getvar "CLAYER"))
(if (not (tblsearch "LAYER" "MYLAYER"))(progn
(entmake (list '(0 . "LAYER")
'(100 . "AcDbSymbolTableRecord")
'(100 . "AcDbLayerTableRecord")
'(2 . "MYLAYER")
'(70 . 0)
'(62 . 2)
'(6 . "CONTINUOUS")
'(290 . 1)
'(370 . -3)
)
)
))
(command "LAYER" "M" "MYLAYER" "")

; Load all MLstyles by loading a block that has all MLstyles in it:
(if (not (tblsearch "BLOCK" "MLstyle"))(command ".insert" "MLstyle=Mleader/Labels-EP" (command)))

(setq MLS (getvar "CMLEADERSTYLE"))
(setvar "CMLEADERSTYLE" "StyleWithTag"); Make the MLstyle 'StyleWithTag' current
(command ".mleader" "L" "H" (getpoint "\nStart arrow: "))
(while (> (getvar "CMDACTIVE") 0)(command pause))

(vl-cmdf ".ddedit" (entlast) "")
(setvar "CMLEADERSTYLE" MLS)(setvar "CLAYER" LA); restore variables
(princ)
)
Vault Professional 2023     +     AEC Collection

Amsterdammed

  • Guest
Re: change Attib value in Block in Multileader?
« Reply #2 on: September 07, 2010, 01:59:49 PM »
almost, but how to skip the dialog, lets say i have a new bom attached with new pos. numbers and want to "autoupdate" the existing ones ,so i need to to it like entmode, in lisp without the user input.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: change Attib value in Block in Multileader?
« Reply #3 on: September 07, 2010, 02:08:42 PM »
On a simple test, it looks like the last 302 is the attribute value.  Granted I only had one attribute within my block.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Amsterdammed

  • Guest
Re: change Attib value in Block in Multileader?
« Reply #4 on: September 07, 2010, 02:26:29 PM »
right, and i have only one, so what do i "entmod"??

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: change Attib value in Block in Multileader?
« Reply #5 on: September 07, 2010, 02:33:34 PM »
Perhaps try something like this:

Code: [Select]
;;---------=={ Set MLeader Block Attribute Value }==----------;;
;;                                                            ;;
;;  Sets the value of the specified tag for the specified     ;;
;;  MLeader                                                   ;;
;;------------------------------------------------------------;;
;;  Author: Lee McDonnell, 2010                               ;;
;;                                                            ;;
;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  mleader - ename/VLA-Object MLeader with attributed block  ;;
;;  tag     - Tagstring of the attribute to change            ;;
;;  value   - Value to which attribute will be set            ;;
;;------------------------------------------------------------;;
;;  Returns:  T if successful, else nil                       ;;
;;------------------------------------------------------------;;

(defun LM:SetMLeaderBlockAttributeValue ( mleader tag value / def id )
  (vl-load-com)
  ;; © Lee Mac 2010

  (if
    (and
      (eq "AcDbMLeader"
        (vla-get-Objectname
          (setq mleader
            (cond
              ( (eq 'VLA-OBJECT (type mleader)) mleader)
              ( (vlax-ename->vla-object mleader) )
            )
          )
        )
      )
      (= 1 (vla-get-ContentType mleader))
      (setq def
        (LM:Itemp
          (vla-get-Blocks
            (vla-get-ActiveDocument
              (vlax-get-acad-object)
            )
          )
          (vla-get-ContentBlockName mleader)
        )
      )
    )
    (if
      (progn
        (vlax-for obj def
          (if (and (eq "AcDbAttributeDefinition" (vla-get-Objectname obj))
                   (eq (strcase tag) (strcase (vla-get-TagString obj))))
            (setq id (vla-get-ObjectID obj))
          )
        )
        id
      )
      (not (vla-SetBlockAttributeValue mleader id value))
    )
  )
)

;;-----------------------=={ Itemp }==------------------------;;
;;                                                            ;;
;;  Retrieves the item with index 'item' if present in the    ;;
;;  specified collection, else nil                            ;;
;;------------------------------------------------------------;;
;;  Author: Lee McDonnell, 2010                               ;;
;;                                                            ;;
;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  coll - the VLA Collection Object                          ;;
;;  item - the index of the item to be retrieved              ;;
;;------------------------------------------------------------;;
;;  Returns:  the VLA Object at the specified index, else nil ;;
;;------------------------------------------------------------;;

(defun LM:Itemp ( coll item )
  ;; © Lee Mac 2010
  (if
    (not
      (vl-catch-all-error-p
        (setq item
          (vl-catch-all-apply
            (function vla-item) (list coll item)
          )
        )
      )
    )
    item
  )
)



(defun c:test ( / e )

  (if (setq e (car (entsel "\nSelect MLeader: ")))
    (LM:SetMLeaderBlockAttributeValue e "TAG1" "Test")
  )
)

I wish the enums for vla-get-ContentType and vla-get-ContentBlockType were better documented... I kinda had to make an educated guess...  :|

T.Willey

  • Needs a day job
  • Posts: 5251
Re: change Attib value in Block in Multileader?
« Reply #6 on: September 07, 2010, 02:39:28 PM »
Sounded fun, so here is another option; regular lisp.

Code: [Select]
(defun UpdateMleaderAttributes ( attList / cnt ss Ent tempList ChangeAtt newEntData )
    ; Will update all mleaders whose attribute's tag matches those in the attList argument.
    ; Call like (UpdateMleaderAttributes '(("DETAIL" . "1")("SHEET" . "S-2.4")))
   
    (setq cnt -1)
    (if (setq ss (ssget "_x" '((0 . "MULTILEADER"))))
        (while (setq Ent (ssname ss (setq cnt (1+ cnt))))
            (foreach i (entget Ent)
                (if
                    (and
                        (equal (type (cdr i)) 'ENAME)
                        (setq tempList (assoc (cdr (assoc 2 (entget (cdr i)))) attList))
                    )
                    (setq ChangeAtt T)
                )
                (setq newEntData
                    (cons
                        (if
                            (and
                                ChangeAtt
                                (equal (car i) 302)
                            )
                            (progn
                                (setq ChangeAtt nil)
                                (cons 302 (cdr tempList))
                            )
                            i
                        )
                        newEntData
                    )
                )
            )
            (entmod (reverse newEntData))
            (setq newEntData nil)
        )
    )
    (princ)
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: change Attib value in Block in Multileader?
« Reply #7 on: September 07, 2010, 02:47:17 PM »
<snip>
I wish the enums for vla-get-ContentType and vla-get-ContentBlockType were better documented... I kinda had to make an educated guess...  :|

ContentType
Quote
Members  Description 
kNoneContent = 0  MLeader has no content 
kBlockContent = 1  MLeader has block content 
kMTextContent = 2  MLeader has MText content 
kToleranceContent = 3  MLeader has tolerance content 

Didn't find anything in the Arx help about the ContentBlockType.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Amsterdammed

  • Guest
Re: change Attib value in Block in Multileader?
« Reply #8 on: September 07, 2010, 03:09:14 PM »
wow,

thanks fellows, that is cool. I need to dig into that object stuff, there are so many functions out there that make live so much easier..

Thanks again!

Bernd

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: change Attib value in Block in Multileader?
« Reply #9 on: September 07, 2010, 04:45:57 PM »
<snip>
I wish the enums for vla-get-ContentType and vla-get-ContentBlockType were better documented... I kinda had to make an educated guess...  :|

ContentType
Quote
Members  Description 
kNoneContent = 0  MLeader has no content 
kBlockContent = 1  MLeader has block content 
kMTextContent = 2  MLeader has MText content 
kToleranceContent = 3  MLeader has tolerance content 

Didn't find anything in the Arx help about the ContentBlockType.

Thanks for looking it up Tim, appreciated. I take it that is all from the Arx documentation? (glad my guess was right :-) )


Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: change Attib value in Block in Multileader?
« Reply #10 on: September 07, 2010, 04:46:26 PM »
wow,

thanks fellows, that is cool. I need to dig into that object stuff, there are so many functions out there that make live so much easier..

Thanks again!

Bernd

You're very welcome Bernd - I hadn't dealt in this area before, so it was a learning experience for me too  :-)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: change Attib value in Block in Multileader?
« Reply #11 on: September 07, 2010, 04:56:12 PM »
<snip>
I wish the enums for vla-get-ContentType and vla-get-ContentBlockType were better documented... I kinda had to make an educated guess...  :|

ContentType
Quote
Members  Description 
kNoneContent = 0  MLeader has no content 
kBlockContent = 1  MLeader has block content 
kMTextContent = 2  MLeader has MText content 
kToleranceContent = 3  MLeader has tolerance content 

Didn't find anything in the Arx help about the ContentBlockType.

Thanks for looking it up Tim, appreciated. I take it that is all from the Arx documentation? (glad my guess was right :-) )



Yup, and you're welcome Lee.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

bbarkman

  • Guest
Re: change Attib value in Block in Multileader?
« Reply #12 on: September 21, 2012, 11:31:50 AM »
Perhaps try something like this:

Code: [Select]
;;---------=={ Set MLeader Block Attribute Value }==----------;;
;;                                                            ;;
;;  Sets the value of the specified tag for the specified     ;;
;;  MLeader                                                   ;;
;;------------------------------------------------------------;;
;;  Author: Lee McDonnell, 2010                               ;;
;;                                                            ;;
;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  mleader - ename/VLA-Object MLeader with attributed block  ;;
;;  tag     - Tagstring of the attribute to change            ;;
;;  value   - Value to which attribute will be set            ;;
;;------------------------------------------------------------;;
;;  Returns:  T if successful, else nil                       ;;
;;------------------------------------------------------------;;

(defun LM:SetMLeaderBlockAttributeValue ( mleader tag value / def id )
  (vl-load-com)
  ;; © Lee Mac 2010

  (if
    (and
      (eq "AcDbMLeader"
        (vla-get-Objectname
          (setq mleader
            (cond
              ( (eq 'VLA-OBJECT (type mleader)) mleader)
              ( (vlax-ename->vla-object mleader) )
            )
          )
        )
      )
      (= 1 (vla-get-ContentType mleader))
      (setq def
        (LM:Itemp
          (vla-get-Blocks
            (vla-get-ActiveDocument
              (vlax-get-acad-object)
            )
          )
          (vla-get-ContentBlockName mleader)
        )
      )
    )
    (if
      (progn
        (vlax-for obj def
          (if (and (eq "AcDbAttributeDefinition" (vla-get-Objectname obj))
                   (eq (strcase tag) (strcase (vla-get-TagString obj))))
            (setq id (vla-get-ObjectID obj))
          )
        )
        id
      )
      (not (vla-SetBlockAttributeValue mleader id value))
    )
  )
)

;;-----------------------=={ Itemp }==------------------------;;
;;                                                            ;;
;;  Retrieves the item with index 'item' if present in the    ;;
;;  specified collection, else nil                            ;;
;;------------------------------------------------------------;;
;;  Author: Lee McDonnell, 2010                               ;;
;;                                                            ;;
;;  Copyright © 2010 by Lee McDonnell, All Rights Reserved.   ;;
;;  Contact: Lee Mac @ TheSwamp.org, CADTutor.net             ;;
;;------------------------------------------------------------;;
;;  Arguments:                                                ;;
;;  coll - the VLA Collection Object                          ;;
;;  item - the index of the item to be retrieved              ;;
;;------------------------------------------------------------;;
;;  Returns:  the VLA Object at the specified index, else nil ;;
;;------------------------------------------------------------;;

(defun LM:Itemp ( coll item )
  ;; © Lee Mac 2010
  (if
    (not
      (vl-catch-all-error-p
        (setq item
          (vl-catch-all-apply
            (function vla-item) (list coll item)
          )
        )
      )
    )
    item
  )
)



(defun c:test ( / e )

  (if (setq e (car (entsel "\nSelect MLeader: ")))
    (LM:SetMLeaderBlockAttributeValue e "TAG1" "Test")
  )
)

I wish the enums for vla-get-ContentType and vla-get-ContentBlockType were better documented... I kinda had to make an educated guess...  :|

This is nice.  Any chance of not having to select an mleader?  I'd like to enter a new value from a prompt (that's easy) and have the lisp update all mleaders based on "TAG1."