Visual LISP, AutoLISP and General Customization

Reply
Active Member
varcii
Posts: 6
Registered: ‎10-22-2006
Message 1 of 5 (85 Views)

Insert Field in a Table

85 Views, 4 Replies
10-23-2006 06:44 PM
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)
)
)
*Adesu
Message 2 of 5 (85 Views)

Re: Insert Field in a Table

10-30-2006 12:40 AM 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)
)
)
Distinguished Contributor
Fatty
Posts: 1,986
Registered: ‎08-02-2004
Message 3 of 5 (85 Views)

Re: Insert Field in a Table

10-30-2006 02:49 AM 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'~
Active Member
varcii
Posts: 6
Registered: ‎10-22-2006
Message 4 of 5 (85 Views)

Re: Insert Field in a Table

10-31-2006 03:14 PM 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 :smileyhappy:
Distinguished Contributor
Fatty
Posts: 1,986
Registered: ‎08-02-2004
Message 5 of 5 (85 Views)

Re: Insert Field in a Table

11-01-2006 12:56 AM 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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community