Message 1 of 5
NEED SOME WHELP WITH A SCRIPT I WROTE BUT IT KEEPS SAYING BLOCK "SHEETS NOT FOUND NOT SURE HOW TO FIX
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
(defun c:ZoomViewportsToSheets (/ doc layouts layoutName layout modelSpace blockName insPt vp sheetBlock sheetNumber) (vl-load-com) ;; Document and Layouts (setq doc (vla-get-activedocument (vlax-get-acad-object))) (setq layouts (vla-get-Layouts doc)) (setq modelSpace (vla-get-ModelSpace doc)) ;; Block names and attribute (setq sheetBlockName "SHEETS" attrName "SHEET_NUMBER") ;; Utility function to find a block by its attribute value in model space (defun get-block-by-attribute (blockName attrValue / ss blk block found) (setq ss (ssget "_X" (list (cons 0 "INSERT") (cons 2 blockName) (cons 410 "Model")))) (if (and ss (> (sslength ss) 0)) (progn (setq blkList (ssnamex ss)) (foreach blk blkList (setq block (vlax-ename->vla-object blk)) (setq found (get-attribute block attrName)) (princ (strcat "\nChecking block: " (vlax-get block 'EffectiveName) " with attribute value: " found)) (if (and found (eq (strcase found) (strcase attrValue))) (return block))))) nil) ;; Utility function to get an attribute value from a block by its tag (defun get-attribute (block attrName / attributes attribute tag) (setq attributes (vla-getattributes block)) (vlax-for att attributes (setq tag (vla-get-tagstring att)) (if (eq (strcase tag) (strcase attrName)) (return (vla-get-TextString att)))) nil) ;; Main function to process each layout (defun process-layout (layout) (setq layoutName (vla-get-Name layout)) (if (/= layoutName "Model") (progn (princ (strcat "\nProcessing layout: " layoutName)) (setvar "CTAB" layoutName) ;; Get the SHEETS block in model space by layout number (setq sheetBlock (get-block-by-attribute sheetBlockName layoutName)) (if sheetBlock (progn (princ (strcat "\nFound SHEETS block for layout: " layoutName)) ;; Get the insertion point of the SHEETS block (setq insPt (vlax-get sheetBlock 'InsertionPoint)) ;; Find and configure the viewport in paper space (vlax-for obj (vla-get-PaperSpace doc) (if (and (eq (vla-get-ObjectName obj) "AcDbViewport") (not (vla-get-ModelType obj))) (progn (setq vp obj) (princ (strcat "\nConfiguring viewport for layout: " layoutName)) (vla-put-DisplayLocked vp :vlax-false) (vla-put-Center vp (vlax-3d-point (car insPt) (cadr insPt))) ;; Optionally adjust viewport size as needed, e.g., set width and height to fit block extents (vla-put-Height vp 200.0) ;; Adjust as necessary (vla-put-Width vp 200.0) ;; Adjust as necessary (vla-put-DisplayLocked vp :vlax-true) ) ) ) ) (princ (strcat "\nSHEETS block not found for layout: " layoutName))) ) ) ) ;; Iterate through each layout and process (vlax-for layout layouts (process-layout layout)) (princ "\nZoom Viewports to SHEETS completed.") (princ) ) (princ "\nRun the function 'c:ZoomViewportsToSheets' to execute the script.\n") (princ)