Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Convert Text to table

11 REPLIES 11
Reply
Message 1 of 12
TherealJD
29751 Views, 11 Replies

Convert Text to table

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.
11 REPLIES 11
Message 2 of 12
kylemorin1912
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.

Message 3 of 12
kozmos
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]

Message 4 of 12
nmulder34
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.

Message 5 of 12
Hallex
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
Message 6 of 12
nmulder34
in reply to: TherealJD

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

Message 7 of 12
kishordm
in reply to: Hallex

Thank you for Such a nice programed LSP.

Message 8 of 12
shacho
in reply to: nmulder34

would you be able to post the lisp you found on the swamp here.  i cant seem to register.

 

thankyou

Message 9 of 12
mughalzia15
in reply to: TherealJD

THAT IS NOT WORK,

WHAT IS SHORTKEY?

THANKS

 

Message 10 of 12
mughalzia15
in reply to: kishordm

HOW THAT WORK

PLS EXPLAIN ME 

THANKS

 

Message 11 of 12
cadffm
in reply to: mughalzia15

Command APPLOAD

Load the *.lsp file you needs,

Start with the new Command COT

follow further instructions

- Sebastian -
Message 12 of 12
jamil_Zaheer
in reply to: TherealJD

Thanks I had found a similar lisp from bunch of lisp files on freecadtipsandtricks.com but I forgot which one was that. It worked. Thanks again.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost