See the top rated post in this thread. Click here

Results 1 to 8 of 8

Thread: Getting the number of a layout tab

  1. #1
    Login to Give a bone
    0

    Default Getting the number of a layout tab

    Hey all,

    Just getting started with AutoLISP.

    At work we don't use sheets but layouts instead. Perhaps it's not the most proper way but that's the way it is. We find layouts are faster since each person completes 15-20 multi-page projects a day.
    Considering the volume of work I want to automate some things, like populating fields.

    The subject of this thread is getting a text object to display a page count such as "3 of 5"

    I Googled the subject and you may be quick to point out that similar sounding questions have been asked before. Maybe not quite.

    What I have:
    (setq layout_count_var (length(layoutlist)))
    in acaddoc.lsp happily returns the count of layout tabs, but that's only half of the solution.

    I found a suggested solution that used DieselExpression, BUT. IT. JUST. DIDN'T. WORK.

    Is there an AutoLISP solution to make a text object (in each layout) display a layout tab's order number?

    I use AutoCAD 2018 if it matters.

    Insight is appreciated.

    Thanks!
    Last edited by whackoprogrammer760234; 2017-12-03 at 05:06 AM.

  2. #2
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    1

    Default Re: Getting the number of a layout tab

    Hi,

    Give this routine a try and let me know.

    Code:
    (defun c:lay2fld (/ doc lay pnt ids id1 id2)
      ;;------------------------------------;;
      ;; Tharwat - Date: 03.Dec.2017	;;
      ;;------------------------------------;;
      (defun ids (obj doc / uty)
        (if (vlax-method-applicable-p
              (setq uty (vla-get-utility doc))
              'getobjectidstring
            )
          (vla-getobjectidstring uty obj :vlax-false)
          (itoa (vla-get-objectid obj))
        )
      )
      (and (setq pnt (getpoint "\nSpecify a point :"))
           (setq doc (vla-get-activedocument (vlax-get-acad-object))
                 lay (vla-get-layouts doc)
                 id1 (ids (vla-item lay (getvar 'ctab)) doc)
                 id2 (ids lay doc)
           )
           (vla-addtext
             (vla-get-block (vla-get-activelayout doc))
             (strcat
               "%<\\AcObjProp Object(%<\\_ObjId " id1 ">%).TabOrder>%"
               " of " "%<\\AcExpr %<\\AcObjProp Object(%<\\_ObjId " id2
               ">%).Count>%-1 >%"
              )
             (vlax-3d-point pnt)
             (getvar 'textsize)
           )
      )
      (princ)
    ) (vl-load-com)

  3. #3
    Login to Give a bone
    0

    Default Re: Getting the number of a layout tab

    Quote Originally Posted by Tharwat View Post
    Hi,

    Give this routine a try and let me know.

    Code:
    (defun c:lay2fld (/ doc lay pnt ids id1 id2)
      ;;------------------------------------;;
      ;; Tharwat - Date: 03.Dec.2017	;;
      ;;------------------------------------;;
      (defun ids (obj doc / uty)
        (if (vlax-method-applicable-p
              (setq uty (vla-get-utility doc))
              'getobjectidstring
            )
          (vla-getobjectidstring uty obj :vlax-false)
          (itoa (vla-get-objectid obj))
        )
      )
      (and (setq pnt (getpoint "\nSpecify a point :"))
           (setq doc (vla-get-activedocument (vlax-get-acad-object))
                 lay (vla-get-layouts doc)
                 id1 (ids (vla-item lay (getvar 'ctab)) doc)
                 id2 (ids lay doc)
           )
           (vla-addtext
             (vla-get-block (vla-get-activelayout doc))
             (strcat
               "%<\\AcObjProp Object(%<\\_ObjId " id1 ">%).TabOrder>%"
               " of " "%<\\AcExpr %<\\AcObjProp Object(%<\\_ObjId " id2
               ">%).Count>%-1 >%"
              )
             (vlax-3d-point pnt)
             (getvar 'textsize)
           )
      )
      (princ)
    ) (vl-load-com)
    Seems to work as intended! Thanks!

  4. #4
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Getting the number of a layout tab

    Quote Originally Posted by whackoprogrammer760234 View Post
    Seems to work as intended! Thanks!
    You're welcome.

  5. #5
    All AUGI, all the time
    Join Date
    2003-07
    Posts
    560
    Login to Give a bone
    0

    Default Re: Getting the number of a layout tab

    if you want just post, I have read the layout name and put the numeric part as the sheet number (layout1 D01 this is handy if you have say two dwgs with layouts 1-10 the second with layouts 11-20 etc Also have a total renumber it will put sheet 1 of 9 next 2 of 9 etc as our title block has a attribute for most values so can change any of them.

    What I am saying is if your title block is in your layout you can do lots of stuff very easy.

    Others to do with layouts include GOTO x jump to layout X useful I have 88 layouts in one project.

    an example
    Code:
    ; 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")
    
    (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))))
    
    (if (= ss1 nil) ; for xxxx jobs
    (progn 
    (setq bname "my_TITLE")
    (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")
    
    ); end AH defun
    
    (AH:dwgindex)
    
    (princ)

  6. #6
    Woo! Hoo! my 1st post
    Join Date
    2023-01
    Posts
    1
    Login to Give a bone
    0

    Default Re: Getting the number of a layout tab

    Hi, Tharwat;
    What field do I put in the text box in which the number goes in the titleblock for this code to work?

    Thanks!

  7. #7
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Getting the number of a layout tab

    Quote Originally Posted by asilvacotto803291 View Post
    Hi, Tharwat;
    What field do I put in the text box in which the number goes in the titleblock for this code to work?

    Thanks!
    Hi,

    Something like this ?
    Code:
    (defun c:test (/ doc lay sel tag ids id1 id2)
      ;;----------------------------------------------------;;
      ;;	Author : Tharwat Al Choufi			;;
      ;; website: https://autolispprograms.wordpress.com	;;
      ;;----------------------------------------------------;;
      (defun ids (obj doc / uty)
        (if (vlax-method-applicable-p
              (setq uty (vla-get-utility doc))
              'getobjectidstring
            )
          (vla-getobjectidstring uty obj :vlax-false)
          (itoa (vla-get-objectid obj))
        )
      )
      (and
        (setq tag "MYTAG") ;; specify the tag name to allow the program to write the field into it.
        (princ "\nSelect attributed block :")
        (setq sel (ssget "_+.:S:E" '((0 . "INSERT") (66 . 1))))
        (setq doc (vla-get-activedocument (vlax-get-acad-object))
              lay (vla-get-layouts doc)
              id1 (ids (vla-item lay (getvar 'ctab)) doc)
              id2 (ids lay doc)
        )
        (vl-some '(lambda (x)
                    (and (= (vla-get-tagstring x) tag)
                         (or (vla-put-textstring
                               x
                               (strcat
                                 "%<\\AcObjProp Object(%<\\_ObjId "
                                 id1
                                 ">%).TabOrder>%"
                                 " of "
                                 "%<\\AcExpr %<\\AcObjProp Object(%<\\_ObjId "
                                 id2
                                 ">%).Count>%-1 >%"
                                )
                             )
                             t
                         )
                    )
                  )
                 (vlax-invoke
                   (vlax-ename->vla-object (ssname sel 0))
                   'GetAttributes
                 )
        )
        (vl-cmdf "_.regen")
      )
      (princ)
    ) (vl-load-com)

  8. #8
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: Getting the number of a layout tab

    So this is my code the way I would do it if it were on my machine.

    Code:
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to get layout number from name of layout 
    ;___________________________________________________________________________________________________________|
    
    (defun LayoutNumber (strLayoutName / colLayouts lstLayoutObjects lstOfLayouts)
     (if (and (setq colLayouts       (Layouts 'activedocument))
              (setq lstLayoutObjects (toobjects colLayouts))
              (setq lstOfLayouts      (mapcar '(lambda (X)(list (strcase (vlax-get X "Name")) 
                                                                (vlax-get X "Taborder") 
                                                          )
                                               ) 
                                               lstLayoutObjects)
              )
         )
      (cadr (assoc (strcase strLayoutName) lstOfLayouts))
     )
    )
    I have rewritten activeX to give me access to all activeX commands with error trapping built in and without vla- prefixes.

    In one of my libraries I have a function called toobjects that converts collections, autolisp selectionsets, lists of handles, objectid's, entity names, entity lists, activeX selection sets to a list of vla objects. One of the functions is collection to list. So I rewrote it here as an example below.

    I stopped nesting functions a long time ago, because I found it is better to test every expression for success (error trapping).

    All of the functions return nil for failure.

    This approach gives me libraries of functions (1000+ functions) that load at every drawing is less than a second.

    This one below will work for you.

    Code:
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to get layout number from name of layout
    ;___________________________________________________________________________________________________________|
    
    (defun LayoutNumber (strLayoutName / colLayouts lstLayoutObjects lstOfLayouts objApplication objActiveDocument)
     (if (and (setq objApplication    (vlax-get-acad-object))
              (setq objActiveDocument (vlax-get objApplication    "ActiveDocument"))
              (setq colLayouts        (vlax-get objActiveDocument "Layouts"))
              (setq lstLayoutObjects  (CollectionToListOfObjects  colLayouts))
              (setq lstOfLayouts      (mapcar '(lambda (X)(list (strcase (vlax-get X "Name")) 
                                                          (vlax-get X "Taborder") 
                                              )
                                      ) 
                                      lstLayoutObjects)
              )
         )
      (cadr (assoc (strcase strLayoutName) lstOfLayouts))
     )
    )
    
    
    ;___________________________________________________________________________________________________________|
    ;
    ; Function to convert a collection to a list of objects
    ;___________________________________________________________________________________________________________|
    
    (defun CollectionToListOfObjects (colLayouts / lstObjects objLayout)
     (vlax-for objLayout colLayouts
      (setq lstObjects (cons objLayout lstObjects))
     )
     (reverse lstObjects)
    )
    (vl-load-com)
    Attached Files Attached Files
    Last edited by peter; 2023-01-09 at 09:44 PM.
    AutomateCAD

Similar Threads

  1. 2011: Express Tools Auto Number - Skips Number in Multi-line Mtext
    By stusic in forum AutoCAD General
    Replies: 3
    Last Post: 2013-01-29, 02:38 PM
  2. Linked door number and security arrow number
    By 01chang in forum Revit Architecture - General
    Replies: 2
    Last Post: 2009-08-19, 01:54 PM
  3. Layout Page Number
    By kwest in forum AutoCAD LT - General
    Replies: 4
    Last Post: 2009-03-27, 01:29 PM
  4. Link Layout TAB to the drawing number
    By boyerd in forum AutoCAD General
    Replies: 4
    Last Post: 2008-03-06, 07:02 PM
  5. Layout tab displays wrong name and number
    By jfields.61630 in forum AutoCAD Sheet Set Manager
    Replies: 3
    Last Post: 2006-12-18, 08:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •