Modify attribute with a multiline text

Modify attribute with a multiline text

kpennell
Collaborator Collaborator
1,065 Views
4 Replies
Message 1 of 5

Modify attribute with a multiline text

kpennell
Collaborator
Collaborator

I would have thought that this might work:

 

 (setq ent (cdr (assoc -2 (tblsearch "block" "EP201-L"))))
 (while ent
  (setq entdata (entget ent))
  (and (and (= (cdr (assoc 0 entdata)) "ATTDEF")
     (= (cdr (assoc 2 entdata)) "TAIL")
       )
       (entmod (subst (cons 1 "\\W0.7500;Whatever I\\want to put in") (assoc 1 entdata) entdata))
  )
  (setq ent (entnext ent))
 )

 

the entity data of the item looks like this, also attached a drawing with the "insert"

 

  (
    (-1 . <Entity name: 7ff42c938ca0>)
    (0 . "INSERT")
    (330 . <Entity name: 7ff42c903f10>)
    (5 . "457A")
    (100 . "AcDbEntity")
    (67 . 1)
    (410 . "SHT 01")
    (8 . "0")
    (100 . "AcDbBlockReference")
    (66 . 1)
    (2 . "EP201-L")
    (10 2.82242 6.12149 0.0)
    (41 . 1.0)
    (42 . 1.0)
    (43 . 1.0)
    (50 . 0.0)
    (70 . 0)
    (71 . 0)
    (44 . 0.0)
    (45 . 0.0)
    (210 0.0 0.0 1.0)
  )

  (
    (-1 . <Entity name: 7ff42c938cb0>)
    (0 . "ATTRIB")
    (330 . <Entity name: 7ff42c938ca0>)
    (5 . "457B")
    (100 . "AcDbEntity")
    (67 . 1)
    (410 . "SHT 01")
    (8 . "0_WELD")
    (100 . "AcDbText")
    (10 2.35144 5.94961 0.0)
    (40 . 0.09375)
    (1 . "5")
    (50 . 0.0)
    (41 . 0.75)
    (51 . 0.0)
    (7 . "Romans")
    (71 . 0)
    (72 . 1)
    (11 2.38492 5.99649 0.0)
    (210 0.0 0.0 1.0)
    (100 . "AcDbAttribute")
    (280 . 0)
    (2 . "GAPDISTANCE")
    (70 . 0)
    (73 . 0)
    (74 . 2)
    (280 . 0)
  )

  (
    (-1 . <Entity name: 7ff42c938cc0>)
    (0 . "ATTRIB")
    (5 . "457C")
    (102 . "{ACAD_XDICTIONARY")
    (360 . <Entity name: 7ff42c938cd0>)
    (102 . "}")
    (330 . <Entity name: 7ff42c938ca0>)
    (100 . "AcDbEntity")
    (67 . 1)
    (410 . "SHT 01")
    (8 . "0_WELD")
    (100 . "AcDbText")
    (10 1.81461 6.07461 0.0)
    (40 . 0.09375)
    (1 . "")
    (50 . 0.0)
    (41 . 0.75)
    (51 . 0.0)
    (7 . "Romans")
    (71 . 0)
    (72 . 2)
    (11 1.81461 6.12149 0.0)
    (210 0.0 0.0 1.0)
    (100 . "AcDbAttribute")
    (280 . 0)
    (2 . "TAIL")
    (70 . 0)
    (73 . 0)
    (74 . 2)
    (280 . 0)
    (71 . 2)
    (72 . 0)
    (11 1.81461 6.12149 0.0)
    (101 . "Embedded Object")
    (10 1.81461 6.12149 0.0)
    (40 . 0.09375)
    (41 . 0.0)
    (46 . 0.0)
    (71 . 6)
    (72 . 5)
    (1 . "\\W0.7500;TYP\\PEP-201"); this is what I want modified.
    (7 . "Romans")
    (210 0.0 0.0 1.0)
    (11 1.0 0.0 0.0)
    (42 . 0.378348)
    (43 . 0.25)
    (50 . 0.0)
    (73 . 1)
    (44 . 1.0)
    (-3
      (
        "AcadAnnotative"
        (1000 . "AnnotativeData")
        (1002 . "{")
        (1070 . 1)
        (1070 . 1)
        (1002 . "}")
      )
    )

0 Likes
1,066 Views
4 Replies
Replies (4)
Message 2 of 5

AntiqueAlan
Contributor
Contributor

When you entmod an attribute of a block, you also have to entupd the block

0 Likes
Message 3 of 5

kpennell
Collaborator
Collaborator

Thanks for the response.

 

usually, the 'entupd' follows 'entmod' which is where I placed it and still no change.  I'm trying to step through what gets returned,  but I'm getting the results I'm expecting.

 

When I run this from the beginning by defining a function, nothing happens, but when I step through it, the wrong text entity (not the attribute), changes.

 

(setq ss (ssget "_X" (list '(0 . "INSERT") '(2 . "EP201-L") (cons 410 (getvar 'ctab)))))
 (setq hnd  (ssname ss 0))
 
 (setq ent (cdr (assoc -2 (tblsearch "block" "EP201-L"))))
 (while ent
  (setq entdata (entget ent))
  (and (and (= (cdr (assoc 0 entdata)) "ATTDEF")
     (= (cdr (assoc 2 entdata)) "TAIL")
       )
       (entmod (subst (cons 1 "asdf") (assoc 1 entdata) entdata))
    (entupd hnd)
  )
  (setq ent (entnext ent))
 )

0 Likes
Message 4 of 5

ronjonp
Mentor
Mentor

Are you using AutoCAD on MAC? If not I'd suggest using vla .. it's a bit simpler IMO:

(defun c:foo (/ e)
  (cond
    ((and (setq e (car (entsel "\nPick block: ")))
	  (vlax-property-available-p (setq e (vlax-ename->vla-object e)) 'hasattributes)
     )
     (foreach att (vlax-invoke e 'getattributes)
       (cond ((= "TAIL" (vla-get-tagstring att)) (vla-put-textstring att "\\W0.7500;TYP\\PEP-201"))
       )
     )
    )
  )
  (princ)
)
0 Likes
Message 5 of 5

dbhunia
Advisor
Advisor

Hi

 

How far I know it is not possible "attribute with multi line text" like "mtext".......

 

And what I get from this post & drawing...... You want to change the value of all the Attribute Tags Named as "TAIL*" with "asdf" of all the Block named "EP201-L" in a Particular Layout Tab......

 


@kpennell wrote:

 

.............................

When I run this from the beginning by defining a function, nothing happens, but when I step through it, the wrong text entity (not the attribute), changes.

 

(setq ss (ssget "_X" (list '(0 . "INSERT") '(2 . "EP201-L") (cons 410 (getvar 'ctab)))))
 (setq hnd  (ssname ss 0))
 
 (setq ent (cdr (assoc -2 (tblsearch "block" "EP201-L"))))
 (while ent
  (setq entdata (entget ent))
  (and (and (= (cdr (assoc 0 entdata)) "ATTDEF")
     (= (cdr (assoc 2 entdata)) "TAIL")
       )
       (entmod (subst (cons 1 "asdf") (assoc 1 entdata) entdata))
    (entupd hnd)
  )
  (setq ent (entnext ent))
 )


 

But the above Syntax is not right......... By this way you are Hitting the Block & Extracting its Data only ...... Not any Attribute.......Your process should be like this.......(For the particular block)

 

 

(setq ss (ssget "_X" (list '(0 . "INSERT") '(2 . "EP201-L") (cons 410 (getvar 'ctab)))))
(repeat (setq N (sslength ss))
	(setq Data (ssname ss (setq N (- N 1))))
	(setq EntityData1 (entget (entnext (entnext Data))));;To Get Att Tag "TAIL_001"
	     (entmod (subst (cons 1 "asdf") (assoc 1 EntityData1) EntityData1))
	(setq EntityData2 (entget (entnext (entnext (entnext Data)))));;To Get Att Tag "TAIL_002"
	     (entmod (subst (cons 1 "asdf") (assoc 1 EntityData2) EntityData2))
	(entupd Data)
)

 

But the above way you have to hit each Attribute to modify it.........

 

The better way, let the code find the Attribute & Modify it as you want Like........

 

 

(setq ss (ssget "_X" (list '(0 . "INSERT") '(2 . "EP201-L") (cons 410 (getvar 'ctab)))))
(repeat (setq NOS (sslength ss))
   (setq obj (vlax-ename->vla-object (ssname SS (setq NOS (- NOS 1)))))
   (foreach att (vlax-invoke Obj 'GetAttributes)
      (cond ((= T (wcmatch (vla-get-Tagstring att) "TAIL*")) (vla-put-textstring att "asdf")))
   )
)

 

Here for the Blue line code will check for all the Attribute Tag Named as "TAIL*" and will change the value with "asdf"...... If you want to change a particular Attribute Tag with A particular value then follow this.......

 

.....................
   (foreach att (vlax-invoke Obj 'GetAttributes)
      (cond ((= (vla-get-Tagstring att) "TAIL_001") (vla-put-textstring att "asdf-1")))
      (cond ((= (vla-get-Tagstring att) "TAIL_002") (vla-put-textstring att "asdf-2")))
   )
......................

Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes