I'm trying to figure out how to get a lisp routine to change the ## from the "page" section to auto insert the page number (not "ctab" name) based on it's position in the layout tabs. I'm already using the lisp routine for the total number of pages and that is working great.
Solved! Go to Solution.
Solved by ronjonp. Go to Solution.
found this little lisp routine on this thread that returns the layouts in order:
@lylegrisso wrote:
I'm already using the lisp routine for the total number of pages and that is working great.
Curious, what is the field source for that total number of pages - " of 11" <--- ?
Why not number them in the sheet set manager? It looks like you're already heavily using fields already.
If you want to do this with code try this. You'll need to supply the blockname of your attributed block and the tag you wish to fill out. IMO the sheet set manager is a bit tidier though.
(defun c:foo (/ a bn c e s tg)
;; Name of your attribute block
(setq bn "TBINFO")
;; Name of the attribute tag to fill out
(setq tg "SHEET#")
(cond ((setq s (ssget "_X" (list '(0 . "INSERT") '(410 . "~Model") (cons 2 bn) '(66 . 1))))
(setq a (cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_LAYOUT"))))
(foreach e (mapcar 'cadr (ssnamex s))
(setq c (dictsearch a (cdr (assoc 410 (entget e)))))
;; Function not available in Bricscad
(setpropertyvalue e tg (itoa (cdr (assoc 71 c))))
)
)
)
(princ)
)
pbejse
I'm using this lisp to get the total number
(vlr-command-reactor nil '((:vlr-commandWillStart . _totalLayoutsReactor)))
ronjonp
I'm not using the sheet set manager due to the client.
I tried your code (after changing the block name and attribute name) and it seems to bring up the visual LISP console, but it's not reacting to the drawing.
paulli_apa
your code didn't work with this either.
found this vlx to download:
CAD Forum - PageOf - creates a field with Page N of M layout counter (VLX LISP for AutoCAD)
description:
CAD Forum - Total number of layouts as a field (Page 3 of 7).
Post a sample drawing with your titleblock. For it to "react" to your drawing you'd need to include it in the "_totalLayoutsReactor" code that you already have.
@lylegrisso wrote:
@ronjonp
here is a sample dwg with my border.also not sure if it matters but I'm using Acad 2023
Worked here see attached:
(defun c:foo (/ a bn c e s tg)
;; Name of your attribute block
(setq bn "BORDER")
;; Name of the attribute tag to fill out
(setq tg "SHT")
(cond ((setq s (ssget "_X" (list '(0 . "INSERT") '(410 . "~Model") (cons 2 bn) '(66 . 1))))
(setq a (cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_LAYOUT"))))
(foreach e (mapcar 'cadr (ssnamex s))
(setq c (dictsearch a (cdr (assoc 410 (entget e)))))
;; Function not available in Bricscad
(setpropertyvalue e tg (itoa (cdr (assoc 71 c))))
)
)
)
(princ)
)
I'm using AutoCAD 2023 as well.
You'd have to run the code again after you make changes .. the other "_totalLayoutsReactor" code you mentioned runs on a reactor which is code that "reacts" to changes/commands automatically.
Are you typing "foo" on the command line after you load it? It does not run automatically.
If you want it to run automatically after load then add this line at the end:
Any reason why you don't want to run PageOf.vlx (my reply message 7)?
After loading the vlx, works pretty well on your SHT attribute.
The only thing you need to do is edit & remove the text you don't want
@paullimapa wrote:
Any reason why you don't want to run PageOf.vlx (my reply message 7)?
For me I don't run compiled code unless I created it and or I completely trust the author. Compiled code for this simple task is unnecessary IMO.
I typically don't like to use compiled code either. But since this little vlx file gets the job done, I thought I share it so OP is aware.
Another example it uses the layout name pulling the number from it, but the layout number could be used instead.
;;-------------------=={ Parse Numbers }==--------------------;;
;; ;;
;; Parses a list of numerical values from a supplied string. ;;
;;------------------------------------------------------------;;
;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;;
;;------------------------------------------------------------;;
;; Arguments: ;;
;; s - String to process ;;
;;------------------------------------------------------------;;
;; Returns: List of numerical values found in string. ;;
;;------------------------------------------------------------;;
(defun LM:ParseNumbers ( s )
(
(lambda ( l )
(read
(strcat "("
(vl-list->string
(mapcar
(function
(lambda ( a b c )
(if
(or
(< 47 b 58)
(and (= 45 b) (< 47 c 58) (not (< 47 a 58)))
(and (= 46 b) (< 47 a 58) (< 47 c 58))
)
b 32
)
)
)
(cons nil l) l (append (cdr l) (list nil))
)
)
")"
)
)
)
(vl-string->list s)
)
)
; end of lee-mac
; start of update
(DEFUN ah:sheetupdate1 ( / DOC LAY PLOTABS LEN TABNAME DWGNUM OLDTAG1 SHEETNUM NEWSTR1 ATT ss1)
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(setq plotabs '())
(vlax-for lay (vla-get-Layouts doc)
(setq plotabs (cons (vla-get-name lay) plotabs))
)
(setq len (length plotabs))
(setq x 0)
(setq oldtag1 "SHTNO.") ;attribute tag name change to suit
(repeat len
(setq tabname (nth x plotabs))
(if (/= tabname "Model")
(progn
(setvar 'ctab tabname)
(command "pspace")
(setq ss1 (ssget "x" (list (cons 0 "INSERT") (cons 2 "Your title block name")(cons 410 tabname))))
(setq sheetnum (abs (car (Lm:parsenumbers tabname))))
(setq newstr1 (STRCAT (rtos sheetnum 2 0) " of " (RTOS (- LEN 1) 2 0)))
(foreach att (vlax-invoke (vlax-ename->vla-object (ssname SS1 0 )) 'getattributes)
(if (= oldtag1 (strcase (vla-get-tagstring att)))
(vla-put-textstring att newstr1)
)
)
)
)
(setq x (+ x 1))
) ; end repeat
)
; end defun ah
(ah:sheetupdate1)
If having a field (automatic update) is not a requirement, then this works.
I modified it to fit your title block name & attribute.
It'll automatically fill out sheet #. But if you move the layout tabs around, you'll have to re-run tabnumber command.
Can't find what you're looking for? Ask the community or share your knowledge.