Replies: 2 comments
-
This has historical reasons. The paperspace layout was introduced in DXF R12. Only one paperspace was supported and all entities were stored in the DXF R2000 introduced multiple paperspace layouts and kept the previous solution with all entities of the modselspace and the entities of the active paperspace in the The The DXF attributes ezdxf/src/ezdxf/addons/drawing/frontend.py Line 979 in bf737bf def _draw_viewports(frontend: UniversalFrontend, viewports: list[Viewport]) -> None:
# The VIEWPORT attributes "id" and "status" are very unreliable, maybe because of
# the "great" documentation by Autodesk.
# Viewport status field: (according to the DXF Reference)
# -1 = On, but is fully off-screen, or is one of the viewports that is not
# active because the $MAXACTVP count is currently being exceeded.
# 0 = Off
# <positive value> = On and active. The value indicates the order of
# stacking for the viewports, where 1 is the "active" viewport, 2 is the
# next, and so on.
viewports.sort(key=lambda e: e.dxf.status)
# Remove all invisible viewports:
viewports = [vp for vp in viewports if vp.dxf.status > 0]
if not viewports:
return
# The "active" viewport determines how the paperspace layout is presented as a
# whole (location & zoom state).
# Maybe there are more than one "active" viewports, just remove the first one,
# or there is no "active" viewport at all - in this case the "status" attribute
# is not reliable at all - but what else is there to do? The "active" layout should
# have the id "1", but this information is also not reliable.
if viewports[0].dxf.get("status", 1) == 1:
viewports.pop(0)
# Draw viewports in order of "status"
for viewport in viewports:
frontend.draw_viewport(viewport) |
Beta Was this translation helpful? Give feedback.
-
Thanks for the hint at draw_viewports. It is at least somewhat helpful, which once again is more than the official docs deliver. I did however just discover something about the status value that might be relevant information for you as well: The viewport ID also seems to be changed but I have to look into that further to make any definitive statements. |
Beta Was this translation helpful? Give feedback.
-
This is not really a ezdxf question but a DXF question in general. I hope that's okay.
First of all I'd like to mention that while I'm not even using ezdxf, the documentation (and sometimes comments in the code) has been INCREDIBLY helpful to understanding the mess that is DXF. In many ways immensely more helpful than the official so called "documentation/specs". So big thanks for that!
Anyways, I am currently trying to figure out VIEWPORT and I am having some issues.
Issues I have encountered and (I think) understood so far through ezdxf docs and tinkering around myself:
More VIEWPORT than expected
A layout always contains at least one viewport, even if no viewport was created. An exception is the model space layout which does not have it. This viewport is somehow necessary internally for AutoCAD and not shown to the user. According to ezdxf docs this implicit viewport can be recognized by its viewport ID being 1 (GroupCode 69).
VIEWPORT in "blocks" or "entities"?
Viewports seem to appear inside of paper space blocks as well as "standalone" entities. The reason seems to be that most layouts store viewports in the paper space block. The only exception is the "active" layout/paper space (the layout currently open ?) which stores its viewports in the "Entities" section for some reason.
The problem
This all seems to be true for files that I have myself created and played around with.
However I've also encountered DXF files where the viewport IDs are not quite what one would expect.
In the "Entites" section all seems fine. In my case I've got two viewports, one of which has viewport ID 1, therefore it is the implicit one which I can ignore.
In the paper space blocks however all viewport IDs are 0!
Following are some screenshots from DXF Explorer:
The two active viewports in the "Entities" section and several paper space blocks, all containing 2 viewport (just one in reality, the other one is the implicit one)
One viewport in "Entities" has ID 1 as expected (The other one not shown has ID 2). The first viewport in the blocks section
has ID 0 (the second one not shown here also has ID 0). This is true for all Viewports in the Blocks section.
As it currently stands I can not really differentiate between the viewports in the paper space blocks but I'd need to know which one is the "real" one. Any insight would be greatly appreciated. Thank you
Beta Was this translation helpful? Give feedback.
All reactions