Jump to content

Multiple CSV files from attributes


MarkS1

Recommended Posts

I'm trying to export attributes to multiple csv files from dynamic blocks, have some code below someone already helped with but just have a slight problem I cannot fix, I have some blocks that are not being selected and others that are being ignored if they don't have all attributes currently 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 only if none of the attributes in the foreach lines are currently 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)
)

 

Blocks.dwg

  • Dislike 1
Link to comment
Share on other sites

Apologies, didn't even remember removing that, I have tried to make a lot of changes to get it working and have gone through many attempts and none worked, I thought the one I posted here was the most recent one that almost worked.

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...