Jump to content

Auto Count all Layouts


Ashishs

Recommended Posts

I am looking for a code to count all layouts in current drawing.

 

Tried Command "Layout" & selecting option "?", it lists all the layouts, but doesn't count.

 

I am looking for result something like this- "Total numbers of Layouts are XX"

 

Tnx 4 ur assistance in advance.

Link to comment
Share on other sites

(defun layouts( / );
 (vl-load-com)
 (princ (strcat "\nThere are " (itoa (vla-get-count (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object))))) " layouts in this drawing."))
 )

 

Short and sweet, just like it should be.

Link to comment
Share on other sites

  • 3 years later...

Sorry to redust this thread, but I am trying to utilize the layout count LISP that Lee and Mark created, but I have no idea how to initiate it. Can I get a little guidance?

Link to comment
Share on other sites

Is there a way to have that displayed in a field?

 

Here is an example program to create an MText object containing a Field Expression referencing the number of paperspace layouts in a drawing; the program could of course be modified to insert the Field Expression in Text, MText or Attributes:

 

[color=GREEN];; Layout Field  -  Lee Mac[/color]
[color=GREEN];; Creates an MText object containing a Field Expression[/color]
[color=GREEN];; referencing the number of paperspace layouts in a drawing.[/color]

([color=BLUE]defun[/color] c:layoutfield ( [color=BLUE]/[/color] ins )
   ([color=BLUE]if[/color] ([color=BLUE]setq[/color] ins ([color=BLUE]getpoint[/color] [color=MAROON]"\nPick Point for Field: "[/color]))
       ([color=BLUE]vla-addmtext[/color]
           ([color=BLUE]vlax-get-property[/color] (LM:acdoc) ([color=BLUE]if[/color] ([color=BLUE]=[/color] 1 ([color=BLUE]getvar[/color] 'cvport)) 'paperspace 'modelspace))
           ([color=BLUE]vlax-3D-point[/color] ([color=BLUE]trans[/color] ins 1 0)) 0.0
           ([color=BLUE]strcat[/color]
               [color=MAROON]"%<\\AcExpr %<\\AcObjProp Object(%<\\_ObjId "[/color]
               (LM:ObjectID ([color=BLUE]vla-get-layouts[/color] (LM:acdoc)))
               [color=MAROON]">%).Count>% - 1 >%"[/color]
           )
       )
   )
   ([color=BLUE]princ[/color])
)

[color=GREEN];; ObjectID  -  Lee Mac[/color]
[color=GREEN];; Returns a string containing the ObjectID of a supplied VLA-Object[/color]
[color=GREEN];; Compatible with 32-bit & 64-bit systems[/color]

([color=BLUE]defun[/color] LM:ObjectID ( obj )
   ([color=BLUE]eval[/color]
       ([color=BLUE]list[/color] '[color=BLUE]defun[/color] 'LM:ObjectID '( obj )
           ([color=BLUE]if[/color]
               ([color=BLUE]and[/color]
                   ([color=BLUE]vl-string-search[/color] [color=MAROON]"64"[/color] ([color=BLUE]getenv[/color] [color=MAROON]"PROCESSOR_ARCHITECTURE"[/color]))
                   ([color=BLUE]vlax-method-applicable-p[/color] ([color=BLUE]vla-get-utility[/color] (LM:acdoc)) 'getobjectidstring)
               )
               ([color=BLUE]list[/color] '[color=BLUE]vla-getobjectidstring[/color] ([color=BLUE]vla-get-utility[/color] (LM:acdoc)) 'obj '[color=BLUE]:vlax-false[/color])
              '([color=BLUE]itoa[/color] ([color=BLUE]vla-get-objectid[/color] obj))
           )
       )
   )
   (LM:ObjectID obj)
)

[color=GREEN];; Active Document  -  Lee Mac[/color]
[color=GREEN];; Returns the VLA Active Document Object[/color]

([color=BLUE]defun[/color] LM:acdoc [color=BLUE]nil[/color]
   ([color=BLUE]eval[/color] ([color=BLUE]list[/color] '[color=BLUE]defun[/color] 'LM:acdoc '[color=BLUE]nil[/color] ([color=BLUE]vla-get-activedocument[/color] ([color=BLUE]vlax-get-acad-object[/color]))))
   (LM:acdoc)
)

([color=BLUE]vl-load-com[/color]) ([color=BLUE]princ[/color])

Link to comment
Share on other sites

An alternative idea is why not read all layouts work out total number then number each sheet as 1 of 16 2 of 16 etc the method of sheet number can be based on a couple of rules.

 

Number by layout list as created

Number by layout list as appears on bottom of screen

Number by the layout lable name eg D012 = 12 this allows non numbering of layouts

 

Using a title block with attributes you have control of each atltribute change.

 

Lastly its a work in progress does other stuff as well. Copies certain lines of a title block to corresponding newly created title blocks that are blank. Would it be of benefit to you ?

 

When we are creating sometimes change order or add title blocks in middle. Create unique layouts that are not construction sheets but for imformation/discussion the latter not numbered.

 

Ps thanks to Lee for previous info on layouts order.

Link to comment
Share on other sites

  • 9 years later...

Could you give give me the lisp for counting layout in fields? 

so I do not have to update my page numbers?

 

Thank you. 

Link to comment
Share on other sites

For just counting layouts you could add this to Lee's code it's just his code for lfsheet with the extra stuff removed:

;|----------------------------------------------------------------------
  Total Sheets

  Generates a field expression referencing the total number of paperspace layouts in the drawing.
----------------------------------------------------------------------|;

(defun c:lfsheets ( ) ; Number of Layouts in drawing
    (layoutfield
       '(lambda ( obj )
            (vla-put-textstring obj
                (strcat
                    "%<\\AcExpr %<\\AcObjProp Object(%<\\_ObjId "
                    (LM:objectid (vla-get-layouts (LM:acdoc)))
                    ">%).Count>%-1 >%"
                )
            )
        )
    )
)

and use this macro to set this number to a text selected in your drawing:

^C^C^P(or C:lfsheets (load "LayoutFieldV1-0 (1).lsp"));lfsheets

Thanks Lee!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...