Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: Lisp routine to add value 'x' to existing attribute values of a block

  1. #11
    Join Date
    Jan 2011
    Posts
    26
    Sorry, I modified the program in a hurry so just consider the following:
    Code:
    (defun c:Test (/ tag bkn s)
      ;;	Tharwat 22.7.2015	;;
      (setq tag "Tag1"        ;; Tag name to match
            bkn "MyBlockName" ;; Block name to be selected <None Dynamic block>
      )
      (princ "\nSelect Attributed Blocks")
      (if (setq s (ssget "_:L" (list '(0 . "INSERT")(cons 2 bkn) '(66 . 1))))
        ((lambda (i / sn)
           (while (setq sn (ssname s (setq i (1+ i))))
           (mapcar '(lambda (u)
                      (and (= (vla-get-tagstring u) tag)
                           (vla-put-textstring u (strcat "x" (vla-get-textstring u))))
                      )
                  (vlax-invoke (vlax-ename->vla-object sn) 'getattributes)
                  )
             ))
          -1)
        )
      (princ)
      ) (vl-load-com)

  2. #12
    Join Date
    Nov 2019
    Posts
    5
    its work when i use it manually
    there is anyway to change it that it would choose the last block that drawn and modify it?
    i need only the last block


    Quote Originally Posted by Tharwat View Post
    Sorry, I modified the program in a hurry so just consider the following:
    Code:
    (defun c:Test (/ tag bkn s)
      ;;	Tharwat 22.7.2015	;;
      (setq tag "Tag1"        ;; Tag name to match
            bkn "MyBlockName" ;; Block name to be selected <None Dynamic block>
      )
      (princ "\nSelect Attributed Blocks")
      (if (setq s (ssget "_:L" (list '(0 . "INSERT")(cons 2 bkn) '(66 . 1))))
        ((lambda (i / sn)
           (while (setq sn (ssname s (setq i (1+ i))))
           (mapcar '(lambda (u)
                      (and (= (vla-get-tagstring u) tag)
                           (vla-put-textstring u (strcat "x" (vla-get-textstring u))))
                      )
                  (vlax-invoke (vlax-ename->vla-object sn) 'getattributes)
                  )
             ))
          -1)
        )
      (princ)
      ) (vl-load-com)

  3. #13
    Join Date
    Jan 2011
    Posts
    26
    Quote Originally Posted by MPD View Post
    its work when i use it manually
    there is anyway to change it that it would choose the last block that drawn and modify it?
    i need only the last block
    If that is the case then I can write a new routine for you that inserts your desired attributed block name then assign the value of the attributes based on your requirements.

    Just list down the name of your attributed block then the number of attributes along with the desired attribute values for each attribute in the block.
    eg:
    Attributed Block name = "MyBlock"
    Attribute one = "Value_1"
    Attribute two = "Value_2"
    ...... etc

  4. #14
    Join Date
    Nov 2019
    Posts
    5
    it would be amazing
    Attributed Block name = "2bar_402"
    Attribute one = "length"

    i need to add to the length and not to overite it

    Quote Originally Posted by Tharwat View Post
    If that is the case then I can write a new routine for you that inserts your desired attributed block name then assign the value of the attributes based on your requirements.

    Just list down the name of your attributed block then the number of attributes along with the desired attribute values for each attribute in the block.
    eg:
    Attributed Block name = "MyBlock"
    Attribute one = "Value_1"
    Attribute two = "Value_2"
    ...... etc

  5. #15
    Join Date
    Jan 2011
    Posts
    26
    Quote Originally Posted by MPD View Post
    it would be amazing
    Attributed Block name = "2bar_402"
    Attribute one = "length"

    i need to add to the length and not to overite it
    Try the following routine and let me know how you get on with it;

    Code:
    (defun c:Test (/ ins spc blk var)
      ;; Tharwat - Date: 17.Nov.2019	;;
      (and (or (tblsearch "BLOCK" "2bar_402")
               (alert "Block name < 2bar_402 > not found in this drawing !"
               )
           )
           (setq ins (getpoint "\nSpecify insertion point :"))
           (setq
             spc (vlax-get (vla-get-activelayout
                             (vla-get-activedocument (vlax-get-acad-object))
                           )
                           'Block
                 )
           )
           (setq var (mapcar 'getvar '(ATTDIA ATTREQ)))
           (mapcar 'setvar '(ATTDIA ATTREQ) '(0 0))
           (setq blk (vlax-invoke spc 'insertblock ins "2bar_402" 1. 1. 1. 0.))
           (progn (foreach x (vlax-invoke blk 'getattributes)
                    (vla-put-textstring x "length")
                  )
                  (mapcar 'setvar '(ATTDIA ATTREQ) var)
           )
      )
      (princ)
    ) (vl-load-com)

  6. #16
    Join Date
    Nov 2019
    Posts
    5
    Thank for your help
    This isnt what i mean but i already fix your previous code to work

  7. #17
    Join Date
    Jan 2011
    Posts
    26
    Quote Originally Posted by MPD View Post
    Thank for your help
    This isnt what i mean but i already fix your previous code to work
    You're welcome anytime and happy coding.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 7
    Last Post: 29-03-2014, 04:45 PM
  2. 2010 Hide Block During Plotting Lisp Routine
    By Ozdesigner62 in forum LISP Routines
    Replies: 0
    Last Post: 18-07-2012, 09:28 PM
  3. added new attribute to existing block
    By charslo in forum AutoCAD 2011 Help
    Replies: 2
    Last Post: 26-11-2011, 05:04 AM
  4. lisp routine for changing the block
    By kusha bhaskara in forum LISP Routines
    Replies: 0
    Last Post: 06-01-2009, 06:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •