- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Good day all!
I've been using this code below for a while now and it works:
(defun c:SHNO ( / allLayoutsList allLayoutsListLength NewSheetNo titlePage nextPages)
(setvar "cmdecho" 0)
;***************** Define block name variables *****************;
(setq titlePage "_SP_TITLE_PAGE_08SEP15") ; title page block name
(setq nextPages "_SP-Border2-F28X40_08SEP2015") ; subsequent pages block name
;***************************************************************;
(setq allLayoutsList (LAYOUTLIST)) ; gets list of all layout names
(setq allLayoutsListLength (vl-list-length allLayoutsList)) ; gets number of layouts
(setq NewSheetNo "")
;;;;;;;;;;----[un]comment to switch sheet and number formats----;
;
;(letterSingleX) ;
;(letterAllXofX) ;
;(fullAllXofX) ;
(fullSingleX) ;
;
;;;;;;;;;;------------------------------------------------------;
(command "LAYOUT" "set" (strcat "Layout 1")) ; sets "Layout 1" current
(setvar "cmdecho" 1)
(princ)
) ;SHNO
(defun fullSingleX ( / counter NewSheetNo ssTTLpageBLKsht ssTTLBLKsht)
(setq counter 1)
(while (<= counter allLayoutsListLength)
(command "LAYOUT" "set" (strcat "Layout " (itoa counter))) ; sets next paper space sheet current
(cond
((= counter 1)
(progn
(setq NewSheetNo (strcat "" (itoa counter) " OF " (itoa allLayoutsListLength) ""))
(setq ssTTLpageBLKsht
(ssget "_X" (list '(0 . "INSERT")
(cons 2 titlePage)
'(66 . 1))))
(setq i1 (sslength ssTTLpageBLKsht))
(setq obj (vlax-ename->vla-object (ssname ssTTLpageBLKsht (setq i1 (1- i1)))) attlst (vlax-invoke obj 'GetAttributes))
(foreach att attlst (if (= (vla-get-TagString att) "SHEET")(vla-put-TextString att NewSheetNo))))) ;progn ;=1
((and (> counter 1)(< counter allLayoutsListLength))
(progn ;- Pages in between first and last sheet numbers
(setq NewSheetNo (strcat "" (itoa counter) ""))
(setq ssTTLBLKsht
(ssget "_X" (list (cons 0 "INSERT")
(cons 2 nextPages)
(cons 66 1)
(cons 410 (getvar "ctab")))))
(setq i2 (sslength ssTTLBLKsht))
(setq obj (vlax-ename->vla-object (ssname ssTTLBLKsht (setq i2 (1- i2)))) attlst (vlax-invoke obj 'GetAttributes))
(foreach att attlst (if (= (vla-get-TagString att) "SHEET")(vla-put-TextString att NewSheetNo))))) ;progn ;1< <MAX
((= counter allLayoutsListLength)
(progn ;- Last page sheet numbers
(setq NewSheetNo (strcat "" (itoa counter) " OF " (itoa allLayoutsListLength) ""))
(setq ssTTLBLKsht
(ssget "_X" (list (cons 0 "INSERT")
(cons 2 nextPages)
(cons 66 1)
(cons 410 (getvar "ctab")))))
(setq i3 (sslength ssTTLBLKsht))
(setq obj (vlax-ename->vla-object (ssname ssTTLBLKsht (setq i3 (1- i3)))) attlst (vlax-invoke obj 'GetAttributes))
(foreach att attlst (if (= (vla-get-TagString att) "SHEET")(vla-put-TextString att NewSheetNo))))) ;progn ;=MAX
) ;cond
(setq counter (+ counter 1))
) ;while
(princ)
) ;fullSingleX
---
This routine works as intended. However, if there are any more than 40 or so sheets in my drawing file, the routine moves like a slug. I just ran this on a drawing that has 60+ sheets and it took longer than 2 minutes.
Do you guys have any ideas how I could restructure/optimize the code so it runs faster?
Thanks!
~Z
Solved! Go to Solution.