I found several links discussing viewports and layouts and found it a bit confusing. I managed to get what I wanted but am left with some questions. We are planning for a base coordinate system change which means all of our CAD data will move. The ultimate goal is to check scales, then pan and zoom each floating modelspace viewport as required, in potentially 1000s of dwg files.
The dwg file I am testing has 45 layouts and 1 viewport on each. The code attached is what I used to get the numbers to match. I understand that viewport 1 on the layout is the paperspace layout itself. But, I had several viewport numbers of -1 on each layout. I thought -1 represented an empty list, like nothing selected in a listbox.
Questions
1 - What does viewport number -1 mean?
2 - What is the purpose of viewporttable?
3 - Why doesn't viewporttable contain viewporttablerecords that have this information - or does it?
There might be more later - now I need a vacation.
TIA
Solved! Go to Solution.
Solved by StephenPreston. Go to Solution.
I've never noticed the viewport number of -1 before until trying your code, looks to me like that number represents a non-current layout, maybe someone knows otherwise? It looks like the current layout will give a positive number and non-current will give a number of -1.
The ViewportTable holds ViewportTableRecord objects which are the tiled viewports in model space.
Viewport objects are the floating viewports on a layout.
From the ObjectARX Reference Guide ->AcDbViewport::number:
>>>
This function returns the viewport ID number. This is the number that is reported by the AutoCAD CVPORT system variable when the viewport is the current viewport in the AutoCAD editor. If the viewport is inactive, -1 is returned.
This value is not saved with the drawing, and changes each time the drawing is opened.
The viewport ID number is used for DXF group code 69.
<<<
I have a drawing with 6 layouts with 1 model space viewport on each. 1 of the layouts has a viewport that has not been activated (whoever created the drawing never switched to model space in this layout). Because of this, there is no viewport number > 1 returned by layout.getviewports(). If I manually activate model space on that layout, and run my code again, it finds the viewport. This means I have a drawing with a layout with a viewport that my code won't find.
Is there another way to find all of the viewports and make sure model space has been activated?
In a layout's viewport collection, the first viewport is actually the screen you are looking at. The other viewports are what you created using Mview command inside of autocad. If you mess with the first viewport object you will get some very funny problems with your cad file (delete one and see!).
jvj
My appologies, all my text got trashed when I posted my last.
Try the attached code that I posted.
Sounds like the 'Layout' has never been switched to/activated
You can use the Layout.Initialize() method.
It will work for a layout that has not been initialized, but will throw an exception for one that has been initialized.
This is what it states in the ObjectARX docs for the AcDbLayout.initialized() method:
This method will do the behind the scenes work to establish a Paper Space viewport for the layout. This allows a layout to be set up and made ready for other viewports and entities to be put into the layout as well as to set various layout properties.
Returns Acad::eOk if successful; otherwise, returns an AutoCAD error status.
So just calling Initialize() on a Layout object won't completely activate it like manually switching to it would.
You shouldn't have to switch to 'model space' thru a Viewport to active the viewport though and have it initialized, hope I understand that part correctly in your post.
Hope this helps!
Thanks to all contributors. I did not notice or consider the initialize method of a layout. I will post my solution when finished. I have to move on for now.
Working with the APIs for autocad and autocad map reminds me of playing with a house of cards - be careful of which card you pull and how you put it back.
Attached is the code and a DWG file that shows some of the problems I am finding. There are 8 layouts (l1-l8). l1 through l3 look normal, except that properties shows 1 polyline and 1 viewport when I select all, but there is only 1 object. But, l4 through l8 are causing trouble. The code results in 15 layouts on l4, but I can only see 1 in Autocad.
Can someone explain what I am seeing here and how to work around it? I am going to check viewport centers and sizes to see if they make sense - I haven't tried that yet.
TIA
Layouts I1 thru I3 each contain a single viewport. Each one of them is not quite rectangular which results in a clipped viewport. When you select a clipped viewport you are selecting 2 objects, the viewport and the clipping object, most cases a polyline.
Try this, on a blank layout create 2 rectangular viewports. Rotate one of them 45 degrees. Select the non-rotated viewport and look at the 'Clipped' property in the properties palette, you will see that it is not clipped. Do the same thing with the rotated viewport you will see that it's 'Clipped' property is 'Yes'. So as soon as a viewport becomes in anyway non-rectangular AutoCAD turns it into a clipped viewport.
Also, there are some layers frozen in this drawing which is why you are not seeing the other objects on the I4 layout.
Hi Jamie,
I have a program that's finding 2 viewports when I can only see 1. I understand what you're saying about one viewport is actually the layout that your looking at, but how can I tell programatically which is which? I have tried using a "watch" and copying the info to text files, but that is taking way too long. Do you know how I can tell the difference between the two viewports?
Thansk,
Mark
Quote from here by kaefer that helped me out a while back
"there's no need to filter out paperspace viewports or even to obtain ViewportIds if you use Database.GetViewports(false)."
From Docs:
Can't find what you're looking for? Ask the community or share your knowledge.