Find & replace 'Attribute TEXT value' based on input provided in XLS

Find & replace 'Attribute TEXT value' based on input provided in XLS

Anonymous
Not applicable
1,790 Views
9 Replies
Message 1 of 10

Find & replace 'Attribute TEXT value' based on input provided in XLS

Anonymous
Not applicable

Dear All, 

I have been running an autolisp program (courtsey by some user online) for Find and replace for 'Normal Text' and 'Attribute Text Value' based on input provided in 'x.xls' file. It works absoulety fine with 'Normal Text' replacment (a different lisp not attached here) but when it comes to find and replacement of 'Attribute Text value' it replaces 'Attribute Tag' and infact 'Default/Text Value' remain unchanged. Please help & correct the attached code, would be great help I  have to run this program in more than 80 files for 'Attribute Text values' change.

 

(defun FLNG_PutAtt(dataList)

  ;;;--- Set up a revised attVal counter
  (setq attValCnt 0)

  ;;;--- Update progress
  (princ "\n Getting Block information...")

  ;;;--- Get a selection set of all blocks
  (if(setq eset(ssget "X" (list (cons 0 "INSERT"))))
    (progn
        
      ;;;--- Set up a counter
      (setq cntr 0)
          
      ;;;--- Update progress
      (princ "\n Processing attributes...")
           
      ;;;--- Cycle through each entity
      (while (< cntr (sslength eset))
            
        ;;;--- Get the name of the first entity
        (setq en(ssname eset cntr))
         
        ;;;--- Get the dxf group codes of the entity
        (setq enlist(entget en))
           
        ;;;--- If the block contains attributes
        (if(= 1 (cdr(assoc 66 enlist)))
          (progn
               
            ;;;--- Get the name of the sub-entity
            (setq en2(entnext en))
               
            ;;;--- Get it's dxf group codes
            (setq enlist2(entget en2))
               
            ;;;--- Loop until SEQEND is found
            (while(/= "SEQEND" (cdr(assoc 0 enlist2)))
                
              ;;;--- Make sure it is an attribute
              (if(= "ATTRIB" (cdr(assoc 0 enlist2)))
                (progn
                   
                  (setq attVal(cdr(assoc 2 enlist2)))
                  (setq oldVal(cdr(assoc 1 enlist2)))
                  (foreach a dataList
                    (if(= (strcase attVal)(strcase (car a)))
                      (progn
                        (cond
                          ((= nil (cadr a))(setq newVal " "))
                          ((= (read "REAL") (type (cadr a)))(setq newVal(vl-princ-to-string (cadr a))))
                          ((= (read "INT") (type (cadr a))) (setq newVal(itoa (cadr a))))
                          (T (setq newVal (cadr a)))
                        ) 
                        (setq enlist2(subst (cons 1 newVal)(assoc 1 enlist2)enlist2))
                        (entmod enlist2)
                        (entupd en2)
                        (princ (strcat "\n Changed Value of Attribute: " attVal " From: " oldVal " To: " newVal))
                        (setq attValCnt(+ attValCnt 1))
                      )
                    )
                  )
                  (setq en2(entnext en2))
                  (setq enlist2(entget en2))
                )  
              )
            ) 
          ) 
        )
        (setq cntr(+ cntr 1))
      )
    )
    (alert "No blocks found in drawing!")
  )
  (princ (strcat "\n Revised (" (itoa attValCnt) ") attributes!"))
  (princ)

 

Attribut-Text-change.jpg

Running only in model space, Acad ver 2010, these are Text and Mtext both.

Would sincerely appreicate if some one could help me on this?

- TOMES

 

0 Likes
Accepted solutions (1)
1,791 Views
9 Replies
Replies (9)
Message 2 of 10

Ajilal.Vijayan
Advisor
Advisor

Hi Tomes,

Welcome to Autodesk Forum.

Can you please post how the supplied argument(datalist) for this function looks like.

Because at this line the program check for matching TAG with the supplied datalist.

So if the datalist contains the TAG value TEXT1, TEXT2, the program should work.

(if(= (strcase attVal)(strcase (car a)))
Message 3 of 10

Anonymous
Not applicable

Hi Vijayan,

Thanks for replying, I am just novice on Lisp.

Hope you are looking either of this >>

 

[1]

-----------------------------------------------

  ;;;--- Get each cells value and store it in a list
(setq dataList (getRangeCells 1stRow 1stCol LstRow LstCol))

------------------------------------------

 

 

[2]

-----------------------------------------------

      ;;;--- Get the data from EXCEL
      (if(setq dataList(FLNG_GET))
        (progn

          ;;;--- If the REPLACE TEXT option was selected
          (if(= replaceTxt 1)
            (progn

              ;;;--- Load the FLNG_PutTxt routine
              (load "FLNG_PutTxt")

              ;;;--- Execute the FLNG_PutTxt routine
              (FLNG_PutTxt dataList)
            )
          )

          ;;;--- If the REPLACE ATTRIBUTE option was selected
          (if(= replaceAtt 1)
            (progn

              ;;;--- Load the FLNG_PutAtt routine
              (load "FLNG_PutAtt")

              ;;;--- Execute the FLNG_PutAtt routine
              (FLNG_PutAtt dataList)
            )
          )

 

--------------------------------------------

 

- TOMES

 

0 Likes
Message 4 of 10

Anonymous
Not applicable

 

Vijayan,

Please note I m looking 'Attribute Value' to be changed not 'Attirbute Tag'.

 

Thanks a lot.

 

 

- TOMES

 

Attribut-Text-change.jpg

0 Likes
Message 5 of 10

Ajilal.Vijayan
Advisor
Advisor

Hi,

Please make sure that the excel file contains the TAGs TEXT1, TEXT2.

Because I think the excel file contains A1,A2 and A3 as TAG and the program change the value of A# TAG.

Does your excel file contains the TAGs TEXT1, TEXT2 ?

If possible please share the excel file too..

 

I try with a sample file and it seems its working.

Before

Spoiler
Before.JPG

After

Spoiler
After.JPG

 

0 Likes
Message 6 of 10

hmsilva
Mentor
Mentor
Accepted solution

Hi Tomes,

Is your 'dataList' something like (("oldVal1" "newVal1")("oldVal2" "newVal2")...("oldValx" "newValx")), just with values?
If it is, you'll have to change the test expression
from
(if(= (strcase attVal)(strcase (car a)))
to
(if(= (strcase oldVal)(strcase (car a)))

 

Hope this helps,
Henrique

EESignature

Message 7 of 10

Anonymous
Not applicable

Thanks Vijayan,

Program infact finds A1,A2, A3 etc. Text or Attribute in AutoCAD and replaces with value in Corresponding Excel cell i.e. A1, A2, A3 etc.

Thus it finds only excel cell value and we need to input only replacment cell value in excel cells A1, A2, A3 etc..

 

Thanks for your time. Sincerely appreciate your help.

 

- TOMES

0 Likes
Message 8 of 10

Anonymous
Not applicable

Hi Henrique,

Excellent Work !! I have been struggling for this, just did as per your instruction and here I get my solution.. Bingo !!!

Overall this program increased my accuracy & reduced my work to 1/3rd.....no doubt All credit goes to you.... wish I could clap.. 🙂

 

Thanks for the support. Please keep helping.

 

regards,

TOMES

 

 

0 Likes
Message 9 of 10

hmsilva
Mentor
Mentor

@Anonymous wrote:

Hi Henrique,

Excellent Work !! I have been struggling for this, just did as per your instruction and here I get my solution.. Bingo !!!

Overall this program increased my accuracy & reduced my work to 1/3rd.....no doubt All credit goes to you.... wish I could clap.. 🙂 

Thanks for the support. Please keep helping.

regards,

TOMES


You're welcome, TOMES
Glad I could help

Henrique

EESignature

Message 10 of 10

olivierlepage89
Observer
Observer

Bonjour, je suis novice dans le domaine des Macros, cependant, j'ai eu l'occasion de travaillé avec une macro similaire pour remplacer des attributs d'un fichier .dxf ave l'aide d'une macro .xls.

Cependant comment reproduire votre macro en détail ou vidéo? Merci de votre retour.

0 Likes