Creating a table of layout index lisp, want to display layout list as they were not in order, please help

Creating a table of layout index lisp, want to display layout list as they were not in order, please help

Anonymous
Not applicable
4,290 Views
19 Replies
Message 1 of 20

Creating a table of layout index lisp, want to display layout list as they were not in order, please help

Anonymous
Not applicable

Hi I have a draft lisp shown below,

 

(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)

0 Likes
Accepted solutions (1)
4,291 Views
19 Replies
Replies (19)
Message 2 of 20

CodeDing
Mentor
Mentor

@Anonymous ,

 

You did not post your full code, so there are variables which we cannot see how they were created.

This might be useful for you. It will return the layout sheets in the order they appear.

(defun LayoutListOrdered ( / dLays lays oLays cnt)
  (setq dLays (cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_LAYOUT"))))
  (setq lays (mapcar '(lambda (l) (cons (cdr (assoc 71 (dictsearch dLays l))) l)) (layoutlist)))
  (repeat (1- (setq cnt (1+ (length lays))))
    (setq oLays (cons (cdr (assoc (setq cnt (1- cnt)) lays)) oLays))
  );repeat
);defun

Best,

~DD

0 Likes
Message 3 of 20

Anonymous
Not applicable

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)

Message 4 of 20

CodeDing
Mentor
Mentor

@Anonymous wrote:

...only thing i want - layout list not to be sorted


I do not understand your request. Can you explain in more detail what your issue is and what your questions are? From what you just said, you do NOT want layouts to be sorted. If that is the case, then I do not know what your question is.

 

Best,

~DD

0 Likes
Message 5 of 20

Anonymous
Not applicable

BankstownCAD_0-1614203411410.png

See above table sheet list is alphabetically sorted

however my layout shown below

BankstownCAD_1-1614203506243.png

I want to match above layout order with my table sheet list,

 

Regards,

 

0 Likes
Message 6 of 20

pendean
Community Legend
Community Legend
Do you not use SSM (SheetSet Manager)? What you want is built into that, SSM is all about Layouts.
0 Likes
Message 7 of 20

Anonymous
Not applicable

My work place doesn't want to use SSM 

0 Likes
Message 8 of 20

CodeDing
Mentor
Mentor

@Anonymous ,

 

The function I provided to you will return a list of the layout names in order.

 

Best,

~DD

0 Likes
Message 9 of 20

Anonymous
Not applicable

Many thanks DD for your kind attention,

 

I have added your segment & trying to work it out, but not yet getting the expected outcome.... 

0 Likes
Message 10 of 20

CodeDing
Mentor
Mentor

@Anonymous ,

 

Did you try changing this line..

(setq list0 (layoutlist)) ;JW - create temp list with all layouts

..to this instead?

(setq list0 (layoutlistordered)) ;JW - create temp list with all layouts

 

0 Likes
Message 11 of 20

Anonymous
Not applicable

Yes, i did so & give me below error;

 

error: no function definition: LAYOUTLISTORDERED

0 Likes
Message 12 of 20

Anonymous
Not applicable
Hi DD,

I can provide you my template too, if you want to have a look across?
0 Likes
Message 13 of 20

CodeDing
Mentor
Mentor

error: no function definition: LAYOUTLISTORDERED


^^^ This error means that you did not successfully load the function I provided to you.

Are you comfortable with loading lisp files? Please load the lisp function I provided you first, then run your command and see if that works.

 

Best,

~DD

0 Likes
Message 14 of 20

Anonymous
Not applicable

I have replaced your code as you said below:

BankstownCAD_0-1614216318811.png

And load the updated Lisp which return with below;

error: no function definition: LAYOUTLISTORDERED 

Did i do it wrong DD? 

0 Likes
Message 15 of 20

CodeDing
Mentor
Mentor

You must also load THIS lisp in addition to your lisp.

0 Likes
Message 16 of 20

Sea-Haven
Mentor
Mentor

Add the Codeding lisp to the start of yours. Then it will get loaded.

0 Likes
Message 17 of 20

Anonymous
Not applicable

Thanks DD for helping me through,

 

No i have new table Sheet Column as per tab order, however sheet descriptions are not following through,

 

I think i lost the connection not sure how to fix,

 

Regards,

Monzoor

 

 

0 Likes
Message 18 of 20

CodeDing
Mentor
Mentor
Accepted solution

@Anonymous ,

 

I have not tested this code, but it might work for you. Let me know.

(defun CBC:DWGINDEX2 ( / errMsg LayoutListOrdered ss e sheetInfo aobj adoc *ps* pt1 acmCol t_Style1 t_Style2 myTable)
  (vl-load-com)

  ;; Initial Check(s)
  (cond
    ((eq "Model" (getvar 'CTAB))
      (setq errMsg "\nYou must be in a layout for this option.")
    );cond 1
    ((not (setq ss (ssget "_X" '((0 . "INSERT") (2 . "CBCRMSA3LAYOUT")))))
      (setq errMsg "\nNo Title Blocks found.")
    );cond 2
  );cond
  ;; Exit if error
  (if errMsg (progn (prompt errMsg) (alert errMsg) (exit)))

  ;; Helper Function(s)
  (defun LayoutListOrdered ( / dLays lays oLays cnt)
    (setq dLays (cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_LAYOUT"))))
    (setq lays (mapcar '(lambda (l) (cons (cdr (assoc 71 (dictsearch dLays l))) l)) (layoutlist)))
    (repeat (1- (setq cnt (1+ (length lays))))
      (setq oLays (cons (cdr (assoc (setq cnt (1- cnt)) lays)) oLays))
    );repeat
  );defun
  
  ;; Get attributes/vals from title blocks
  (foreach lay (cdr (layoutlistordered))
    (if (setq ss (ssget "_X" (list (cons 0 "INSERT") (cons 2 "CBCRMSA3LAYOUT") (cons 410 lay))))
      ;; sheetInfo = ((layoutName description issue) ...)
      (setq e (ssname ss 0)
            sheetInfo
              (cons
                (list
                  lay
                  (strcat
                    (getpropertyvalue e "SHEET-DETAILS/CHAINAGE-RANGE")
                    " SHEET "
                    (getpropertyvalue e "1")
                    " OF "
                    (getpropertyvalue e "2")
                  );strcat
                  (getpropertyvalue e "ISSUE")
                );list
                sheetInfo
              );cons
      );setq
    );if
    (setq ss nil)
  );foreach
  (setq sheetInfo (reverse sheetInfo))

  ;; Create table style template and generate table
  (setq aobj (vlax-get-acad-object))
  (setq adoc (vla-get-activedocument aobj))
  (setq *ps* (vla-get-paperspace adoc))
  (initget 1)
  (setq pt1 (vlax-3d-point (getpoint "\nPick point for top left hand of table: ")))

  (setq acmCol
    (vla-getinterfaceobject
      (vlax-get-acad-object)
      (strcat "AutoCAD.AcCmColor." (substr (getvar "ACADVER") 1 2))
    );vla-
  );setq

  (setq t_Style1 (vla-item (vla-get-dictionaries adoc) "acad_tablestyle")
        t_Style2 (vla-addObject t_Style1 "CBC_Dwg_Index_Table" "AcDbTableStyle")
  );setq

  (vla-setgridvisibility
    t_style2
    (+ acHorztop acVertleft acVertright)
    (+ acTitlerow)
    :vlax-false
  );vla-

  (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 sheetInfo)) 3 7 185))
  (vla-put-StyleName myTable "CBC_Dwg_Index_Table")
  (vla-put-layer mytable "N-NOTES")
  
  (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 cRow 2)
  (foreach sheet sheetInfo
    (vla-setRowHeight mytable cRow 5)
    (vla-setCellAlignment mytable cRow 0 acMiddleLeft)
    (vla-setCellAlignment mytable cRow 1 acMiddleLeft)
    (vla-settext mytable cRow 0 (car sheet))
    (vla-settext mytable cRow 1 (cadr sheet))
    (vla-settext mytable cRow 2 (caddr sheet))
    (setq cRow (+ cRow 1))
  );foreach

  (vlax-release-object aobj)
  (vlax-release-object adoc)
  (vlax-release-object myTable)
  (vlax-release-object *ps*)

  (princ)
);defun

(CBC:DWGINDEX2)

Best,

~DD

Message 19 of 20

Anonymous
Not applicable

Hi DD,

I had a quick go & it is working the way i wanted

Super thanks to you,

You saved my life & my job,

May Almighty bless you, your family & friends,

 Regards,

Monzoor

Message 20 of 20

john.uhden
Mentor
Mentor

@CodeDing and @Anonymous 

I give you both my utmost thanks for your complete code examples.

Today I managed to write a MT2Table routine to convert an Mtext "table" into a real table by subdividing the entire Mtext string by "\\P" and "/t".  The beauty is that a lot of our work requires tabulating lot coverages, and although I wrote a routine to total the square footage in an Mtext object, getting the total in the table will be more reliable.  Well, except that the quantities contain commas, as in "2,475 SF."  I'll have to study what that solution might be.

Anyway, the most important thing is that I learned a lot from you guys.  YAY!

John F. Uhden