This project has moved and is read-only. For the latest updates, please go here.

How get ViewPort's defined on Layout dimensions?

Dec 2, 2014 at 5:41 PM
Edited Dec 2, 2014 at 5:43 PM
I defined viewport on my layout as a single rectangle viewport.
Is any way to get by netdxf dimensions of this viewport? Layout object of this layout , and ViewPort property have no width and heigth, theres only dimensions of View, not viewport.

BR, Mateusz
Dec 3, 2014 at 6:02 PM
May I see a sample of what are you trying to do? The information you seek should be the width and height properties of the Viewport entity. Keep in mind that the dxf stores both the information of the camera and the viewport into this Viewport entity.

Dec 3, 2014 at 8:32 PM
Here is first screenshot, from autocad and i signed values i need:

And here is visual studio screenshot, these properties are from ViewPort object for Layout1. These Width and Height are equat to VIEW values, but i cant find these values i signed on first screenshot. Of course i can write method to fetch them but i want use your great library :)

Dec 4, 2014 at 6:27 PM
I think you are picking the wrong viewport. The layouts store their viewports as any other entity that you may add to it, and multiple number of them might also appear. As the layout viewports are actually entities, you can find them in the document Viewports list or the layouts References. Here you have a piece of code:
            DxfDocument doc = DxfDocument.Load("Viewport.dxf");
            // This is the layout you are working with
            string layoutName = "Layout1";
            Layout layout = doc.Layouts[layoutName];

            // Finding the viewports that belongs to a particular layout. Remember multiple viewports might appear in the same layout.
            // Method 1
            List<Viewport> viewports1 = new List<Viewport>();
            foreach (Viewport viewport in doc.Viewports)
                if (viewport.Owner.Record.Layout == layout)

            // Method 2
            List<Viewport> viewports2 = new List<Viewport>();
            List<DxfObject> references = doc.Layouts.GetReferences(layout);
            foreach (DxfObject o in references)
                if (o is Viewport)
                    viewports2.Add((Viewport) o);

            // you should end up with the same results with both methods
Additionally, the layouts also contain another viewport, while the previous ones are views to your model space, this one represents the actual view of the paper, and this is the viewport that it is stored in the layout Viewport property. I decided to separate it, even thought, the dxf stores it in the same place, because it is more related to the UI rather than to the geometry of your drawing.

I hope it clarifies your doubts, it can get really messy.