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

Cycle Through all Viewports

4 REPLIES 4
Reply
Message 1 of 5
pellacad
2249 Views, 4 Replies

Cycle Through all Viewports

Does anyone know how to properly cycle through all viewports in a drawing?

I'm using this code:
***************************************************************************************
Dim Vport As Autodesk.AutoCAD.Interop.Common.AcadViewport

For Each Vport In objAcad.ActiveDocument.Viewports

MsgBox("PVport = " & Vport.Width & vbCr & _
"ObjectID = " & Vport.ObjectID.ToString)

Next Vport
***************************************************************************************

This code seems to just display paperspace info regarding each tab in my drawing.

Your help and expertise will be greatly appreciated.
4 REPLIES 4
Message 2 of 5
cadMeUp
in reply to: pellacad

The attached file might give you an idea how to go about it. The source uses the managed objects and not the Interop objects. It just goes thru each layout in the dwg and prints the number, width, and height of each viewport.
One thing to note, the ARX Documentation states for the method 'AcDbLayout::getViewportArray()':
{color:#333333}{color:#333333}"This function returns an array of AcDbObjectIds of all the AcDbViewports that exist in the AcDbLayout's paperspace. The first ID in the list will be the paperspace viewport. If the list returned is empty, then this AcDbLayout has never been switched to (activated). The list is updated each time a layout is activated, and kept up-to-date while that layout is active (whenever viewports are added or deleted)."
{color}
{color}That would apply to the 'Layout.GetViewports()' method call in VB or C#. So keep in mind that a Layout has to have been 'activated' to return any of it's viewports.

Message 3 of 5
pellacad
in reply to: pellacad

cadmeup,

Thanks for the great code...

I'm developing an exe in VB.NET (VS 2005)...the program runs externally from ACAD, starting it if it isn't already running.

Your code is runs via the NETLOAD command, so it gets all its hooks from the current running session of ACAD.

I have a small, concise little sub that runs through the drawing activating each layout tab, doing a zoom-extents, even opening modelspace and doing a zoom-extents, then moving on to the next layout tab.

Could you help me get this Viewport sub ported over to use the Interop side of things?
Message 4 of 5
e.g.
in reply to: pellacad

Try to use the AcadPViewport object in your routine.

Or, depends of what you want to do, you can use cadmeup's code and call that specific routine.

E.G.
Message 5 of 5
cadMeUp
in reply to: pellacad

Ok, I see... Going the Acad* objects route, I guess if you have each AcadLayout object, you can get the block object of the layout and just loop thru the items in the AcadBlock checking to see if each one is an AcadPViewport object:
{code}
Dim layout as AcadLayout = someLayout
Dim layoutBlock as AcadBlock = someLayout.Block
For i As Integer = 0 To layoutBlock.Count
Dim ent As AcadEntity = layoutBlock.Item(i)
If TypeOf ent Is AcadPViewport Then
Dim vp As AcadPViewport = CType(ent, AcadPViewport)
...
End If
Next
{code}

The ActiveX/VBA ref states for AcadLayout:
"The representation of a layout is slightly different in ActiveX from that of the AutoCAD user interface. In ActiveX, the content of a standard AutoCAD layout is broken out into two separate objects: Layout object and Block object. The Layout object contains the plot settings and the visual properties of the layout as it appears in the AutoCAD user interface. The Block object contains the geometry for the layout.

Each Layout object is associated with one Block object. To access the Block object associated with a given layout, use the Block property. Conversely, each Block object is associated with one Layout object. To access the Layout object associated with a given Block, use the Layout property for that block.

In ActiveX, in addition to the paper space layouts, model space is considered a layout."

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