Author Topic: Attribute value edit  (Read 2014 times)

dexus and 1 Guest are viewing this topic.

mohan

  • Newt
  • Posts: 98
Attribute value edit
« on: June 24, 2021, 11:51:53 AM »
Please help me to complete the simple route
I have to change all the dates to default value


Code: [Select]
(defun c:editmyattri ( / )
  (setq myblockname is attributeblock))
  (setq myolddate (store the tag value when i select over the tag value))
(command "._attedit" "_N" "_N" myblockname "DATE" "*" myolddate "JUNE 2021")
(princ))
"Save Energy"

mhupp

  • Bull Frog
  • Posts: 250

CodeDing

  • Newt
  • Posts: 55
Re: Attribute value edit
« Reply #2 on: June 24, 2021, 03:44:13 PM »
mohan,

This could help you. In my opinion, this is an easier approach than the older approach by CAB in the provided link.
This approach will only work if you're using AutoCAD.

Use like so:
Code: [Select]
(defun c:TEST ( / )
  (if (UpdateAllBlockAttribute
        (getstring "\nEnter BLOCK Name: ")
        (getstring "\nEnter TAG Name: ")
        (getstring t "\nEnter New VALUE: ")
      )
    (prompt "\nUpdates Complete.")
    (prompt "\nNo Updates Made.")
  );if
  (princ)
);defun

Functions:
Code: [Select]
(defun LM:effectivename ( obj )
    (vlax-get-property obj
        (if (vlax-property-available-p obj 'effectivename)
            'effectivename
            'name
        )
    )
)
(defun UpdateAllBlockAttribute (blkName attName newVal / ssBlocks cnt e blkList propAvailable)
  ;; Updates the attribute name [attName] value within all blocks [with blkName] to new value [newVal].
  ;; all inputs.. blkName, attName, newVal ..are string values
  ;; returns - list, of all entity names that were updated
  (if (and (apply 'and (mapcar '(lambda (s) (eq 'STR (type s))) (list blkName attName newVal)))
           (tblsearch "BLOCK" blkName)
           (setq ssBlocks (ssget "_X" '((0 . "INSERT"))))
           (repeat (setq cnt (sslength ssBlocks))
             (setq e (ssname ssBlocks (setq cnt (1- cnt))))
             (if (eq (strcase blkName) (strcase (LM:effectivename (vlax-ename->vla-object e))))
               (setq blkList (cons e blkList)
                     propAvailable (null (vl-catch-all-error-p (vl-catch-all-apply 'getpropertyvalue (list e attName))))
               );setq
             );if
             blkList
           );repeat
           propAvailable
      );and
    (mapcar
      '(lambda (e) (setpropertyvalue e attName newVal) e)
      blkList
    );mapcar
  );if
);defun

Best,
~DD
Senior CAD Tech & AI Specialist
Need AutoLisp help?
Try my custom GPT 'AutoLISP Ace'

BIGAL

  • Swamp Rat
  • Posts: 1433
  • 40 + years of using Autocad
Re: Attribute value edit
« Reply #3 on: June 24, 2021, 07:52:28 PM »
Codeding I suggest replace

(getstring "\nEnter BLOCK Name: ")
(getstring "\nEnter TAG Name: ")

with a nentsel "Pick attribute" you can then get the attribute tag name, the second step is to reselect using ssget pt and get block name so have ssget filters.

No need for mistakes in block name and tag name then.

An example
Code: [Select]
; Select attribute up date with pick text
; By Alan H July 2019


(defun txt2att ( / ss pt ent txt oldsnap)
(while (setq ent (nentsel "Pick Attribute"))
(setq pt (cadr ent))
(setq tag (cdr (assoc 2  (entget (car ent)))))
(setq ent (entsel "pick text"))
(setq txt (cdr (assoc 1  (entget (car ent)))))
(setq oldsnap (getvar 'osmode))
(setvar 'osmode 0)
(setq ss (ssget pt))
(foreach att (vlax-invoke (vlax-ename->vla-object (ssname SS 0 )) 'getattributes)
        (if (= tag (strcase (vla-get-tagstring att)))
        (vla-put-textstring att txt)
        )
)
)
(setvar 'osmode oldsnap)
(princ)
)
(txt2att)
A man who never made a mistake never made anything

JohnK

  • Administrator
  • Seagull
  • Posts: 10659
Re: Attribute value edit
« Reply #4 on: June 24, 2021, 09:42:13 PM »
For "pick-based-attribute-editing", I liked this one the best (clean and proper coding).
https://www.theswamp.org/index.php?topic=10028.msg128497#msg128497

For "find-and-replace" I really like this one.
https://www.theswamp.org/index.php?topic=4591.msg605179#msg605179

The one provided by CAB in the link has a bit of a background to it and is very good; CAB modified a function of SMadsen's and generally speaking, SMadsen had a very nice style and his code is always worth studying for his hidden gems of AutoLisp and professional coding style. MP also demonstrated that same professional style in the first link in this post.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

mohan

  • Newt
  • Posts: 98
Re: Attribute value edit
« Reply #5 on: June 27, 2021, 07:21:43 AM »
mohan,

This could help you. In my opinion, this is an easier approach than the older approach by CAB in the provided link.
This approach will only work if you're using AutoCAD.

Use like so:
Code: [Select]
(defun c:TEST ( / )
  (if (UpdateAllBlockAttribute
        (getstring "\nEnter BLOCK Name: ")
        (getstring "\nEnter TAG Name: ")
        (getstring t "\nEnter New VALUE: ")
      )
    (prompt "\nUpdates Complete.")
    (prompt "\nNo Updates Made.")
  );if
  (princ)
);defun

Functions:
Code: [Select]
(defun LM:effectivename ( obj )
    (vlax-get-property obj
        (if (vlax-property-available-p obj 'effectivename)
            'effectivename
            'name
        )
    )
)
(defun UpdateAllBlockAttribute (blkName attName newVal / ssBlocks cnt e blkList propAvailable)
  ;; Updates the attribute name [attName] value within all blocks [with blkName] to new value [newVal].
  ;; all inputs.. blkName, attName, newVal ..are string values
  ;; returns - list, of all entity names that were updated
  (if (and (apply 'and (mapcar '(lambda (s) (eq 'STR (type s))) (list blkName attName newVal)))
           (tblsearch "BLOCK" blkName)
           (setq ssBlocks (ssget "_X" '((0 . "INSERT"))))
           (repeat (setq cnt (sslength ssBlocks))
             (setq e (ssname ssBlocks (setq cnt (1- cnt))))
             (if (eq (strcase blkName) (strcase (LM:effectivename (vlax-ename->vla-object e))))
               (setq blkList (cons e blkList)
                     propAvailable (null (vl-catch-all-error-p (vl-catch-all-apply 'getpropertyvalue (list e attName))))
               );setq
             );if
             blkList
           );repeat
           propAvailable
      );and
    (mapcar
      '(lambda (e) (setpropertyvalue e attName newVal) e)
      blkList
    );mapcar
  );if
);defun

Best,
~DD
Thanks for the reply . . .
My Attribute block name is default
My Attribute tag name is default
My Attribute tag value is default, so i don't want to type each time
Some drawings having one Attribute & others are more, when I run the route it look for the block + tag names & tag values which should inside the route
I thing you got my point, i am tired with google, there were so many routes for Attributes
« Last Edit: June 27, 2021, 07:29:20 AM by mohan »
"Save Energy"