Message 1 of 7
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hope someone can help with the below. Trying to export attributes to multiple csv files from dynamic blocks, I have some blocks that are not being selected and others that are being ignored if they don't have all attributes visible that are in the foreach lines. I need all blocks included in the csv files, with blank cells if that attribute is currently not visible, block to be ignored if none of the attributes in the foreach lines are visible. I have attached a DWG with some dynamic blocks inserted, these block names are not final, there will be more added with different block names. Code below, any help is appreciated.
(Defun c:TripleCSV ( / _comma _Visible data ss i ev dp attb a b c folder opf csvfile)
(setq _comma (lambda (lst)(substr
(apply 'strcat
(mapcar '(lambda (str)
(strcat "," str) ) lst)
) 2
)
)
)
(defun _Visible (l) (Vl-remove-if '(lambda (atv)
(zerop (car atv))) l))
(and
(setq ReferenceNumber (strcase (getstring "\nEnter Reference Number: ")))
(snvalid ReferenceNumber )
(setq data nil
ss (ssget '((0 . "INSERT")(66 . 1))))
(repeat (setq i (sslength ss))
(setq ev (vlax-ename->vla-object (ssname ss (setq i (1- i)))))
(if (and
(setq vp (Vl-some '(lambda (dy)
(if (eq (Vlax-get dy 'PropertyName) "Lookup1")
(Vlax-get dy 'Value)))
(Vlax-invoke ev 'GetDynamicBlockProperties)))
(setq attb (mapcar '(lambda (atb)
(list (vlax-get atb 'Visible )(vla-get-tagstring atb)
(Vla-get-textstring atb)))
(Vlax-invoke ev 'GetAttributes)
)
)
)
(setq data (cons (mapcar 'cdr (_Visible attb)) data ))
)
)
(setq folder (acet-ui-pickdir (Getvar 'dwgprefix)))
(setq data (vl-sort data
'(lambda (n m)
(< (cadr (assoc "ID_TAG" n))
(cadr (assoc "ID_TAG" m))
)
)
)
)
(foreach itm '(("_Devices"
("DEVICE_NUMBER" "DEVICE_TYPE" "PANEL_NUMBER" "PORT_NUMBER" "INPUT_NUMBER" "INPUT_TYPE" "OUTPUT_NUMBER" "OUTPUT_TYPE" ))
("_Inputs"
("DEVICE_NUMBER" "PANEL_NUMBER" "PORT_NUMBER" "INPUT_NUMBER" "INPUT_TYPE" ))
("_Outputs"
("DEVICE_NUMBER" "PANEL_NUMBER" "PORT_NUMBER" "OUTPUT_NUMBER" "OUTPUT_TYPE" ))
("_Panels"
("PANEL_TYPE" "PANEL_NUMBER" ))
)
(setq opf (open (setq csvfile (strcat folder "\\" ReferenceNumber (Car itm) ".csv")) "w"))
(write-line (_comma (setq taglst (Cadr itm))) opf)
(Foreach val data
(if (vl-every '(lambda (j)(assoc j val)) (Cadr itm))
(write-line
(_comma (mapcar '(lambda (v)
(cadr (assoc v val))) taglst)) opf)
)
)
(close opf)
(startapp "explorer" csvfile)
)
)
(princ)
)
Solved! Go to Solution.