lisp to fill table

lisp to fill table

islerahmet06
Contributor Contributor
2,342 Views
2 Replies
Message 1 of 3

lisp to fill table

islerahmet06
Contributor
Contributor

Hello again 🙂

 

I have a dwg to define parts, in dwg there is a description for every parts to define (thickness, lenght quantity) and have a table for all parts,

 

for example my first part  has 2mm thickness, 1000mm length, 2000mm width

i write it as (L2x1000...……..2000) and i write samething to table, and also quantities...

 

When i finish my part and define it, i must write everything at table, is there any easy way to do this?

Thanks for your time.

 

 

0 Likes
2,343 Views
2 Replies
Replies (2)
Message 2 of 3

jamieq
Collaborator
Collaborator

Do you need code to get all the parts and add them to a list with quantities? 

Assuming you already have that, and your list is in the format:

 

(list
'("\(L2x1000...……..2000\)" "20")
'("\(L3x1100...……..2100\)" "40")
)

 

You can use this create and fill a table. I've put variable values in square brackets. 

(setq *ms* (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))
(setq myTable (vla-AddTable *ms* (vlax-3d-point pt) (+ 2 (length lst)) 2 24 120)) ; makes a table with as many rows as length lst plus two for the title and headers, 2 columns, row height 24 and cell width 120
(vla-setcelltextheight myTable 0 0 18) ; title text height 18, to stand out
(setq y 1)
(repeat (1+ (length lst)) 
	(setq x 0)
	(repeat 2 ; adjust for number of columns
		(vla-setcelltextheight myTable x y 12) ; cell text height 12
		(vla-setCellAlignment myTable x y 5) ; cell alignment middle center
		(setq x (1+ x))
	)
	(setq y (1+ y))
)
(vla-setText mytable 0 0 "Parts") ; fill in title
(vla-setText mytable 1 0 "Description") ; fill in header
(vla-setText mytable 1 1 "Quantity") ; fill in header
(setq row 2)
(foreach item lst
	(vla-setText mytable row 0 (car item)) ; fill in description
	(vla-setText mytable row 1 (last item)) ; fill in quantity
	(setq row (1+ row))
)
(vlax-release-object myTable)      
(vlax-release-object *ms*)    

This is modified slightly from some code I use myself. It also assumes units are inches, which I mention since you put mm in your descriptions. You'll need to adjust for different units settings. 

Message 3 of 3

jamieq
Collaborator
Collaborator

Only just realized I didn't put variables in square brackets. Please disregard that. 

0 Likes