Author Topic: Export point coordinate and xdata  (Read 824 times)

0 Members and 1 Guest are viewing this topic.

milanp

  • Newt
  • Posts: 35
Export point coordinate and xdata
« on: May 06, 2022, 01:25:26 PM »
Is it possible to export the coordinates of the selected points and the defined xdata (1000 code(point number)) to the same txt file? This would give the "Point Number(from xdata),X, Y, Z"

* Registered Application Name: Milan
* Code 1000, ASCII string: 1  (Point number)

Code: [Select]
(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 "Milan")
(setq ss (ssget (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 (cdr 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 '("Br" "Y" "X" "Z"));<-- 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)

 Thanks  :eat:
« Last Edit: May 07, 2022, 01:23:15 PM by milanp »

BIGAL

  • Swamp Rat
  • Posts: 1398
  • 40 + years of using Autocad
Re: Export point coordinate and xdata
« Reply #1 on: May 07, 2022, 02:59:54 AM »
Look at the if no need to close, I made my own excel.lsp as need to check a few things, is excel open, if not correct file open, just start a new one and so on.

Code: [Select]
(if (= (setq myxl (vlax-get-object "Excel.Application") ) nil)
(setq myxl (vlax-get-or-create-object "excel.Application"))
)
A man who never made a mistake never made anything

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Export point coordinate and xdata
« Reply #2 on: May 09, 2022, 11:36:37 AM »
Look at the if no need to close, I made my own excel.lsp as need to check a few things, is excel open, if not correct file open, just start a new one and so on.

Code: [Select]
(= (setq myxl (vlax-get-object "Excel.Application") ) nil)
No need to check = nil
Code - Auto/Visual Lisp: [Select]
  1. (or (setq myxl (vlax-get-object "Excel.Application"))
  2.     (setq myxl (vlax-get-or-create-object "excel.Application"))
  3. )
  4. (setq myxl (cond ((vlax-get-object "Excel.Application"))
  5.                  ((vlax-get-or-create-object "excel.Application"))
  6.            )
  7. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

BIGAL

  • Swamp Rat
  • Posts: 1398
  • 40 + years of using Autocad
Re: Export point coordinate and xdata
« Reply #3 on: May 09, 2022, 07:24:14 PM »
Thanks will update in my library excel.lsp
A man who never made a mistake never made anything