Retrieve layout names by order of which they sit to populate in drawing list on the first page

Retrieve layout names by order of which they sit to populate in drawing list on the first page

wfraser3
Explorer Explorer
1,664 Views
5 Replies
Message 1 of 6

Retrieve layout names by order of which they sit to populate in drawing list on the first page

wfraser3
Explorer
Explorer

Hi all,

 

I'm wondering if anyone has any ideas on how to call out a layout tab name based on there order onto the first page. This is without using sheet set manager since my co-workers don't know how to use it. The file I'm working on is a template for projects at work.

 

So I have a drawing list table set up on the first page and I want a code that will take the layout name of the first page (which I understand I can just use ctab) and insert it into the first row. Then the second row takes the layout name of the second page. Then the third row takes the layout name of the third page. And so on and so forth. It can't be specific to one layout, because I want to be able to move the layouts around and for the table to update in the order the layouts are in.

 

I've looked around quite a bit and it looks like this isn't a simple task and I understand if the best solution is to use sheet set manager. However, I like challenges like these and wanted to see if anyone could come up with something. The closest I've come is retrieving the object layout ID and then using the code to output the name. A couple issues with this: it's specific to the layout and not the order plus I'm stuck at only being able to retrieve the name in code (VBA) but can't insert it as a field. I do think this kind of method is on the right track, maybe.

 

Thanks in advance.

0 Likes
1,665 Views
5 Replies
Replies (5)
Message 2 of 6

rkmcswain
Mentor
Mentor

I know this does not answer your question the way you want, but drop your sheets into SSM and you can add a "Sheet List Table" in literally seconds that does what you want. And it will update when you move the sheets around in order.

 

Your co-workers don't "have to know how to use SSM" - although that's like saying "my co-workers don't know how to make text, or use the circle command".....  SSM is not some secret super advanced tool. 

 

Anyway, back to the above, even if just YOU setup the sheet set and make the Sheet List table, your co-workers don't have to know or care where it came from.

R.K. McSwain     | CADpanacea | on twitter
Message 3 of 6

hak_vz
Advisor
Advisor

@wfraser3 

Following function create ordered lists of layout names so you can use it to populate your table.

 

(defun getLayoutOrderList( / lst mklist mappend flatten)
	(defun mklist (x) (if (listp x) x (list x)))
	(defun mappend (fn lst)(apply 'append (mapcar fn lst))) 
	(defun flatten (expr)(mappend 'mklist expr))
	(vlax-for lay 
		(vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
		(setq lst (cons (list (vla-get-taborder lay)(vla-get-name lay)) lst))
	)
	(cdr(flatten(mapcar 'cdr (vl-sort lst '(lambda (a b) (< (car a)(car b)))))))
)

 

It is late at my location. If you need a code to populate a table, I can' provide it tomorrow.

@rkmcswain  solution sounds reasonable.

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 4 of 6

Sea-Haven
Mentor
Mentor

Done for me back in 2013 use as an example

 

; dwg index to a table
; by Alan H NOV 2013
(defun AH:dwgindex (/ doc objtable ss1 lay ans ans2 plotabs ss1 tag2 tag3 list1 list2 curlayout colwidth numcolumns numrows INC rowheight )

(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
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(setq curspace (vla-get-paperspace doc))
(setq pt1 (vlax-3d-point (getpoint "\nPick point for top left hand of table:  "))) 

; read values from title blocks

(setq bname "DA1DRTXT") ; title block name

(setq tag2 "DRG_NO") ;attribute tag name
(setq tag3 "WORKS_DESCRIPTION") ;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 ans (vla-get-textstring att))
            (if (/= ans NIL)
            (setq list1 (cons ans list1))
            ) ; if 
            ); end progn
          ) ; end if
        (if (= tag3 (strcase (vla-get-tagstring att)))
          (progn
          (setq ans2 (vla-get-textstring att))
          (if (/= ans2 NIL)
              (setq list2 (cons ans2 list2)) 
           ) ; end if
           ) ; end progn
	 ) ; end if tag3 
    
) ; end foreach

) ; end repeat
(setvar 'ctab curlayout)
(command "Zoom" "E")
(command "regen")


(reverse list1)
;(reverse list2)

; now do table 
(setq numrows (+ 2 (sslength ss1)))
(setq numcolumns 2)
(setq rowheight 0.2)
(setq colwidth 150)
(setq objtable (vla-addtable curspace pt1 numrows numcolumns rowheight colwidth))
(vla-settext objtable 0 0 "DRAWING REGISTER")
(vla-settext objtable 1 0 "DRAWING NUMBER") 
(vla-settext objtable 1 1 "DRAWING TITLE") 

(SETQ X 0)
(SETQ Y 2)

(REPEAT (sslength ss1)
  (vla-settext objtable Y 0 (NTH X LIST1))
  (vla-settext objtable Y 1 (NTH X LIST2))
  (vla-setrowheight objtable y 7)

  (SETQ X (+ X 1))
  (SETQ Y (+ Y 1))
)

(vla-setcolumnwidth objtable 0 55)
(vla-setcolumnwidth objtable 1 170)

(command "_zoom" "e")
(princ)
); end AH defun

(AH:dwgindex)

  

0 Likes
Message 5 of 6

pbejse
Mentor
Mentor

So I have a drawing list table set up on the first page

What is "drawing list table" ? ACAD_TABLE"  An attribute block?  MText? or even worse "TEXT"? 

 

It can't be specific to one layout,  because I want to be able to move the layouts around and for the table to update in the order the layouts are in.


There goes Field value out of the window, I'm not even sure you can use tab layout name as a field value, 'Ctab works only if you are on the same tab. You can use a placeholder though.

 

But, one way or the other, the user still needs to "update" the values after re-aranging the tab order via lisp or otherwise. Even with sheet set. There's just no way around it.

I could be totally wrong about all that. though 😊

 


I've looked around quite a bit and it looks like this isn't a simple task and I understand if the best solution is 


It would be loads easier to help you if we can see what we're dealing with@wfraser3 

Anyhoo..

(Defun c:Demo ( / aDoc layouts _LayutOrder )
(defun _LayutOrder (layt / l);<-- can be modified to do more than just collect
	(vlax-for lay  layt
		(setq l (cons (list (vla-get-taborder lay)(vla-get-name lay)) l))
	)
  (vl-sort l '(lambda (a b)(< (Car a)(car b))))
  )
  
  (setq aDoc (vla-get-ActiveDocument (vlax-get-acad-object))
	layouts(vla-get-layouts aDoc))
  (setq Layoutorder (Cdr (_LayutOrder layouts)))
(textscr)
  (foreach itm Layoutorder
    (print itm))
(princ)
)

HTH

 

 

 

0 Likes
Message 6 of 6

Sea-Haven
Mentor
Mentor

Pbejse your right about change order it takes a few seconds to remake the table and delete the old one using what I posted. How far do we need automation to go if move a layout then run index again.

0 Likes