NEED SOME WHELP WITH A SCRIPT I WROTE BUT IT KEEPS SAYING BLOCK "SHEETS NOT FOUND NOT SURE HOW TO FIX

NEED SOME WHELP WITH A SCRIPT I WROTE BUT IT KEEPS SAYING BLOCK "SHEETS NOT FOUND NOT SURE HOW TO FIX

djharo71
Explorer Explorer
650 Views
4 Replies
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

djharo71
Explorer
Explorer
(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)
0 Likes
651 Views
4 Replies
Replies (4)
Message 2 of 5

Pointdump
Consultant
Consultant

Hi David,
Welcome to the Autodesk Forums.
You'll probably get more response by posting in the >>>Customization Forum<<<. That's where all the code-heads hang out.
Dave

Dave Stoll
Las Vegas, Nevada

EESignature

64GB DDR4 2400MHz ECC SoDIMM / 1TB SSD
NVIDIA Quadro P5000 16GB
Windows 10 Pro 64 / Civil 3D 2025
0 Likes
Message 3 of 5

O_Eckmann
Mentor
Mentor

Hi @djharo71 ,

 

Because your block are dynamic, the name is *U... so you have to select all block and test their effectivename

 

Have you written this code or is it ChatGPT answer? Because there some other errors in your code.

 

 

Olivier Eckmann

EESignature

0 Likes
Message 4 of 5

djharo71
Explorer
Explorer
chatbotapp wrote it. I am not a programer and have been trying to find ways
to speed up some of the work because i have been working on some projects
lately that have over 300 sheets. If you could help that would be great
0 Likes
Message 5 of 5

O_Eckmann
Mentor
Mentor

Hi @djharo71 ,

 

Using IA to generate program in Lisp langage for AutoCAD is a very bad idea, it doesn't work actually, except for very simple use (changing color of an objet is OK, more complex algorithme is impossible 😊)

 

If you want to learn how to write a lisp, I think you can find help on some forum.

If you search someone to write this program freely, you can try your chance, but not sure you find. As @Pointdump says, you can find more help in AutoCAD customization forum, your question isn't relative to Map 3D.

 

Just for information, you couldn't have more than 254 layouts (sheets) in a single drawing. So if you need to produce 300 sheets, you have to take that into account.

 

Olivier Eckmann

EESignature

0 Likes