Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Adding Xdata From Slected Mtext or Text

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
karunakaran1991
988 Views, 3 Replies

Adding Xdata From Slected Mtext or Text

Hi,

 

I am creating lisp routine and the work is to selected Mtext or text and the corresponding content is to be added as Xdata to the selected entity.

 

(defun C:addxdata()

(setq a(entget(car(entsel"\nSelect Text: "))))

(setq Xdata1 (cdr (assoc 1 a))) (princ Xdata1)

(setq b(entget(car(entsel"\nSelect Text: "))))

(setq Xdata2 (cdr (assoc 1 b))) (princ Xdata2)

(regapp "Test_Xdata" )

(setq oldlist (entget (car (entsel))))

(setq thedata '((-3 ("Test_Xdata" (1000 . Xdata1) (1000 . Xdata2 ))))) )

 

Then I used list Xdata option available under Express tool Tab (Auto Cad 2014).

 

I didn't find any Xdata Attached with it.

 

After Adding the Xdata, I wanna export to Excel.

 

For the Excel Conversion, Lisp is working good.

 

I guess the Problem is in the following line,

 

(setq thedata '((-3 ("Test_Xdata" (1000 . Xdata1) (1000 . Xdata2 )))))

 

Though the value stored in variable it is not working properly.

 

Tags (1)
3 REPLIES 3
Message 2 of 4
hmsilva
in reply to: karunakaran1991

Try

 

(defun C:addxdata ( / a adata b bdata c newlist oldlist thedata Xdata1 Xdata2)
  (if (and (setq a (car (entsel "\nSelect Text: ")))
           (setq adata (entget a))
           (wcmatch (cdr (assoc 0 adata)) "TEXT,MTEXT")
           (setq Xdata1 (cdr (assoc 1 adata)))
           (princ Xdata1)
           (setq b (car (entsel "\nSelect Text: ")))
           (setq bdata (entget b))
           (wcmatch (cdr (assoc 0 bdata)) "TEXT,MTEXT")
           (setq Xdata2 (cdr (assoc 1 bdata)))
           (princ Xdata2)
           (setq c (car (entsel "\nSelect object to attach xdata...")))
           (setq oldlist (entget c))
      )
    (progn
      (regapp "Test_Xdata")
      (setq thedata (list (list -3
                                (list "Test_Xdata"
                                      (cons 1000 Xdata1)
                                      (cons 1000 Xdata2)
                                )
                          )
                    )
      )
      (setq newlist (append oldlist thedata))
      (entmod newlist)
    )
  )
  (princ)
)

 

From the help files:

 

String
 1000. Strings in extended data can be up to 255 bytes long (with the 256th byte reserved for the null character).

 

 

Henrique

EESignature

Message 3 of 4
karunakaran1991
in reply to: hmsilva

 I got it where i missed.

 

Thanks Hmsilva for your precious time 

 

Message 4 of 4
hmsilva
in reply to: karunakaran1991

You're welcome!
Glad I could help

Henrique

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost