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

Insert Field in a Table

4 REPLIES 4
Reply
Message 1 of 5
varcii
400 Views, 4 Replies

Insert Field in a Table

I'm currently trying to write a LISP programme to insert a table with various bits of data (number of objects, total length of objects) variables from programme. While this programme works out this data, some of it may need altering later ie the number of objects, therefore if total length of objects is a field formula "=c2*length" where length is a real number and c2 is the cell ref. Currently I am getting a single quotation mark forcing it to be text not a formula.

Code attached.

( entmake ( list
(cons 0 "ACAD_TABLE")
(cons 100 "AcDbEntity")
(cons 8 "Dim")
(cons 100 "AcDbBlockReference")
(cons 10 ( list 1545.07 -124.979 0.0))
(cons 41 1.0)
(cons 42 1.0)
(cons 43 1.0)
(cons 71 0)
(cons 44 0.0)
(cons 45 0.0)
(cons 100 "AcDbTable")
(cons 11 ( list 1.0 0.0 0.0))
(cons 90 54)
(cons 91 2)
(cons 92 5)
(cons 93 24)
(cons 94 0)
(cons 95 0)
(cons 96 0)
(cons 40 1.0)
(cons 41 1.0)
(cons 141 8.0)
(cons 141 8.0)
(cons 141 8.0)
(cons 142 35.0)
(cons 142 30.0)
(cons 142 40.0)
(cons 142 40.0)
(cons 142 45.0)
(cons 171 1)
(cons 175 1)
(cons 176 1)

(cons 91 0)
(cons 178 0)
(cons 145 0.0)
(cons 92 0)
(cons 301 "CELL_VALUE")
(cons 93 7)
(cons 90 512)
(cons 94 0)
(cons 171 1)
(cons 175 1)
(cons 176 1)
(cons 91 0)
(cons 178 0)
(cons 145 0.0)
(cons 92 0)
(cons 301 "CELL_VALUE")
(cons 93 6)
(cons 90 4)
(cons 1 "Mark No.")
(cons 94 0)
(cons 171 1)
(cons 175 1)
(cons 176 1)
(cons 91 0)
(cons 178 0)
(cons 145 0.0)
(cons 92 0)
(cons 301 "CELL_VALUE")
(cons 93 6)
(cons 90 4)
(cons 1 "No. Required")
(cons 94 0)
(cons 171 1)
(cons 175 1)
(cons 176 1)
(cons 91 0)
(cons 178 0)
(cons 145 0.0)
(cons 92 0)
(cons 301 "CELL_VALUE")
(cons 93 6)
(cons 90 4)
(cons 1 "Hole Centres")
(cons 94 0)
(cons 171 1)
(cons 175 1)
(cons 176 1)
(cons 91 0)
(cons 178 0)
(cons 145 0.0)
(cons 92 0)
(cons 301 "CELL_VALUE")
(cons 93 6)
(cons 90 4)
(cons 1 "Total Metres")
(cons 94 0)
(cons 171 1)
(cons 175 1)
(cons 176 1)
(cons 91 0)
(cons 178 0)
(cons 145 0.0)
(cons 92 0)
(cons 301 "CELL_VALUE")
(cons 93 6)
(cons 90 4)
(cons 1 "As Shown")
(cons 94 0)
(cons 171 1)
(cons 175 1)
(cons 176 1)
(cons 91 0)
(cons 178 0)
(cons 145 0.0)
(cons 92 0)
(cons 301 "CELL_VALUE")
(cons 93 6)
(cons 90 4)
(cons 1 "E1")
(cons 94 0)
(cons 171 1)
(cons 175 1)
(cons 176 1)
(cons 91 0)
(cons 178 0)
(cons 145 0.0)
(cons 92 0)
(cons 301 "CELL_VALUE")
(cons 93 6)
(cons 90 4)
(cons 1 "4")
(cons 94 0)
(cons 171 1)
(cons 175 1)
(cons 176 1)
(cons 91 0)
(cons 178 0)
(cons 145 0.0)
(cons 92 0)
(cons 301 "CELL_VALUE")
(cons 93 6)
(cons 90 4)
(cons 1 "70")
(cons 94 0)
(cons 171 1)
(cons 175 1)
(cons 176 1)
(cons 91 0)
(cons 178 0)
(cons 145 0.0)
(cons 92 0)
(cons 301 "CELL_VALUE")
(cons 93 6)
(cons 90 4)
(cons 1 "=c2*6")
(cons 94 0)
(cons 171 1)
(cons 175 1)
(cons 176 1)
)
)
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: varcii

I just test your code,my computer hang !!!.

wrote in message news:5371901@discussion.autodesk.com...
I'm currently trying to write a LISP programme to insert a table with
various bits of data (number of objects, total length of objects) variables
from programme. While this programme works out this data, some of it may
need altering later ie the number of objects, therefore if total length of
objects is a field formula "=c2*length" where length is a real number and c2
is the cell ref. Currently I am getting a single quotation mark forcing it
to be text not a formula.

Code attached.

( entmake ( list
(cons 0 "ACAD_TABLE")
(cons 100 "AcDbEntity")
(cons 8 "Dim")
(cons 100 "AcDbBlockReference")
(cons 10 ( list 1545.07 -124.979 0.0))
(cons 41 1.0)
(cons 42 1.0)
(cons 43 1.0)
(cons 71 0)
(cons 44 0.0)
(cons 45 0.0)
(cons 100 "AcDbTable")
(cons 11 ( list 1.0 0.0 0.0))
(cons 90 54)
(cons 91 2)
(cons 92 5)
(cons 93 24)
(cons 94 0)
(cons 95 0)
(cons 96 0)
(cons 40 1.0)
(cons 41 1.0)
(cons 141 8.0)
(cons 141 8.0)
(cons 141 8.0)
(cons 142 35.0)
(cons 142 30.0)
(cons 142 40.0)
(cons 142 40.0)
(cons 142 45.0)
(cons 171 1)
(cons 175 1)
(cons 176 1)

(cons 91 0)
(cons 178 0)
(cons 145 0.0)
(cons 92 0)
(cons 301 "CELL_VALUE")
(cons 93 7)
(cons 90 512)
(cons 94 0)
(cons 171 1)
(cons 175 1)
(cons 176 1)
(cons 91 0)
(cons 178 0)
(cons 145 0.0)
(cons 92 0)
(cons 301 "CELL_VALUE")
(cons 93 6)
(cons 90 4)
(cons 1 "Mark No.")
(cons 94 0)
(cons 171 1)
(cons 175 1)
(cons 176 1)
(cons 91 0)
(cons 178 0)
(cons 145 0.0)
(cons 92 0)
(cons 301 "CELL_VALUE")
(cons 93 6)
(cons 90 4)
(cons 1 "No. Required")
(cons 94 0)
(cons 171 1)
(cons 175 1)
(cons 176 1)
(cons 91 0)
(cons 178 0)
(cons 145 0.0)
(cons 92 0)
(cons 301 "CELL_VALUE")
(cons 93 6)
(cons 90 4)
(cons 1 "Hole Centres")
(cons 94 0)
(cons 171 1)
(cons 175 1)
(cons 176 1)
(cons 91 0)
(cons 178 0)
(cons 145 0.0)
(cons 92 0)
(cons 301 "CELL_VALUE")
(cons 93 6)
(cons 90 4)
(cons 1 "Total Metres")
(cons 94 0)
(cons 171 1)
(cons 175 1)
(cons 176 1)
(cons 91 0)
(cons 178 0)
(cons 145 0.0)
(cons 92 0)
(cons 301 "CELL_VALUE")
(cons 93 6)
(cons 90 4)
(cons 1 "As Shown")
(cons 94 0)
(cons 171 1)
(cons 175 1)
(cons 176 1)
(cons 91 0)
(cons 178 0)
(cons 145 0.0)
(cons 92 0)
(cons 301 "CELL_VALUE")
(cons 93 6)
(cons 90 4)
(cons 1 "E1")
(cons 94 0)
(cons 171 1)
(cons 175 1)
(cons 176 1)
(cons 91 0)
(cons 178 0)
(cons 145 0.0)
(cons 92 0)
(cons 301 "CELL_VALUE")
(cons 93 6)
(cons 90 4)
(cons 1 "4")
(cons 94 0)
(cons 171 1)
(cons 175 1)
(cons 176 1)
(cons 91 0)
(cons 178 0)
(cons 145 0.0)
(cons 92 0)
(cons 301 "CELL_VALUE")
(cons 93 6)
(cons 90 4)
(cons 1 "70")
(cons 94 0)
(cons 171 1)
(cons 175 1)
(cons 176 1)
(cons 91 0)
(cons 178 0)
(cons 145 0.0)
(cons 92 0)
(cons 301 "CELL_VALUE")
(cons 93 6)
(cons 90 4)
(cons 1 "=c2*6")
(cons 94 0)
(cons 171 1)
(cons 175 1)
(cons 176 1)
)
)
Message 3 of 5
Anonymous
in reply to: varcii

Better yet let you attach sample drawing
with tour table
maybe I could to help but with using ActiveX method
Or search this forum an example how to create table
(written by Tony Tanzillo)

~'J'~
Message 4 of 5
varcii
in reply to: varcii

solved the problem i was having with vla-settext method

i found this post useful as a starting point http://discussion.autodesk.com/thread.jspa?messageID=5363129

code

(defun purlin_table2 ( / objTable ent span mark qty ctr)
; table already exists in drawing
(setq ent (car (entsel))
objTable (vlax-ename->vla-object ent)
span (getreal "\nLength of Purlin Required:")
mark "m1"
qty (getint "\nNumber of Purlin Required:")
ctr "70")

(vla-setcelltextstyle objtable 1 1 "Technic")
(vla-setcelltextstyle objtable 1 2 "Technic")
(vla-setcelltextstyle objtable 1 3 "Technic")
(vla-setcelltextstyle objtable 1 4 "Technic")

(vla-setcelltextstyle objtable 2 1 "Technic")
(vla-setcelltextstyle objtable 2 2 "Technic")
(vla-setcelltextstyle objtable 2 3 "Technic")
(vla-setcelltextstyle objtable 2 4 "Technic")
(vla-settext objTable 1 1 mark)
(vla-settext objTable 1 2 qty)
(vla-settext objTable 1 3 ctr)
(vla-settext objTable 1 4 (strcat "%<\\AcExpr (c2*"(rtos (* span 0.001) 2 3)") \\f \"%zs8\">%"))
(if (= opposite 1)
(progn
(vla-settext objTable 2 1 (strcat mark "a"))
(vla-settext objTable 2 2 qty)
(vla-settext objTable 2 3 ctr)
(vla-settext objTable 2 4 (strcat "%<\\AcExpr (c3*"(rtos (* span 0.001) 2 3)") \\f \"%zs8\">%"))
)
)
)

cheers all 🙂
Message 5 of 5
Anonymous
in reply to: varcii

Hovewer, you can try this also:
Change to your suit

~'J'~
;=============code begin
(defun test()
(setq rows 12
cols 5
hh 0.45333
hr 0.36
cw 1.575
span 1200.0
subhdr '("Sub1" "Sub2" "Sub3" "Sub4" "Sub5"))

; make body list

(setq lst (list
'(0 . "ACAD_TABLE")
'(100 . "AcDbEntity")
'(67 . 0)
'(410 . "Model")
'(8 . "0")
'(100 . "AcDbBlockReference")
'(10 0.0 0.0 0.0) ;_ Insertion point
'(41 . 1.0) ;_ Vertical cell margin
'(42 . 1.0)
'(43 . 1.0)
'(50 . 0.0)
'(70 . 0)
'(71 . 0)
'(44 . 0.0)
'(45 . 0.0)
'(210 0.0 0.0 1.0)
'(100 . "AcDbTable")
'(11 1.0 0.0 0.0) ;_ Horizontal direction vector
'(90 . 22) ;_ Flag for table value (unsigned integer)
(cons 91 (+ rows 2)) ;_ Number of rows include header and subheader rows
(cons 92 cols) ;_ Number of columns
'(93 . 0) ;_ Flag for an override
'(94 . 0) ;_ Flag for an override of border color
'(95 . 0) ;_ Flag for an override of border lineweight
'(96 . 0) ;_ Flag for an override of border visibility
) ;_ list
)

(setq lst (append lst (list (cons 141 hh))))
(repeat (1+ rows)
(setq lst (append lst (list (cons 141 hr)))))
(repeat cols (setq lst (append lst (list (cons 142 cw)))))

; make header

(setq lst (append lst
(list
'(171 . 1)
'(172 . 0)
'(173 . 0)
'(174 . 0)
'(175 . 5)
'(176 . 1)
'(177 . 0)
'(178 . 0)
'(145 . 0.0)
'(1 . "Header")
)))

; make merged cells in header row

(repeat (1- cols)
(setq lst (append lst
(list
'(171 . 1)
'(172 . 0)
'(173 . 1)
'(174 . 0)
'(175 . 1)
'(176 . 1)
'(177 . 0)
'(178 . 0)
'(145 . 0.0)
'(1 . "")
))))

; make subheaders

(repeat cols
(setq lst (append lst
(list
'(171 . 1)
'(172 . 0)
'(173 . 0)
'(174 . 0)
'(175 . 1)
'(176 . 1)
'(177 . 0)
'(178 . 0)
'(145 . 0.0)
(cons 1 (car subhdr))
)))
(setq subhdr (cdr subhdr)))

;; populate table:

(setq row 2 i 0.25)
(repeat rows
(setq row (1+ row) col 0)
(repeat cols
(setq col (1+ col))
(setq txt (rtos i 2 3))
(setq lst (append lst
(list
'(171 . 1)
'(172 . 0)
'(173 . 0)
'(174 . 0)
'(175 . 1)
'(176 . 1)
'(177 . 0)
'(178 . 0)
'(145 . 0.0)
(if (= col 4)(cons 1 (strcat "%<\\AcExpr (c2*"(rtos (* span 0.001) 2 3)") \\f \"%zs8\">%"))

(cons 1 txt))
)))
(setq i (+ i 0.11))))
(entmake lst) (princ))
(test)
;=============code end

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

Post to forums  

Autodesk Design & Make Report

”Boost