Jump to content

Is there a lisp for updating existing numeric attribute values by a known integer?


James Willey

Recommended Posts

If you're as ancient as I am, you may remember the NUMINC lisp routine by Lee Mac Programming. This post hinges off that.

 

Case Problem

Setout numbers defined by a block with one attribute.

Block inserted using the NUMINC lips routine.

After creating the blocks with incremental numeric attribute values from eg. 01 to 99, I've discovered that I've missed one point after eg. 39 or perhaps I need to add a new block due to a design change, how then can I efficiently update the remaining individual blocks to increase their numeric attribute values from 40 to what will now be 100?

 

Is there such a lisp routine that will;

  • Prompt me to select the block in question
  • Use the Attribute Editor in the background perhaps
  • Search for a numeric attribute value (X)
  • Prompt for an integer (Y) to increase or decrease that known value
  • Calculate X+Y=Z 
  • Apply the new value (Z) to the attribute
  • Complete the Attribute Editor command
  • Prompt for a new selection or Esc to cancel the routine

 

Thanks in advance.

Link to comment
Share on other sites

Here is a Lisp. It can add 1 (or other number) to an integer attribute of many blocks, at once.

(defun c:pp()
  (setq blockName (getstring T "Block name: ")
	attrName (strcase (getstring T "Attribute: "))
	plus (getint "value to add: "))
  (setq ss (ssget (list '(0 . "INSERT")(cons 2 blockName)'(66 . 1))))
  (repeat (setq i (sslength ss))
    (setq en (ssname ss (setq i (1- i))))
    (while (and (/= (cdr (assoc 0 (setq el (entget en)))) "SEQEND") (/= (cdr (assoc 2 el)) attrName)) (setq en (entnext en)))
    (setq el (subst (cons 1 (itoa (+ plus (atoi (cdr (setq ass1 (assoc 1 el))))))) ass1 el)
	  el (entmod el))
    )
  (setq ss nil)
  )

 

Link to comment
Share on other sites

Just a suggestion, no need to  type block name, using nentsel pick the attribute you want to change, this returns the Tag name as a property. pt is the ( cadr ent).

 

Then do (ssget pt '((0 . "Insert")))) from this pull block name.

 

Then can do a ssget using blkname to get all blocks.

 

Now where did I put this code, I use if often. Found it.

 

(setq blk (nentsel "\nPick the block attribute to get tag name "))
(setq pt (cdr blk))
(setq blktagname (cdr (assoc 2 (entget (car blk)))))
(setq ent (ssname (ssget pt '((0 . "INSERT"))) 0))
(setq blkname (cdr (assoc 2 (entget ent))))

 

Edited by BIGAL
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...