Here is full code;
The code creates table, only thing i want - layout list not to be sorted
; dwg index to a table
; modified 2020 (JW)
(defun CBC:dwgindex2 (/ lentab ss1 ans2 ans3 ans4 ans5 anstab tag2 tag3 tag4 tag5 list1 list2 list3 list4 list5 listtab curlayout INC *PS* I LST MYTABLE PT1 SSET acmcol t_style1 t_style2 rep1 num aobj adoc)
(vl-load-com)
(setq curlayout (getvar "ctab"))
(if (= curlayout "Model")
(progn
(Alert "You need to be in a layout for this option")
(exit)
) ; end progn
) ; end if model
; lisp part1 - get title block attributes, source AH https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/batch-extracting-title-block-info/td...
(setq bname "CBCRMSA3LAYOUT") ; title block name
(setq list0 (layoutlist)) ;JW - create temp list with all layouts
(setq list1 (vl-remove (nth 0 list0) list0)) ;JW - remove cover page from list ((vl-remove (nth x list)) removes x number of items from list, first item starts from 0)
(setq tag2 "SHEET-DETAILS/CHAINAGE-RANGE") ;attribute tag name
(setq tag3 "ISSUE") ;attribute tag name
(setq tag4 "1") ;attribute tag name
(setq tag5 "2") ;attribute tag name
(setq ss1 (ssget "x" (list (cons 0 "INSERT") (cons 2 bname))))
(setq INC (sslength ss1))
(repeat INC
(foreach att (vlax-invoke (vlax-ename->vla-object (ssname SS1 (SETQ INC (- INC 1)) )) 'getattributes)
(if (= tag2 (strcase (vla-get-tagstring att)))
(progn
(setq ans2 (vla-get-textstring att))
(if (/= ans2 NIL)
(setq list2 (cons ans2 list2))
) ; if
); end progn
) ; end if - created list2 from attribute tag2
(if (= tag3 (strcase (vla-get-tagstring att)))
(progn
(setq ans3 (vla-get-textstring att))
(if (/= ans3 NIL)
(setq list3 (cons ans3 list3))
) ; end if
) ; end progn
) ; end if - created list3 from attribute tag3
(if (= tag4 (strcase (vla-get-tagstring att)))
(progn
(setq ans4 (vla-get-textstring att))
(if (/= ans4 NIL)
(setq list4 (cons ans4 list4))
) ; end if
) ; end progn
) ; end if - created list4 from attribute tab4
(if (= tag5 (strcase (vla-get-tagstring att)))
(progn
(setq ans5 (vla-get-textstring att))
(if (/= ans5 NIL)
(setq list5 (cons ans5 list5))
) ; end if
) ; end progn
) ; end if - created list5 from attribute tab5
) ; end foreach
) ; end repeat
;lisp part2 concatenate attributes: Bigal https://www.cadtutor.net/forum/topic/54784-combining-lists/
(setq lentab (length list2)) ; JW - set number of repetitions as lentab
(setq x 0) ; JW - set variable x to track number of reps
(repeat lentab
(setq anstab (strcat (nth x list2) " SHEET " (nth x list4) " OF " (nth x list5)))
(setq listtab (cons anstab listtab))
(setq x (+ x 1))
) ; end repeat. JW - for each x from 0 to "lentab", concatenate and add to list "listtab"
(setq listtab (reverse listtab)) ; JW - reverses list to correct order
; JW - this next line might be useless, try deleting this later
(setvar 'ctab curlayout)
; part 3 - create table style template and generate table, source: INDEXREVDATE.lsp
; create an empty list, set a counter variable, and
; set a reference to the current model space.
(setq lst '() i 0)
(setq aobj (vlax-get-acad-object))
(setq adoc (vla-get-activedocument aobj))
(setq *ps* (vla-get-paperspace adoc))
(setq pt1 (vlax-3d-point (getpoint "\nPick point for top left hand of table: "))) ;JW - select insertion point with cursor
(setq acmCol (vla-getinterfaceobject
(vlax-get-acad-object)
(strcat "AutoCAD.AcCmColor."
(substr (getvar "ACADVER") 1 2))))
(setq t_Style1 (vla-item (vla-get-dictionaries adoc) "acad_tablestyle")
t_Style2 (vla-addObject t_Style1 "CBC_Dwg_Index_Table" "AcDbTableStyle")
)
(vla-setgridvisibility t_style2 (+ acHorztop acVertleft acVertright)
(+ acTitlerow):vlax-false)
(vla-setrgb acmCol 41 41 41)
(vla-put-colorindex acmcol 008)
(vla-setgridcolor t_style2 (+ acVertLeft acHorzTop acVertRight) acTitleRow acmCol)
(vla-setgridcolor t_style2 (+ acHorzInside) acDataRow acmCol)
(vla-setrgb acmCol 0 255 255)
(vla-put-colorindex acmcol acCyan)
(vla-setcolor t_style2 acTitleRow acmCol)
(vla-setgridcolor t_style2 (+ acHorzBottom acHorzInside acVertInside) acHeaderRow acmCol)
(vla-setgridcolor t_style2 (+ acHorzBottom acVertLeft acVertRight acVertInside) acDataRow acmCol)
(vla-setgridcolor t_style2 (+ acHorzTop acHorzBottom acVertLeft acVertRight) acHeaderRow acmCol)
(vla-setgridcolor t_style2 (+ acHorzTop acHorzBottom acVertLeft acVertRight) acDataRow acmCol)
(vla-setrgb acmCol 0 255 0)
(vla-put-colorindex acmcol acGreen)
(vla-setcolor t_style2 acHeaderRow acmCol)
(vla-setcolor t_style2 acDataRow acmCol)
(vla-setAlignment t_style2 acTitleRow acMiddleCenter)
(vla-setAlignment t_style2 acHeaderRow acMiddleCenter)
(vla-setAlignment t_style2 acDataRow acMiddleCenter)
(vla-SetTextHeight t_Style2 acTitleRow 2.5)
(vla-SetTextHeight t_Style2 acHeaderRow 1.8)
(vla-SetTextHeight t_Style2 acDataRow 1.8)
(vla-SetTextStyle t_Style2 acTitleRow "RMS - 2.5mm")
(vla-SetTextStyle t_Style2 acHeaderRow "RMS - 1.8mm")
(vla-SetTextStyle t_Style2 acDataRow "RMS - 1.8mm")
(vla-put-Vertcellmargin t_Style2 0.5)
(vla-put-Horzcellmargin t_Style2 2)
(setq myTable (vla-AddTable *ps* pt1 (+ 2 (length list1)) 3 7 185)) ;JW - Create table
(vla-put-StyleName myTable "CBC_Dwg_Index_Table") ;JW - Table style
(vla-put-layer mytable "N-NOTES") ;JW - Table layer
(vla-setRowHeight mytable 0 5)
(vla-setRowHeight mytable 1 5)
(vla-setRowHeight mytable 2 5)
(vla-setColumnWidth mytable 0 25)
(vla-setColumnWidth mytable 1 85)
(vla-setColumnWidth mytable 2 10)
;set the header/title texts
(vla-setText mytable 0 0 "DRAWING INDEX")
(vla-setText mytable 1 0 "SHEET NO. / SET")
(vla-setText mytable 1 1 "SHEET DESCRIPTION")
(vla-setText mytable 1 2 "ISSUE")
(setq rep1 2) ;JW - variable used to progress table rows
(setq num 0) ;JW - variable used to get data from lists
(repeat (length list1)
(vla-setRowHeight mytable rep1 5)
(vla-setCellAlignment mytable rep1 0 acMiddleLeft)
(vla-setCellAlignment mytable rep1 1 acMiddleLeft)
(vla-settext mytable rep1 0 (NTH num LIST1))
(vla-settext mytable rep1 1 (NTH num LISTtab))
(vla-settext mytable rep1 2 (NTH num LIST3))
(setq num (+ num 1))
(setq rep1 (+ rep1 1))
); end repeat
;set drawing sheet set row bottom cyan (NOT USED)
;(vla-mergecells myTable 2 2 0 2)
;(vla-setCellAlignment mytable 2 0 acMiddleLeft)
;(vla-setrgb acmCol 0 255 255)
;(vla-put-colorindex acmcol acCyan)
;(vla-setcellgridcolor mytable 2 0 acBottomMask acmCol)
;(vla-setcellgridcolor mytable 2 1 acBottomMask acmCol)
;(vla-setcellgridcolor mytable 2 2 acBottomMask acmCol)
(vlax-release-object aobj)
(vlax-release-object adoc)
(vlax-release-object myTable)
(vlax-release-object *ps*)
(princ)
); end JW defun
(CBC:dwgindex2)