MarkS1 Posted January 25, 2021 Posted January 25, 2021 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 1 Quote
pBe Posted January 28, 2021 Posted January 28, 2021 Multiple csv files from attributes <--- (Defun c:TripleCSV ( / _comma data ss i folder opf csvfile) ;; pBe Nov 2020 ;;; <-- I could have sworn... (setq _comma (lambda (lst)(substr... Quote
MarkS1 Posted February 1, 2021 Author Posted February 1, 2021 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. Quote
Recommended Posts
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.