Author Topic: Edit attribute values  (Read 2488 times)

0 Members and 1 Guest are viewing this topic.

mohan

  • Newt
  • Posts: 98
Edit attribute values
« on: November 20, 2019, 12:33:00 PM »
Another small lisp........

I have to Attribute blocks

1. Block name say ATTRIBUTE1 having TAG names
TITLE_1:RRRRRRR
TITLE_2:WWWWW
TITLE_3:HHHHHH
DRAWN:SJ
DESIGNED:DJB
CHECKED:DJB
APPROVED:GAB
DWG_NO:123456
DATE:NOVEMBER 2019

*Select all the block name of ATTRIBUTE1 & change the tag values as above (I can modify in the lisp TAG Names, Block names or the Values as per my requirements)


2. Block name say ATTRIBUTE2 having TAG names
REV_NO:01
DESCRIPTION:YYYYYYYY
DRAWN:SJ
DESIGNED:DJB
CHECKED:DJB
APPROVED:GAB
DATE:NOV 2019

*Select all the block name of ATTRIBUTE2 & change the tag values as above (I can modify in the lisp TAG Names, Block names or the Values as per my requirements)
No inputs just run the lisp with defun command

thanks
"Save Energy"

JohnK

  • Administrator
  • Seagull
  • Posts: 10674
Re: Edit attribute values
« Reply #1 on: November 20, 2019, 02:47:20 PM »
Are you interested in learning to write a program to do this?
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

mohan

  • Newt
  • Posts: 98
Re: Edit attribute values
« Reply #2 on: November 21, 2019, 01:05:29 AM »
I started learning AutoLisp Program, time is the problem - doing a Job with cooking & other Misc. things at home
If you share a easy understanding pdf tutorial of AutoLisp - that will be much grateful

I wanted to Learn only how to use (run) the approved codes of below Programs
Visual Basic Customization
.NET
ObjectARX

thanks
"Save Energy"

BIGAL

  • Swamp Rat
  • Posts: 1459
  • 40 + years of using Autocad
Re: Edit attribute values
« Reply #3 on: November 21, 2019, 01:23:40 AM »
Please be careful a Block has attributes,
Each attribute has a "TAG NAME"
For any individual attribute it has a "Attribute value"

It gets confusing what your trying to do using "TAG" all the time in request a dwg or image would explain better.
A man who never made a mistake never made anything

mohan

  • Newt
  • Posts: 98
Re: Edit attribute values
« Reply #4 on: November 21, 2019, 02:04:02 AM »
Can you Fix this Lisp please! or help me with a script

Code: [Select]
(defun c:attrimedit (nil)
  (setvar 'cmdecho 0)
  (c:gatte)
  (foreach x '(("_.BLOCK" "Ren Drawing Title" "DATE" "       NOVEMBER  2019" "YES")
               ("_.BLOCK" "Ren Drawing Title" "REV_NO1" "A" "YES")
       ("_.BLOCK" "Ren Tittleblock Revision" "REV_NO" "A" "YES")
               ("_.BLOCK" "Ren Tittleblock Revision" "REV_DESC" "     ISSUED FOR CONSTRUCTION" "YES")
               ("_.BLOCK" "Ren Tittleblock Revision" "DATE" "NOV'  2019" "YES")
      )
    (eval (cons 'command-s x))
  )
  (setvar 'cmdecho 1)
  (princ)
)

thanks
"Save Energy"

BIGAL

  • Swamp Rat
  • Posts: 1459
  • 40 + years of using Autocad
Re: Edit attribute values
« Reply #5 on: November 25, 2019, 12:21:02 AM »
Again a dwg or image would explain better.
A man who never made a mistake never made anything

ahsattarian

  • Newt
  • Posts: 114
Re: Edit attribute values
« Reply #6 on: December 01, 2020, 12:28:45 AM »
This Helps U   :




Code - Auto/Visual Lisp: [Select]
  1. (defun c:gatte2 ()
  2.   (princ "\n  Select Attribute : ")
  3.   (setq es (entsel)) ;|  #nentselp  |;
  4.   (setq po (cadr es))
  5.   (setq s (car es))
  6.   (setq en (entget s))
  7.   (setq typ (strcase (cdr (assoc 0 en)) t)) ;|  #type  |;
  8.   (setq es1 (nentselp po))
  9.   (setq s1 (car es1))
  10.   (setq en1 (entget s1))
  11.   (setq typ1 (strcase (cdr (assoc 0 en1)) t)) ;|  #type  |;
  12.   (cond
  13.     ((and (= typ "insert") (= typ1 "attrib"))
  14.      (setq nam (cdr (assoc 2 en)))
  15.      (setq tag (cdr (assoc 2 en1)))
  16.      (setq val (cdr (assoc 1 en1)))
  17.      (setq atedn-var1 (getstring (strcat " New Value < " val " > : ")))
  18.      (cond ((= atedn-var1 "") (setq atedn-var1 val)))
  19.      (setq i 0)
  20.      ;;(setq ss2 (ssget ;|"x"|; (list (cons 0 "insert") (cons 66 1))))
  21.      (setq ss2 (ssget ;|"x"|; (list (cons 0 "insert") (cons 2 nam) (cons 66 1))))
  22.      (setq n2 (sslength ss2))
  23.      (setq k2 -1)
  24.      (repeat n2
  25.        (setq k2 (1+ k2))
  26.        (setq s2 (ssname ss2 k2))
  27.        (setq method1 2)
  28.        (cond
  29.          ((= method1 1) (setq s3 s2))
  30.          ((= method1 2) (setq en3 (entget s2)))
  31.        )
  32.        (setq g 1)
  33.        (while (= g 1)
  34.          (cond
  35.            ((= method1 1) (setq s3 (entnext s3)))
  36.            ((= method1 2) (setq s3 (entnext (cdr (assoc -1 en3)))))
  37.          )
  38.          (setq en3 (entget s3))
  39.          (setq typ3 (strcase (cdr (assoc 0 en3)) t)) ;|  #type  |;
  40.          ;;(myprint "typ3")
  41.          (if (= typ3 "seqend")
  42.            (setq g 0)
  43.            (progn
  44.              (setq tag3 (cdr (assoc 2 en3)))
  45.              (setq la3 (cdr (assoc 8 en3)))
  46.              (setq en4 (tblsearch "layer" la3))
  47.              (setq layerstatus (cdr (assoc 70 en4)))
  48.              ;;(myprint "layerstatus")
  49.              (if (= tag3 tag)
  50.                (if (= (logand layerstatus 4) 4) ;|  #locked - Not Necessary : Works Without it !!  |;
  51.                  (princ "\n  Locked  !!  ")
  52.                  (progn
  53.                    (setq en3 (subst (cons 1 atedn-var1) (assoc 1 en3) en3))
  54.                    (entmod en3)
  55.                    (setq i (1+ i))
  56.                  )
  57.                )
  58.              )
  59.            )
  60.          )
  61.        )
  62.        (entupd s2)
  63.      )
  64.      (princ (strcat "\n  Number of Attributes Changed :  " (itoa i) "  <<  "))
  65.     )
  66.     (t (princ "\n  Not an Attribute in a Block !!  "))
  67.   )
  68. )