Integrating Lisp that gets MLEADER PROPERTIES with Excel

Integrating Lisp that gets MLEADER PROPERTIES with Excel

athuasc
Explorer Explorer
511 Views
4 Replies
Message 1 of 5

Integrating Lisp that gets MLEADER PROPERTIES with Excel

athuasc
Explorer
Explorer

I've been trying to integrate the current code with excel. It gets the properties of the selected MLEADERS, an example of the result is (("1" "G049") ("1" "G669") ("1" "G049") ("1" "G669")),  and show in the command line. I needed it to open a excel sheet and put all the results into one cell. Everyting that i could do was open excel, but i dont know how to pass a variable. Can somebody code it for me or give some tips?

 

(defun c:PROPRIEDADES ( / aDoc Mle MleD atrbvalues Allattrbvalues)
(defun _GetAtrID (ent / a lst)
(vlax-for itm ent
(if (eq (vla-get-Objectname itm) "AcDbAttributeDefinition")
(setq lst (cons (vla-get-ObjectID itm) lst)))
lst
)
)
(setq Allattrbvalues nil
aDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
(if (setq ss (ssget '((0 . "MULTILEADER"))))
(repeat (setq i (sslength ss))
(and (= (vla-get-ContentType
(setq Mle (vlax-ename->vla-object (ssname ss (setq i (1- i)))))) 1)
(setq MleD (vla-item (vla-get-blocks Adoc) (vla-get-ContentBlockName Mle)))
(setq atrbID (_GetAtrID MleD))
(setq atrbvalues (mapcar '(lambda (v)
(vla-GetBlockAttributeValue Mle v)) atrbID))
(setq Allattrbvalues (cons atrbvalues Allattrbvalues))
)
)
)
Allattrbvalues
)

0 Likes
512 Views
4 Replies
Replies (4)
Message 2 of 5

john.uhden
Mentor
Mentor

@athuasc

I'm sure there are many examples here of putting AutoCAD values into Excel.  I have a few of my own if you can't find any by searching here.  But I'm having trouble with why you would want to put multiple values into one cell.  Is it a list of strings, or reals, or integers?  How would you use them later, in Excel or otherwise?

John F. Uhden

Message 3 of 5

Sea-Haven
Mentor
Mentor

Look for getexcel.lsp a great palce to start has GET & PUT cell functions, like John I adapted off getexcel.lsp

 

(defun ahputcell (cellname val1 / )
(setq myRange (vlax-get-property  (vlax-get-property myxl "ActiveSheet") "Range" cellname))
(vlax-put-property myRange 'Value2 val1)
)
(ahputcell "E7" x)
Message 4 of 5

athuasc
Explorer
Explorer

@john.uhden 
I have done a macro in excel that organizes the content in a cell into two collums and various lines (this is the easy part, the thing that i consider the most important is getting this values to excel).
I was able to open a spreadsheet and print text into it, but i couldn't pass my variable AllAttrbvalue into cells.
It is attatched the lisp of reading MLEADER in autocad, my DWG example and my excel macro that organizes the first cell.
 Thank you for helping ! 

 

0 Likes
Message 5 of 5

Sea-Haven
Mentor
Mentor

So you want the list in excel to become like A1 A2 A3 that is why I coded  ahputcell, you need also the extra code to convert row column style answer 1 1 to "A1", 3 3 to "C3" look for the Gile code in getexcel if required.

 

Now its easy use foreach the 1st value is take (car is cell A1 (cadr is B1 the next in list is A2 B2, A3 B3 and so on. Have a go if you get stuck post. 

Hint

 

(ahputcell (strcat "A" (rtos x 2 0))  (car val))
(ahputcell (strcat "B" (rtos x 2 0))  (cadr val))
(setq x (1+ x))

 

 

Also  you can check is excel already open

 

 

 

(defun ahchkexcel (filename  /  )
(if (= (setq myxl (vlax-get-object "Excel.Application") ) nil)
(setq myxl (vlax-get-or-create-object "excel.Application"))
)

 

 

  

0 Likes