I have attached an updated lisp that will need editing.
The lisp can run from modelspace or paperspace, so there is no need to check. I have included them but commented out so you can see how i have structured them within the cond statement.
Below is the top of the attached lisp.
I have included a local error function (just in case). The main purpose of this is to close the open file if an error should occur whilst it is open. This error routine replaces AutoCAD's error routine only for the duration of the lisp.
The red items are the needed parts for the model/paper space checks. The sections in the "cond" statement have been commented out. If you want to remove them, only remove items coloured red.
The orange item is a check to ensure the drawing has been saved. This is to avoid a disconnected drawing csv file pairing. The program will still work if the line is removed.
The indigo line is the check for the block.
Please note that the path variable will need setting to the path where you require the csv file to be saved.
(defun c:EPD ( / *error* c_doc b_nme tag ss path f_name fp val i_pt p_len b_lst)
(defun *error* ( msg )
(if fp (close fp))
(if (and c_doc (= 8 (logand 8 (getvar 'UNDOCTL)))) (vla-endundomark c_doc))
(if (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) (princ (strcat "\nOops an Error : " msg " occurred.")))
(princ)
);end_*error*_defun
(setq c_doc (vla-get-activedocument (vlax-get-acad-object))
c_spc (vla-get-activespace c_doc);Remove this line if you don't want a model/paper space check
b_nme "PILE_BLOCK"
);end_setq
(cond ;( (= acpaperspace c_spc) (alert "Command Unavailable in Paperspace"))
;( (= acmodelspace c_spc) (alert "Command Unavailable in Modelspace"))
( (= (getvar 'dwgtitled) 0) (alert "Drawing not Saved"))
( (not (tblobjname "block" b_nme)) (alert (strcat "Block " b_nme " NOT available in drawing")))
( (and (setq b_lst nil
path (getvar 'dwgprefix);CHANGE THIS TO YOUR REQUIRED PATH TO CSV FILE!!!
I am not one of the robots you're looking for