;; SHEETNUMBERS ;; To work correctly, this LISP needs to be loaded with the drawing. ;; this can be done by adding a call in on_doc_load.lsp ;; CAD Concepts ;; https://cadconcepts.co.nz ;; 2022-07-31 ;; CCL-SETCUSTDOCPROPS ;; Sets a custom drawing property of the given key to a given value ;; (CCL-SetCustDocProps "My_CustomProperty" "My_CustomProperty_Value") ;; returns: ("My_CustomProperty" "My_CustomProperty_Value") if the key is set, otherwise returns nil (defun CCL-SetCustDocProps ( Key KeyValue / oSInfo SetKeyValue) (vl-load-com) ; Retrieve the summary info object (setq oSInfo (vla-get-SummaryInfo (vla-get-Database (vla-get-ActiveDocument (vlax-get-Acad-Object))))) (if (vl-catch-all-error-p (vl-catch-all-apply 'vla-SetCustomByKey (list oSInfo Key KeyValue)) ; set the key & value ) (setq SetKeyValue nil) ; if an issue is struck, then return nil (setq SetKeyValue (list Key KeyValue)) ; otherwise return the key and keyvalue in the form of a list ); end if SetKeyValue ; return (key keyvalue) ) ;; SHEETNUMBERS ;; ;; Creates a set of Custom doc properties containing the position number of the paperspace layout and the total number of layouts (defun SheetNumbers ( / olayout LayoutVals LayoutName oThisLayout VarName VarValue) (vl-load-com) (setq olayouts (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))) ; get the layouts object (CCL-SetCustDocProps "*LAYOUT-TOTAL-NUMBER*" (length (layoutlist))) ; Set the total number of sheets ; for each of our paper space layouts (foreach LayoutName (layoutlist) (setq oThisLayout (vla-item olayouts LayoutName)) ; get this layouts object ; Set a LISP variable of the layouts taborder (number) ; The lisp variable is in the form "*LAYOUT--NUMBER*" where is the unique handle of the layout (setq VarName (strcat "*LAYOUT-" (vla-get-handle othislayout) "-NUMBER*")) (setq VarValue (vla-get-taborder oThisLayout)) (CCL-SetCustDocProps VarName VarValue) ) ) ;; Set a reactor to call update LISP fields prior to printing (vlr-command-reactor "Update Sheet Numbers on Printing" '((:vlr-commandWillStart . UpdateSheetNumbers))) ;; Note. an alternative to reactors would be to define your own PRINT, PLOT, PUBLISH commands that called the SheetNumbers ;; function prior to running the command. ;; UPDATESHEETNUMBERS ;; Reactor function (defun UpdateSheetNumbers (reactor commandcall / cmd) (setq cmd (nth 0 commandcall)) (cond ((or (= cmd "PRINT") (= cmd "PUBLISH") (= cmd "PLOT")) ; if any print commands are called ;(princ (strcat "\nCommand = " cmd " started, updating SheetNumbers")) (SheetNumbers) ; then update the LISP field values ) ) ) (SheetNumbers) ; Automatically run this function on loading (prin1)