Layout.Viewports Node - Empty List

I am trying to move text from Paper Space to Model Space for each layout I have in my .dwg, but when I try to return the viewports from my layout tabs, I get Empty List for each layout. Screenshot below.

Does anyone have any advice on how to get this to work?

I am bringing this topic back up. I think this might have something to do with a viewport being active maybe? I am now trying to place a north arrow in each layout and have the rotation of the north arrow read the twist angle of the layouts viewport, but I am getting an Empty List for each viewport/layout tab unless I double click into the viewport of each sheet. Any way I can avoid this?

Correct - it’s a little quirk of AutoCAD that a layout has to be activated for its viewport(s) to be initialized.

1 Like

Any ideas on how to make this happen automatically? It really disrupts the flow of my script if we have to manually go into each viewport and activate it.

It would have to be done via the API. You can access the LayoutManager and then set the active layout. That could be put in a loop to do all of them.

I am revisiting this issue now and I am running into inconsistencies with the python script I put together to activate the viewports. Sometimes it does great! Other times, it won’t work at all. Sometimes (like the screenshot) it will work partly. Again the idea behind this process is to get the viewports activated so I can retrieve scaling and rotation factors of the viewport to place scale bars and north arrows on layouts.


VP Activation.dyn (11.2 KB)

@zachri.jensen

I am revisiting this forum post again. I am still struggling to find a way to access the API and Layoutmanager to activate multiple viewports and its really hindering my ability to complete a couple Dynamo graphs because of this issue. Any advice or starting points that could help me get this working?

Funny, didn’t know the Layouts must have been activated first.

First I created a Viewport on Layout1 (empty drawing). Then I copied/pasted it, and Dynamo found both, obviously, because the Layout had been active.
Then I copied the whole Layout to a new Layout without making it active, and then Dynamo returned an empty list for that particular Layout.

But, the node Viewport.GetAllDocumentViewports returned them all!

You can find this node in The Civil Nodes package. I’ll have a look in the code to see where is the difference, can’t explain yet. Also, there is no way back to see on which Layout the Viewport resides, there is no Viewport.Layout node or something similar. But with String.Split you get some result:

You can get the layout that any object resides in like this:

Fantastic feedback! That Viewport.GetAllDocumentViewports node does return all of the viewports. But now that node will not work with my Viewport.TwistAngle node to return back the angle of the viewport? Any thoughts on how to work around this?

@Anton_Huizinga
I thought I had a python script working (still may?). It worked on a single test file with multiple viewports to return what appears was correct rotation angles of 0, but then when I tried a new layout with the viewports having rotation the Viewport.GetAllDocumentViewports is returning back with 13 viewports, but I feel confident that I agree that it only has 7 viewports (as shown in the Layout.Viewports node even though the first 6 are empty lists and not activated). Thoughts?


Trying to think outside the box here, but could I do some unnecessary task in each viewport to activate it? Thinking like making a line or text at each viewport and then translating that to model space and then deleting it?

I guess activating the Layout is enough, what Zachri says. You can do that by setting the variable CTAB with The Civil Nodes package:

After that, the viewports are approachable.

Good tip! It is not in my system yet to look at the generic nodes :slight_smile:

1 Like