Jump to content

Table export lisp from Paperspace - Debug


Mihail

Recommended Posts

Hi All,

 

I just need a bit of help with debugging and improving of below lisp. The idea is simple. I have a table in paperspace in one of the drawings and I want to export it through a lisp in order to put it in a more complex automated process. Yesterday it was working fine but today the code failed and it exported from both modelspace and layout. Beside this after a purge I got the error message even if the table was there and I could export it with the default EXPORTTABLE command.

Also, If anyone has a bit of time to help me with improving a bit the path. I have a revision block with attributes. One of them has revision no value. The block name is constant on all the projects being automated so it can be selected by name. Is there any way to get that attribute value of the revision and use it in the path where REV 0 is. If the attribute is 1 the path to be REV 1. I tried some codes from Lee but I could not make them work.

I did not note the source of the code so I cant remember who did it to mention here 😢. Sorry for that

 

Thank you!

 

(defun c:DTR0 ( / ss fName f cnt e tbl r c cR cC tmp txt)
;CustomTableExport
(command "-purge" "all" "" "n")	
(if (not (setq ss (ssget "_X" '((0 . "ACAD_TABLE")(410 . "Layout*")))))
  (progn (alert "No Tables Found") (exit))
);if
(setq fName (strcat (getvar "dwgprefix")"\\Preliminary\\Rev 0\\Datum Setout.csv"))
(if (setq f (open fName "a"))
  (progn
    (repeat (setq cnt (sslength ss))
      (setq e (ssname ss (setq cnt (1- cnt))))
      ;(write-line (strcat (getvar 'DWGNAME) " - Table " (itoa (1+ cnt))) f)
      (setq tbl (vlax-ename->vla-object e))
      (setq r (vla-get-rows tbl) c (vla-get-columns tbl))
      (setq cR 0)
      (repeat r
	(setq cC 0 txt "")
	(repeat c
	  (setq tmp (vlax-variant-value (vlax-variant-change-type (vla-getcellvalue tbl cR cC) 8)))
	  (if (= (1- c) cC)
	    (progn (setq txt (strcat txt (if tmp tmp ""))) (write-line txt f))
	    (setq txt (strcat txt (if tmp tmp "") ","))
	  );if
	  (setq cC (1+ cC))
	);repeat c
	(setq cR (1+ cR))
      );repeat r
    );repeat cnt
    (close f)
  );progn
);if
(prompt "\nCTE Complete..")
(princ)
);defun

 

SAMPLE FILE.dwg

Edited by Mihail
SAMPLE FILE ADDED
Link to comment
Share on other sites

here is a start , can't do more right now because wife suddenly wants to go shopping...

 

(defun c:DTR0 ( / ss fName f cnt e tbl r c cR cC tmp txt)
  (vl-load-com)
  ;CustomTableExport
  (command "-purge" "all" "" "n")	
  (if (not (setq ss (ssget "_X" '((0 . "ACAD_TABLE")(410 . "Layout*")))))
    (progn (alert "No Tables Found") (exit))
  );if
  (setq fName (strcat (getvar "dwgprefix")"\\Preliminary\\Rev 0\\Datum Setout.csv"))
  (rlx_mf (vl-filename-directory fName))
  
  (if (setq f (open fName "a"))
    (progn
      (repeat (setq cnt (sslength ss))
        (setq e (ssname ss (setq cnt (1- cnt))))
        ;(write-line (strcat (getvar 'DWGNAME) " - Table " (itoa (1+ cnt))) f)
        (setq tbl (vlax-ename->vla-object e))
        (setq r (vla-get-rows tbl) c (vla-get-columns tbl))
        (setq cR 0)
        (repeat r
          (setq cC 0 txt "")
	  (repeat c
	    (setq tmp (vlax-variant-value (vlax-variant-change-type (vla-getcellvalue tbl cR cC) 8)))
	    (if (= (1- c) cC)
	      ;;; (progn (setq txt (strcat txt (if tmp tmp ""))) (write-line txt f))
              (progn (setq txt (LM:UnFormat (strcat txt (if tmp tmp "")) nil)) (write-line txt f))
	      (setq txt (strcat txt (if tmp tmp "") ","))
	    );if
	    (setq cC (1+ cC))
	  );repeat c
	  (setq cR (1+ cR))
        );repeat r
    );repeat cnt
    (close f)
    );progn
    (princ "\ncsv file not created")
  );if
  (prompt "\nCTE Complete..")
  (princ)
);defun


;;; rlx_mf - make folder, returns T of nil
(defun rlx_mf ( fol / sf)
  (defun MF (rt sf) (if sf ((lambda (fol)(vl-mkdir fol)(MF fol (cdr sf)))(strcat rt "\\" (car sf)))))
  (if (setq sf (rlx_sf (vl-string-translate "/" "\\" fol))) (MF (car sf) (cdr sf))) (vl-file-directory-p fol))

;;--------------------------------------------------------=={ UnFormat String }==--------------------------------------------------------;;
;;  Returns a string with all MText formatting codes removed - Author: Lee Mac, Copyright © 2011 - www.lee-mac.com                       ;;
;;---------------------------------------------------------------------------------------------------------------------------------------;;
;;  Arguments: str - String to Process, mtx - MText Flag (T if string is for use in MText) Returns: String with formatting codes removed ;;
;;---------------------------------------------------------------------------------------------------------------------------------------;;

(defun LM:UnFormat ( str mtx / _replace rx sx)
  (defun _replace ( new old str )(vlax-put-property rx 'pattern old)(vlax-invoke rx 'replace str new))
  (setq sx '(("\032" "\\\\\\\\") (" " "\\\\P|\\n|\\t")
	     ("$1" "\\\\(\\\\[ACcFfHLlOopQTW])|\\\\[ACcFfHLlOopQTW][^\\\\;]*;|\\\\[ACcFfHLlOopQTW]")
	     ("$1$2/$3" "([^\\\\])\\\\S([^;]*)[/#\\^]([^;]*);")("$1$2" "\\\\(\\\\S)|[\\\\](})|}")("$1" "[\\\\]({)|{")))
  (if (setq rx (vlax-get-or-create-object "VBScript.RegExp"))
    (progn (setq str (vl-catch-all-apply (function (lambda ()(vlax-put-property rx 'global actrue)(vlax-put-property rx 'multiline actrue)
       (vlax-put-property rx 'ignorecase acfalse) (foreach pair sx (setq str (_replace (car pair) (cadr pair) str)))
         (if mtx (_replace "\\\\" "\032" (_replace "\\$1$2$3" "(\\\\[ACcFfHLlOoPpQSTW])|({)|(})" str)) (_replace "\\" "\032" str))))))
            (vlax-release-object rx)(if (null (vl-catch-all-error-p str)) str))))

 

Link to comment
Share on other sites

If its getting a table from "Model" space then its ignoring this (410 . "Layout*")

Maybe use this, limited testing. Returned correct number.

 

(if (not (setq ss (ssget "_X" (list (cons 0 "ACAD_TABLE")(cons 410 "Layout*")))))

 

  • Like 1
Link to comment
Share on other sites

Like rlx loop through all the layouts ignore the one called "Model" then get the table/s and use ssadd to make final selection set.

 

Mihail post again if want code for "any layout".

 

 

Edited by BIGAL
  • Like 1
Link to comment
Share on other sites

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...