Author Topic: Curious behavior with paper space blocks/layouts  (Read 1754 times)

0 Members and 1 Guest are viewing this topic.

Joe Burke

  • Guest
Curious behavior with paper space blocks/layouts
« on: March 01, 2011, 07:41:17 AM »
Using 2008.

I wonder if the following problem is a known issue. It seems I cannot get data about objects in paper space layouts until the layout(s) are activated. IOW, if I open a DWG file which was saved with model space active, a LISP routine which tries to access objects in paper space returns nil.

Example code follows. Both methods fail.

Code: [Select]
(defun GetPSObjects1 ( / doc layouts pslst)
  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (setq layouts (vla-get-Layouts doc))
  ;; works okay if this line is included.
  ;(vlax-for x layouts (vlax-put doc 'ActiveLayout x))
  (vlax-for x layouts
    (if (not (eq "Model" (vlax-get x 'Name)))
      (vlax-for i (vlax-get x 'Block)
        (setq pslst (cons i pslst))
      )
    )
  )
  pslst
)

(defun GetPSObjects2 ( / doc blocks pslst)
  (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
  (setq blocks (vla-get-Blocks doc))
  (vlax-for x blocks
    (if
      (and
        (not (eq "*MODEL_SPACE" (strcase (vlax-get x 'Name))))
        (= -1 (vlax-get x 'IsLayout))
      )
      (vlax-for i x
        (setq pslst (cons i pslst))
      )
    )
  )
  pslst
)

I should add, if the drawing contains one or more apparently empty paper space layouts, the code should return the default viewport for each layout.
« Last Edit: March 01, 2011, 07:59:27 AM by Joe Burke »

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Curious behavior with paper space blocks/layouts
« Reply #1 on: March 01, 2011, 10:12:53 AM »
Maybe it's an '08 thing, as in '09 it seems to work as it should.  Typed into the command line after saving and drawing in model space, then opening it up again.

Code: [Select]
(vlax-for lo (vla-get-layouts (vla-get-activedocument
(vlax-get-acad-object)))
(if (/= (vla-get-Name lo) "Model")
(vlax-for i (vla-get-block lo)
(print (vla-get-objectname i))
)
)
)

"AcDbViewport"
"AcDbPolyline"
"AcDbViewport"
"AcDbBlockReference"
"AcDbBlockReference"
"AcDbBlockReference"
"AcDbBlockReference"
"AcDbBlockReference"
"AcDbBlockReference"
"AcDbBlockReference"
"AcDbPolyline"
"AcDbPolyline"
"AcDbPolyline"
"AcDbViewport" nil

Here is your code also working.
Code: [Select]
Command: (getpsobjects1)
(#<VLA-OBJECT IAcadPViewport2 0f064f5c> #<VLA-OBJECT IAcadLWPolyline 0ec19ac4>
#<VLA-OBJECT IAcadLWPolyline 0ec1b024> #<VLA-OBJECT IAcadLWPolyline 0ec1ba44>
#<VLA-OBJECT IAcadBlockReference 0ee06e24> #<VLA-OBJECT IAcadBlockReference
0ee06db4> #<VLA-OBJECT IAcadBlockReference 0ee06d44> #<VLA-OBJECT
IAcadBlockReference 0ee06cd4> #<VLA-OBJECT IAcadBlockReference 09f97124>
#<VLA-OBJECT IAcadBlockReference 09f96f64> #<VLA-OBJECT IAcadBlockReference
09f96cc4> #<VLA-OBJECT IAcadPViewport2 0a25748c> #<VLA-OBJECT IAcadLWPolyline
0ec1a5a4> #<VLA-OBJECT IAcadPViewport2 0a2576ec>)

Code: [Select]
Command: (getpsobjects2)
(#<VLA-OBJECT IAcadPViewport2 09eb5784> #<VLA-OBJECT IAcadLWPolyline 0ec1aa84>
#<VLA-OBJECT IAcadLWPolyline 0ec1aa24> #<VLA-OBJECT IAcadLWPolyline 0ec1a964>
#<VLA-OBJECT IAcadBlockReference 0ee07d74> #<VLA-OBJECT IAcadBlockReference
0ee07d04> #<VLA-OBJECT IAcadBlockReference 0ee07c94> #<VLA-OBJECT
IAcadBlockReference 0ee07c24> #<VLA-OBJECT IAcadBlockReference 0ee07ad4>
#<VLA-OBJECT IAcadBlockReference 0ee07a64> #<VLA-OBJECT IAcadBlockReference
0ee079f4> #<VLA-OBJECT IAcadPViewport2 09eb581c> #<VLA-OBJECT IAcadLWPolyline
0ec1b744> #<VLA-OBJECT IAcadPViewport2 09eb56ec>)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Joe Burke

  • Guest
Re: Curious behavior with paper space blocks/layouts
« Reply #2 on: March 02, 2011, 06:29:04 AM »
Tim,

Thanks for testing in 2009. Agreed, it sounds like a 2008 quirk at this point. I'll test my code in 2006 and 2010 when I have time and access to those versions.