TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: dubb on June 19, 2017, 02:36:51 PM

Title: Select and edit a tag in a block with multiple attributes.
Post by: dubb on June 19, 2017, 02:36:51 PM
I would like to know how to edit a specific tag in an attribute without having to explicitly defining the tag id. I have seen this somewhere before I can't recall where.
In case I had a block with two attribute tags I would like to click on either text it would edit that specific tag. See attached for an example of the block. If someone could help me out with some sample code. Much appreciated. Thanks.

*Would like to utilize entsel or entmod to edit the attribute*
Title: Re: Select and edit a tag in a block with multiple attributes.
Post by: ronjonp on June 19, 2017, 03:10:44 PM
Maybe:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ e)
  2.   (if (and (setq e (car (nentsel))) (= "ATTRIB" (cdr (assoc 0 (setq e (entget e))))))
  3.     (entmod (subst (cons 1 "TEST") (assoc 1 e) e))
  4.   )
  5.   (princ)
  6. )
You can also hold down CNTRL and double click the attribute to edit with out the 'Enhanced Attribute Editor".
Title: Re: Select and edit a tag in a block with multiple attributes.
Post by: dubb on June 19, 2017, 03:21:23 PM
That is exactly what I'm looking for. Thanks Ron.

Maybe:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:foo (/ e)
  2.   (if (and (setq e (car (nentsel))) (= "ATTRIB" (cdr (assoc 0 (setq e (entget e))))))
  3.     (entmod (subst (cons 1 "TEST") (assoc 1 e) e))
  4.   )
  5.   (princ)
  6. )
You can also hold down CNTRL and double click the attribute to edit with out the 'Enhanced Attribute Editor".
Title: Re: Select and edit a tag in a block with multiple attributes.
Post by: ronjonp on June 19, 2017, 03:42:26 PM
Glad to help :)
Title: Re: Select and edit a tag in a block with multiple attributes.
Post by: dubb on June 20, 2017, 12:06:25 PM
Here is what I a made.

Next thing I want to do is update or edit an attribute in a block without having to define the tag id. The block only has one attribute.

Code: [Select]
;select text or mtext
;select attribute
;edits attribute with text
(defun c:atxt (/ e)
  (setq txt (cdr(assoc 1 (entget(car(entsel))))))
    (if (and (setq e (car (nentsel))) (= "ATTRIB" (cdr (assoc 0 (setq e (entget e))))))
    (entmod (subst (cons 1 txt) (assoc 1 e) e))
  )
  (princ)
)