.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Layouts and Viewports

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
fieldguy
6285 Views, 14 Replies

Layouts and Viewports

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

  

14 REPLIES 14
Message 2 of 15
cadMeUp
in reply to: fieldguy

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.

Message 3 of 15
StephenPreston
in reply to: cadMeUp

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. 

<<<

 

Cheers,

Stephen Preston
Autodesk Developer Network
Message 4 of 15
fieldguy
in reply to: StephenPreston

Thank you.  I should have caught that in the documentation.

Message 5 of 15
fieldguy
in reply to: fieldguy

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?  

Message 6 of 15
JamieVJohnson2
in reply to: fieldguy

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

jvj
Message 7 of 15
cadMeUp
in reply to: fieldguy

If a lay
Message 8 of 15
cadMeUp
in reply to: cadMeUp

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!

Message 9 of 15
fieldguy
in reply to: cadMeUp

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.   

Message 10 of 15
fieldguy
in reply to: fieldguy

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

Message 11 of 15
cadMeUp
in reply to: fieldguy

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.

Message 12 of 15
mgorecki
in reply to: JamieVJohnson2

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

Message 13 of 15
JamieVJohnson2
in reply to: mgorecki

It should always be the first one in the enumerated list.

 

jvj

jvj
Message 14 of 15
mgorecki
in reply to: JamieVJohnson2

Thanks.

Message 15 of 15
jeff
in reply to: mgorecki

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:

Input flag indicating whether to return paperspace viewports associated with layouts.
You can also find your answers @ TheSwamp

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost