Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
Distinguished Contributor
TherealJD
Posts: 416
Registered: ‎10-03-2008
Message 1 of 6 (6,608 Views)

Convert Text to table

6608 Views, 5 Replies
11-19-2009 07:28 AM
I'm trying to convert an old text table to an acad table so i can easily export it out to excel.

I found a cool lisp routine to do exactly that on the cadalyst site. However, the lisp routine is giving me an error.

"MAKETABLE Error: ActiveX Server returned an error: Parameter not optional"

I've attached the lisp routine for reference.

Anyone know what to do, to fix this? I've tried in civil 3d 2009, and autocad 2008. Both give the same error.
Contributor
kylemorin1912
Posts: 12
Registered: ‎03-30-2010
Message 2 of 6 (6,503 Views)

Re: Convert Text to table

11-05-2010 02:06 PM in reply to: TherealJD

I know this post is years old, but that LISP routine was EXACTLY what I needed to complete a project I am working on. I have a bunch of drawings that have exploded tables (only single text entities and lines) representing a table, but I need to export them to a .csv file and manipulate there...this worked perfectly.

Distinguished Contributor
kozmos
Posts: 143
Registered: ‎12-04-2003
Message 3 of 6 (6,484 Views)

Re: Convert Text to table

11-06-2010 05:45 AM in reply to: kylemorin1912

The error comes from the function populate-table.

Only if the 1st string content is "DESCRIPTION" can u have the definition of colleft.

so if the colleft is not defined, you will stop while running (vla-SetCellAlignment tobj (setq j (1+ j)) colleft acMiddleLeft)

[code]

(defun populate-table (tobj tlist rowlines collines)
  (setq i    (- 1)
 data (car tlist)
  ) ;_ end of setq  
  (repeat (/ (length data) 4)
    (setq txtstr    (car data)
   inspt     (vlax-safearray->list (cadr data))
   textstyle (caddr data)
   txtht     (cadddr data)
   rowcol    (get-rowcol inspt rowlines collines)
   row     (car rowcol)
   col     (cadr rowcol)
   rowheight (caddr rowcol)
   colwidth  (cadddr rowcol)
    ) ;_ end of setq
    (if (= txtstr "DESCRIPTION")
      (setq colleft col)
    ) ;_ end of if
    (if (= row 0)
      (progn
 (if (< col 5)
   (progn
     (vla-SetText tobj 0 0 txtstr)
     (vla-SetCellTextStyle tobj 0 0 textstyle)
     (vla-SetCellTextHeight tobj 0 0 txtht)
   ) ;_ end of progn
   (progn
     (if (> (length collines) 7)
       (progn
  (vla-SetText tobj 0 6 "CALCULATED CABLE DISTANCE")
  (vla-SetCellTextStyle tobj 0 6 textstyle)
  (vla-SetCellTextHeight tobj 0 6 txtht)
       ) ;_ end of progn
     ) ;_ end of if
   ) ;_ end of progn
 ) ;_ end of if
      ) ;_ end of progn
      (progn
 (vla-SetText tobj row col txtstr)
      ) ;_ end of progn
    ) ;_ end of if
   
    (vla-SetCellTextHeight tobj row col txtht)
    (vla-SetColumnWidth tobj col colwidth)
    (vla-SetRowHeight tobj row rowheight)
    (vla-SetCellTextStyle tobj row col textstyle)
    (repeat 4
      (setq data (cdr data))
    ) ;_ end of repeat
  ) ;_ end of repeat
 
  (setq j 1)
  (repeat (- (length rowlines) 3)    
      (vla-SetCellAlignment tobj (setq j (1+ j)) colleft acMiddleLeft)
  ) ;_ end of repeat
) ;_ end of populate-table

[/code]

Valued Contributor
N_nmulder
Posts: 56
Registered: ‎12-27-2007
Message 4 of 6 (6,284 Views)

Re: Convert Text to table

01-13-2011 06:42 AM in reply to: TherealJD

So what would be the solution? I am getting the same error. I am not a LISP expert, but looking through the code, it would seem that "DESCRIPTION" and "CALCULATED CABLE DISTANCE" are both required in order for the routine to work.

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 5 of 6 (6,272 Views)

Re: Convert Text to table

01-13-2011 11:26 AM in reply to: TherealJD

Try this one for plain text table (wwould not working with mtext though)

;; Import the multi column plain text	;;
;; into newly created Excel file	;;
;; written by Fatty (c) 2007 * all rights released	;;
;; edited 8/20/08
(defun rem-dups	(mylist / newlst)
  ;; remove duplicates
  ;; published by hutch
  (foreach item	mylist
    (and (null (member item newlst))
	 (setq newlst (cons item newlst))
    )
  )
  newlst
)

(defun get-contents (/ data en i ip output p1 p2 rowlist ss tmp txt ylist)
  (setq data nil);debug only
  (alert "Select text by window selection\n\twithout title")
  (setq p1 (getpoint "\nSpecify the first corner point around the text ")
	p2 (getcorner p1 "\nSpecify the opposite corner point of window ")
	)
  (setq	ss (ssget "W" p1 p2 (list (cons 0 "TEXT")))
	i  -1
  )
  (repeat (sslength ss)
    (setq en   (ssname ss (setq i (1+ i)))
	  ip   (cdr (assoc 10 (entget en)))
	  txt  (cdr (assoc 1 (entget en)))
	  tmp  (cons txt ip)
	  data (cons tmp data)
    )
  )

  (setq	ylist (mapcar 'caddr data)
	ylist (rem-dups ylist)
	ylist (vl-sort ylist (function (lambda (a b) (> a b))))
  )
  (repeat (length ylist)
    (setq rowlist (vl-remove-if-not
		    (function (lambda (x)
				(equal (caddr x) (car ylist) 0.01)
			      )
		    )
		    data
		  )
	  rowlist (vl-sort rowlist
			   (function (lambda (a b) (< (cadr a) (cadr b))))
		  )
    )
    (setq output (append output (list rowlist)))
    (setq ylist (cdr ylist))
  )

  (setq	output (mapcar (function (lambda (x)
				   (mapcar 'car x)
				 )
		       )
		       output
	       )
  )
  output
)

;;	***	main part	***	;;

(defun C:ETT (/	      adoc    aexc    awb     axss    cll     col
	      colm    csht    rowdata excel_list      nwb     osm
	      rang    row     sht
	     )

  (vl-load-com)

  (setq excel_list (get-contents))
  (setq fname (getstring T "\nEnter an Excel file name without XLS extension: "))
  (setq	aexc (vlax-get-or-create-object "Excel.Application")
	awb  (vlax-get-property aexc "Workbooks")
	nwb  (vlax-invoke-method awb "Add")
	sht  (vlax-get-property nwb "Sheets")
	csht (vlax-get-property sht "Item" 1)
	cll  (vlax-get-property csht "Cells")
  )
  (vlax-put-property csht 'Name "Table")
  (vla-put-visible aexc :vlax-false)

  (setq	n   1
	num (length (car excel_list))
  )
  (repeat num
    (setq row 1
	  colm n
    )
    (setq rowdata (mapcar 'car excel_list))
    (repeat (length rowdata)
      (vlax-put-property
	cll
	"Item"
	row
	colm
	(vl-princ-to-string (car rowdata))
      )
      (setq row (1+ row))
      (setq rowdata (cdr rowdata))
    )
    (setq excel_list (mapcar 'cdr excel_list))
    (setq row (1+ row)
	  n   (1+ n)
    )
  )

  (setq rang (vlax-get-property csht "UsedRange"))

  ;; Horizontal alignment Left(Indent) :
  (vlax-put-property
    rang
    "Horizontalalignment"
    (vlax-make-variant -4131 3)
  )
  ;; Vertical alignment Center :
  (vlax-put-property
    rang
    "VerticalAlignment"
    (vlax-make-variant -4108 3)
  )
  ;; Set text format :
  (vlax-put-property
    rang
    "NumberFormat"
    (vlax-make-variant "@" 8); <-- text format (use "0,000" for number format)
  )

  (vlax-invoke-method (vlax-get-property csht "Columns") "AutoFit")
  
  (vlax-invoke-method
    nwb
    'SaveAs
    (strcat (getvar "dwgprefix")
	    fname
    )
    -4143
    nil
    nil
    :vlax-false
    :vlax-false
    1
    2
  )
  (vlax-invoke-method aexc "Quit")

  (mapcar (function (lambda (x)
		      (vl-catch-all-apply
			(function (lambda ()
				    (progn
				      (vlax-release-object x)
				      (setq x nil)
				    )
				  )
			)
		      )
		    )
	  )
	  (list cll csht rang sht nwb awb aexc)
  )
  (gc)
  (princ)
)
;; TesT :
;;(C:ETT)
(princ "\n\t***	Type ETT to execute...")
(princ)

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Valued Contributor
N_nmulder
Posts: 56
Registered: ‎12-27-2007
Message 6 of 6 (6,243 Views)

Re: Convert Text to table

01-14-2011 07:16 AM in reply to: TherealJD

Thanks for your reply. I was able to find another routine at The Swamp which works great. Check it out.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!