PDA

View Full Version : Export XData


cvorster
2008-07-31, 11:10 AM
Can someone please help me with the following:

I need to export XData of a polyline to an external ascii file. From there I can import it to excel and do some calculations.

Please help!

patrick35
2008-07-31, 12:17 PM
Hi

No easy answer to export xdatas.
The simplest is that you give an example with the data that you wish to extract.

@+

fixo
2008-08-01, 10:39 AM
See how it will work for you


(defun C:WXD (/
appname
col
data
en
header
item_list
obj
result
row
spec_list
ss
xdv
xlapp
xlbook
xlbooks
xlcells
xlsheet
xlsheets) ;write xdata to Excel


;; main part
(setq result nil)
(setq appname (getstring T
"\nEnter the name of extension application (case-nonsensitive): "))
(setq ss (ssget "_X" (list (list -3 (list appname)))))
(while (setq en (ssname ss 0))
(setq obj (vlax-ename->vla-object (ssname ss 0)))
(vla-getXdata
obj
appname
'xtp
'xdv
)

(setq data
(mapcar 'vlax-variant-value
(vlax-safearray->list xdv)
)
)
(setq spec_list (cons (list (cadr data) (caddr data) (cadddr data))
spec_list))
(ssdel en ss))
;; Excel part

(or (vl-load-com))


(alert "Just Close Excel, Nothing Else")
(setq xlApp (vlax-get-or-create-object "Excel.Application")
xlBooks (vlax-get-property xlApp "Workbooks")
xlBook (vlax-invoke-method xlBooks "Add")
xlSheets (vlax-get-property xlBook "Sheets")
xlSheet (vlax-get-property xlSheets "Item" 1)
xlCells (vlax-get-property xlSheet "Cells")
)


(vla-put-visible xlApp :vlax-true)
(setq row 1)
(setq col 1)
(setq header '("Column1" "Column2"));<-- change header names to your suit
(repeat (length header)
(vlax-put-property
xlCells
"Item"
row
col
(vl-princ-to-string (car header))
)
(setq header (cdr header))
(setq col (1+ col))
)
(setq row 2
col 1
)
(repeat (length spec_list)
(setq item_list (car spec_list))

(repeat (length item_list)
(vlax-put-property
xlCells
"Item"
row
col
(vl-princ-to-string (car item_list))
)
(setq item_list (cdr item_list))
(setq col (1+ col))
)
(setq spec_list (cdr spec_list))
(setq col 1
row (1+ row)
)
)

(vlax-invoke-method
xlBook
'SaveAs
(strcat (getvar "dwgprefix")
(vl-string-right-trim ".dwg" (getvar "dwgname"))
)
-4143
nil
nil
:vlax-false
:vlax-false
1
2
)
(vlax-release-object xlCells)
(vlax-release-object xlSheet)
(vlax-release-object xlSheets)
(vlax-release-object xlBook)
(vlax-release-object xlBooks)
(vlax-release-object xlApp)
(setq xlApp nil)
(gc)
(gc)
(princ)
)
(princ "\nStart command with WXD...")
(princ)


~'J'~