.NET

Reply
Valued Mentor
fieldguy
Posts: 382
Registered: ‎03-31-2005
Message 1 of 15 (1,862 Views)
Accepted Solution

Layouts and Viewports

1862 Views, 14 Replies
08-18-2011 10:02 AM

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

  

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. 

<<<

 

Valued Mentor
cadMeUp
Posts: 331
Registered: ‎05-11-2006
Message 2 of 15 (1,834 Views)

Re: Layouts and Viewports

08-19-2011 08:44 AM 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.

ADN Support Specialist
StephenPreston
Posts: 422
Registered: ‎05-22-2006
Message 3 of 15 (1,827 Views)

Re: Layouts and Viewports

08-19-2011 10:19 AM 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
Valued Mentor
fieldguy
Posts: 382
Registered: ‎03-31-2005
Message 4 of 15 (1,815 Views)

Re: Layouts and Viewports

08-19-2011 03:26 PM in reply to: StephenPreston

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

Valued Mentor
fieldguy
Posts: 382
Registered: ‎03-31-2005
Message 5 of 15 (1,772 Views)

Re: Layouts and Viewports

09-01-2011 10:32 AM 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?  

Mentor
JamieVJohnson2
Posts: 170
Registered: ‎08-26-2010
Message 6 of 15 (1,768 Views)

Re: Layouts and Viewports

09-01-2011 11:12 AM 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
Valued Mentor
cadMeUp
Posts: 331
Registered: ‎05-11-2006
Message 7 of 15 (1,756 Views)

Re: Layouts and Viewports

09-01-2011 04:44 PM in reply to: fieldguy
If a lay
Valued Mentor
cadMeUp
Posts: 331
Registered: ‎05-11-2006
Message 8 of 15 (1,752 Views)

Re: Layouts and Viewports

09-01-2011 04:55 PM 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!

Valued Mentor
fieldguy
Posts: 382
Registered: ‎03-31-2005
Message 9 of 15 (1,710 Views)

Re: Layouts and Viewports

09-02-2011 10:58 AM 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.   

Valued Mentor
fieldguy
Posts: 382
Registered: ‎03-31-2005
Message 10 of 15 (1,652 Views)

Re: Layouts and Viewports

09-12-2011 08:20 AM 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

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.