Author Topic: Help modifying ATTNUM  (Read 1528 times)

0 Members and 1 Guest are viewing this topic.

Bart Henry

  • Mosquito
  • Posts: 2
Help modifying ATTNUM
« on: July 02, 2021, 12:45:45 PM »
Hello all, I am using the ATTNUM lisp by Lee Mac... I would like to know 2 things. first how, how would I hard code the "tag" to always be "WIRE#", without having to type it in. 2nd how would i change the code to let me pick 2 blocks at a time. I am VERY new to lisp.

Here is the code.

Code - Auto/Visual Lisp: [Select]
  1. (defun c:attnum ( / ent enx num tag )
  2.     (if (/= "" (setq tag (strcase (getstring "\nSpecify attribute tag <exit>: "))))
  3.                 (progn
  4.             (setq num (cond ((getint "\nSpecify starting number <1>: ")) (1)))
  5.             (while
  6.                 (not
  7.                     (progn
  8.                         (setvar 'errno 0)
  9.                         (setq ent (car (entsel (strcat "\nSelect block number " (itoa num) " <exit>: "))))
  10.                         (cond
  11.                             (   (= 7 (getvar 'errno))
  12.                                 (prompt "\nMissed, try again.")
  13.                             )
  14.                             (   (null ent))
  15.                             (   (/= "INSERT" (cdr (assoc 0 (setq enx (entget ent)))))
  16.                                 (prompt "\nThe selected object is not a block.")
  17.                             )
  18.                             (   (/= 1 (cdr (assoc 66 enx)))
  19.                                 (prompt "\nThe selected block is not attributed.")
  20.                             )
  21.                             (   (progn
  22.                                     (setq ent (entnext ent)
  23.                                           enx (entget  ent)
  24.                                     )
  25.                                     (while
  26.                                         (and
  27.                                             (= "ATTRIB" (cdr (assoc 0 enx)))
  28.                                             (/= tag (strcase (cdr (assoc 2 enx))))
  29.                                         )
  30.                                         (setq ent (entnext ent)
  31.                                               enx (entget  ent)
  32.                                         )
  33.                                     )
  34.                                     (/= "ATTRIB" (cdr (assoc 0 enx)))
  35.                                 )
  36.                                 (prompt (strcat "\nThe selected block does not contain the attribute \"" tag "\"."))
  37.                             )
  38.                             (   (entmod (subst (cons 1 (itoa num)) (assoc 1 enx) enx))
  39.                                 (entupd ent)
  40.                                 (setq num (1+ num))
  41.                                 nil
  42.                             )
  43.                             (   (prompt "\nUnable to edit attribute value."))
  44.                         )
  45.                     )
  46.                 )
  47.             )
  48.         )
  49.     )
  50.     (princ)
  51. )



EDIT (John): Added code tags.
« Last Edit: July 08, 2021, 08:34:21 AM by John Kaul (Se7en) »

BIGAL

  • Swamp Rat
  • Posts: 1411
  • 40 + years of using Autocad
Re: Help modifying ATTNUM
« Reply #1 on: July 03, 2021, 02:28:07 AM »
Try
1 (setq tag "WIRE#")

 2 while and extra close bracket
Code: [Select]
(while (setq ent (car (entsel (strcat "\nSelect block number " (itoa num) " <exit>: "))))
...........
.................
                            (   (prompt "\nUnable to edit attribute value."))
                        )
                    )
                )
            )
)
        )
    )
    (princ)
A man who never made a mistake never made anything

Bart Henry

  • Mosquito
  • Posts: 2
Re: Help modifying ATTNUM
« Reply #2 on: July 08, 2021, 07:14:59 AM »
So the IF statement should change from

     (if (/= "" (setq tag (strcase (getstring "\nSpecify attribute tag <exit>: "))))

to

     (if (/= "" (setq tag WIRE#)))


ronjonp

  • Needs a day job
  • Posts: 7529
Re: Help modifying ATTNUM
« Reply #3 on: July 08, 2021, 01:01:18 PM »
So the IF statement should change from

     (if (/= "" (setq tag (strcase (getstring "\nSpecify attribute tag <exit>: "))))

to

     (if (/= "" (setq tag WIRE#)))
Welcome to TheSwamp! :)
Code - Auto/Visual Lisp: [Select]
  1. ;; Change this
  2. (/= "" (setq tag (strcase (getstring "\nSpecify attribute tag <exit>: "))))
  3. ;; To this
  4. (setq tag "WIRE#")

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Help modifying ATTNUM
« Reply #4 on: July 14, 2021, 06:19:37 PM »
2nd how would i change the code to let me pick 2 blocks at a time.

Such that both are populated with the same value?

BIGAL

  • Swamp Rat
  • Posts: 1411
  • 40 + years of using Autocad
Re: Help modifying ATTNUM
« Reply #5 on: July 14, 2021, 09:15:53 PM »
An alternative load the changed code then type (attnum "WIRE#") on command line, then can be used for any tagname. You can also do a simple defun that loads the code.

Code: [Select]
Change the 2 lines
(defun attnum (tag / ent enx num )
    (if (/= "" tag)

Add at top of code, or any other tag names you want just make more defuns.

Code: [Select]
(defun c:wire ()
(if (not attnum)(load "attnum"))
(attnum "WIRE#")
)
A man who never made a mistake never made anything