Message 1 of 10
Attribute to CSV
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi guys,
I am trying to extract more attributes from the "node" block.
Node block has a couple other variables that I would like to display in the same fashion.
Right now is only working with Serv_Name, I also need 5 more, if blank then just writes "TBD" on the csv.
How can I achieve this? I am not good when it comes to VLA.
Credits to pEb from the CadTutor forum for most of the code.
(defun c:ConnectedTo ( / _First&Second AttbList PlineList PB&PlineList ss ent i typ _rtos _carcadr fn fl ) ;credits to pBe from Cadtutor.net
(vl-load-com)
(defun _First&Second (lst alst / a b c d)
(repeat 2
(setq a (car lst) lst (cdr lst))
(setq c (cadar (vl-sort
(mapcar '(lambda (k)
(list (distance a (cadr k))
k)) alst)
(function (lambda (p1 p2)
(< (car p1) (car p2)))))))
(setq d (cons (car c) d))
)
)
(if (setq AttbList nil PlineList nil PB&PlineList nil
ss (ssget "_X"
'((-4 . "<OR") (-4 . "<AND")
(0 . "INSERT") (2 . "NODE")
(-4 . "AND>") (-4 . "<AND")
(0 . "LWPOLYLINE")(8 . "RA*")
(-4 . "AND>")
(-4 . "OR>")
)
))
(progn
(repeat (setq i (sslength ss))
(setq ent (ssname ss (setq i (1- i))))
(cond
((eq (setq typ (cdr (assoc 0 (entget ent))))
"INSERT")
(if (setq attval (car (vl-remove-if-not
'(lambda (j) (eq (vla-get-tagstring j) "Serv_Name"))
(vlax-invoke (vlax-ename->vla-object ent)
'Getattributes))))
(setq AttbList
(cons (list (vla-get-textstring attval)
(cdr (assoc 10 (entget ent))))
AttbList))))
((and (eq typ "LWPOLYLINE")
(> (distance (vlax-curve-getStartPoint ent)(vlax-curve-getEndPoint ent)) 0.1))
(setq PlineList
(cons (list (vlax-curve-getStartPoint ent)
(vlax-curve-getEndPoint ent)
(vlax-curve-getDistAtParam ent
(vlax-curve-getEndParam ent)))
PlineList))
)
)
)
(foreach itm PlineList
(setq PB&PlineList
(cons (list (_First&Second itm AttbList)
(car itm)
(cadr itm)
(last itm))
PB&PlineList))
)
)
)
(princ)
(setq _rtos (lambda (q) (rtos q 2 16)))
(setq _carcadr (lambda (x) (list (car x) (cadr x))))
(if (= (getvar 'Dwgtitled) 1)
(progn
(setq fl (strcat (getvar 'Dwgprefix)
(cadr (fnsplitl (getvar 'Dwgname)))
".csv"))
(setq fn (open fl "w"))
(foreach pline (vl-sort PB&PlineList '(lambda (s1 s2) (< (last s1) (last s2))))
(setq line (strcat (caar pline)
","
(_rtos (last pline))
","
(if (eq (caar pline) (cadar pline)) "" (cadar pline))))
(write-line line fn)
)
(close fn)
(startapp (strcat "explorer /select, "fl", /e"))
)
)
(princ "ConnectedTo function executed successfully.")
)