Select and fill attributes with predefined values

Select and fill attributes with predefined values

Anonymous
Not applicable
2,819 Views
14 Replies
Message 1 of 15

Select and fill attributes with predefined values

Anonymous
Not applicable

Hi all,

 

Can anyone help me to set values for 5 distinct attributes with predefined string values in the LISP code?

 

Unlike their values, attributes tag names cannot be pre-determined in the code though. That's why I want to be able to select the attribute by a click and get their value updated afterwards. i.e. 1st value (predefined in the code) goes to the first selected ATTRIBUTE, 2nd value (predefined in the code) goes to  second selected ATTRIBUTE and so on.

 

I should mention some attributes that I select, may not have any value at the moment. I have turned ON the QTEXT value so I can select blank attributes.

 

 

Thanks in advance.

 

0 Likes
Accepted solutions (1)
2,820 Views
14 Replies
Replies (14)
Message 2 of 15

Anonymous
Not applicable

Try NENTSEL.  It's like ENTSEL but instead of returning a list of the main entity's name (if you're clicking on an attribute that would be the entity name of the INSERT to which it's attached) and the pick point it returns the entity name of the selected sub-entity (if you click on an ATTRIB that would be the entity name of the ATTRIB itself) and the pick point.  If I do

 

(setq return_value (nentsel))

 

AutoCAD prompts

 

Select object:

 

Then when I click on the ELEV attribute of an old-school DCA POINT block in this drawing on my screen it returns this list

 

(<Entity name: -7d8390> (428227.0 1.29808e+006 0.0))

 

(car return_value) returns

 

<Entity name: -7d8390>

 

and (entget (car return_value)) returns the entity data for the POINT attribute:

 

((-1 . <Entity name: -7d8390>) (0 . "ATTRIB") (330 . <Entity
name: -7d8398>) (5 . "57836") (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8
. "elev") (100 . "AcDbText") (10 428224.0 1.29808e+006 0.0) (40 . 0.8) (1 .
"8.182373") (50 . 0.0) (41 . 1.0) (51 . 0.0) (7 . "S6") (71 . 0) (72 . 0) (11
0.0 0.0 0.0) (210 0.0 0.0 1.0) (100 . "AcDbAttribute") (2 . "ELEV") (70 . 0)
(73 . 0) (74 . 0) (280 . 0))

 

which you can modify with ENTMOD, as well as reading information from the entity data.

 

So supposed I want to reset the value of the selected attribute to "101.25".

 

(defun test()

 (setq return_value (nentsel))

 (setq attribute_name (car return_value))

 (setq attribute_data (entget attribute_name))

 (setq revised_attribute_data

  (subst

   (cons 1 "101.25")

   (assoc 1 attribute_data)

   attribute_data

  )

 )

 (entmod revised_attribute_data)

 (entupd attribute_name)

)

 

The last ENTUPD line is not strictly necessary, as the attribute value was updated by the previous ENTMOD line, but you wouldn't see the change on the screen until you REGEN the drawing.  Also, in a real program you want to do some checking to make sure you selected something and that what you selected was an ATTRIB rather than some other kind of entity.

0 Likes
Message 3 of 15

joselggalan
Advocate
Advocate

Can you indicate the string tags of the 5 attributes please..

 

 

0 Likes
Message 4 of 15

Ranjit_Singh
Advisor
Advisor

maybe something like this

(defun c:somefunc  (/ ctr values attdata)
 (setq ctr 1)
 (repeat 5
  (setq values (cons (getstring t (strcat "\nEnter att" (itoa ctr) " value: ")) values)
        ctr    (1+ ctr)))
 (while (setq ctr 1)
  (mapcar '(lambda (x)
            (and (setq attdata (entget (car (nentsel (strcat "\nSelect tag" (itoa ctr) ": ")))))
                 (= (cdr (assoc 0 attdata)) "ATTRIB")
                 (entmod (subst (cons 1 x) (assoc 1 attdata) attdata)))
            (setq ctr (1+ ctr)))
          (reverse values)))
 (princ))
0 Likes
Message 5 of 15

Anonymous
Not applicable

Assume I want to fill attributes like below:

"0" ----> This value has to be replaced by anything currently sitting on 1st click
"17-03-2017" ----> This value has to be replaced by anything currently sitting on 2ns click
"AS BUILT" ----> This value has to be replaced by anything currently sitting on 3rd click
"JG" ----> This value has to be replaced by anything currently sitting on 4th click
"KV" ----> This value has to be replaced by anything currently sitting on 5th click

Unlike the code provided by Ranjit in Post #4, I don't want to enter String values during run-time. Instead I prefer have them hard coded into the LISP routine beforehand.

0 Likes
Message 6 of 15

Anonymous
Not applicable

Thanks heaps Ranjit. Your code works fine but it has two flaws:

 

1- It does not break the loop after filling 5th TAG i.e. it keeps asking for TAG1, etc again.

2- I prefer to define string values in the code rather than giving user the option to enter them during run-time.

 

 

0 Likes
Message 7 of 15

Anonymous
Not applicable
Thanks W Kiernan. Lessons learnt.
0 Likes
Message 8 of 15

Ranjit_Singh
Advisor
Advisor
(defun c:somefunc  (/ attdata ctr)
 (setq ctr 1)
 (mapcar '(lambda (x)
           (and (setq attdata (entget (car (nentsel (strcat "\nSelect tag" (itoa ctr) ": ")))))
                (= (cdr (assoc 0 attdata)) "ATTRIB")
                (entmod (subst (cons 1 x) (assoc 1 attdata) attdata)))
           (setq ctr (1+ ctr)))
         '("value1" "value2" "value3" "value4" "value5"))
 (princ))
0 Likes
Message 9 of 15

Anonymous
Not applicable

It give me following error on run:

 

; error: bad argument type: fixnump: nil
0 Likes
Message 10 of 15

Ranjit_Singh
Advisor
Advisor
Accepted solution

forgot to initialize ctr

(defun c:somefunc  (/ attdata ctr)
 (setq ctr 1)
 (mapcar '(lambda (x)
           (and (setq attdata (entget (car (nentsel (strcat "\nSelect tag" (itoa ctr) ": ")))))
                (= (cdr (assoc 0 attdata)) "ATTRIB")
                (entmod (subst (cons 1 x) (assoc 1 attdata) attdata)))
           (setq ctr (1+ ctr)))
         '("value1" "value2" "value3" "value4" "value5"))
 (princ))
0 Likes
Message 11 of 15

Anonymous
Not applicable

Thanks Ranjit. It works but 5th TAG is getting ignored  i.e. updates the the first 4 attributes that I click but ignores the fifth one.

0 Likes
Message 12 of 15

Ranjit_Singh
Advisor
Advisor

Works at my end. Unless you provide more information it will be difficult to find the cause. Is there an error message?

0 Likes
Message 13 of 15

Anonymous
Not applicable

oops. My bad. The fifth one that I was clicking, was actually a piece of TEXT, not Attribute. 

 

 

Thanks for your help.

 

 

0 Likes
Message 14 of 15

appuraja
Explorer
Explorer

I want to explore above point more for one of my requirement.

Actually I having attribute block with Field ROOM1 , ROOM2, ROOM3, ROOM4. When i am inserting this block on my floorplan, i want to insert the Room name in each field just by selecting that respective room text. For example: if my room is having name & number "Store (one text above) 123 (2nd text below)" then i want to fill Store in ROOM1 and 123 in ROOM2.  Can you please provide the script for the same? Thanks in advance

 

 

0 Likes
Message 15 of 15

devitg
Advisor
Advisor

It will be for better help , if you can upload your sample.dwg 

0 Likes