Trying to select PViewport objects

Trying to select PViewport objects

Anonymous
Not applicable
1,423 Views
9 Replies
Message 1 of 10

Trying to select PViewport objects

Anonymous
Not applicable
Greetings all.

I'm (very) new to VBA and I'm struggling along, but I'm completely confused now. Using the following code, I can create a new PViewport object but I can't select it. However, if I change the FilterData(0) variable to "Viewport", I can. That seems really wrong to me. Unforunately, it also picks up the master viewports (layout and modelspace) as well, which I don't want.

Can someone please explain how to select the viewports on a layout without picking the master viewports as well?

Thanks in anticipation,
Trevor

---

Sub Viewport_Test()

Dim VPSelection As AcadSelectionSet
Dim TestVP As AcadPViewport
Dim TVPCenter(2) As Double
Dim TVPWidth As Double
Dim TVPHeight As Double

'Create PViewport object
TVPCenter(0) = 30: TVPCenter(1) = 30: TVPCenter(2) = 0
TVPWidth = 50: TVPHeight = 40

Set TestVP = ThisDrawing.PaperSpace.AddPViewport(TVPCenter, TVPWidth, TVPHeight)

'Select Viewports
Set VPSelection = ThisDrawing.SelectionSets.Add("ABC")
Dim FilterType(1) As Integer
Dim FilterData(1) As Variant

FilterType(0) = 0: FilterData(0) = "Viewport"
FilterType(1) = 67: FilterData(1) = 1
Call VPSelection.Select(acSelectionSetAll, , , FilterType, FilterData)

'List Selection Set info
MsgBox ("There are now " + CStr(VPSelection.Count) + " objects in the Selection Set.")

'Clean up
TestVP.Delete
ThisDrawing.SelectionSets.Item("ABC").Delete

End Sub
0 Likes
1,424 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable
Play with this modification to see if any issues arrise. It seems like it excludes the "Master" viewport in a selection set.


The post editor is having trouble dealing with the DXF code portion of my post. I'll attach it to a follow up post. Message was edited by: SEANT
0 Likes
Message 3 of 10

Anonymous
Not applicable
Hopefully this works better.
0 Likes
Message 4 of 10

Anonymous
Not applicable
Thanks for that, Sean, I really appreciate you taking the time to throw that together for me. It does work nicely as advertised.

Question that arises: It seems to me that you've selected all the VIEWPORTS in all Layouts and filtered out the first one of each Layout, the one associated with the Layout object; you haven't selected any PViewport objects: why VIEWPORTS and not PViewports? (Sorry, that sentence is a bit of a mouthful, isn't it? It does make sense though.)

I got the impression that that's why there is a PViewport object listed in the VBA documentation, so that the dedicated paperspace viewports could be selected as being distinct from the windows we normally work through. If that's wrong, what IS a PViewport?

Thanks
Trevor Message was edited by: T_Bernhard
0 Likes
Message 5 of 10

Anonymous
Not applicable
I think there is a difference in terminology between VBA and DXF with regard to viewports. DXF 'Viewport' = VBA 'PViewport'.

The experiments I've given the routine - multiple modelspace viewports and multiple Paperspace (floating) viewports - return the correct amounts.

There is a caveat, however. With a freshly opened drawing, each layout must be activated to initialize the 'Main' viewport for isolation. This thread:

http://www.theswamp.org/index.php?topic=10992.0

elaborates on the issue. It discusses a similar Lisp routine, but the issue seems to apply to VBA as well.

I'm still trying to translate their solution to VBA but not having much luck. See what you can make of it.
0 Likes
Message 6 of 10

Anonymous
Not applicable
A viewport is the original legacy viewport with no irregular boundary
support. A viewport is created when you use mview and draw a basic
rectangle. A Pviewport is a viewport that can have a poly line for a
boundary. A pviewport supports clipping and other features that the legacy
viewport does not. You can not use vba to select a a pViewport intuitively.
You can not just select a pViewport on the screen. When selecting a
Pviewport with vba utilities you may get a polyline. You will have to build
a function to handle the polyline that you select and check its object
limits with any viewport objects in the paperspace that you are working in.
When you find a match then you set your pviewport object accordingly. The
api that shows the realationshop between the polyline and the pViewport is
missing with VBA, atleast with 2006.

In short, when you use autocad selection methods you may grab a viewport,
pviewport, or a polyline when you select a viewport from paperspace.
--
CB



wrote in message news:5576746@discussion.autodesk.com...
Thanks for that, Sean, I really appreciate you taking the time to throw that
together for me. It does work nicely as advertised.

Question that arises: It seems to me that you've selected all the VIEWPORTS
in all Layouts and filtered out the first one of each Layout, the one
associated with the Layout object; you haven't selected any PViewport
objects: why VIEWPORTS and not PViewports? (Sorry, that sentence is a bit of
a mouthful, isn't it? It does make sense though.)

I got the impression that that's why there is a PViewport object listed in
the VBA documentation, so that the dedicated paperspace viewports could be
selected as being distinct from the windows we normally work through. If
that's wrong, what IS a PViewport?

Thanks
Trevor

Message was edited by: T_Bernhard
0 Likes
Message 7 of 10

Anonymous
Not applicable
That certainly explains it. Thanks for the heads up.
0 Likes
Message 8 of 10

Anonymous
Not applicable
Wow, quite an explanation, thanks CB.

[clip]
"A pviewport supports clipping and other features that the legacy viewport does not. You can not use vba to select a a pViewport intuitively. You can not just select a pViewport on the screen. When selecting a Pviewport with vba utilities you may get a polyline."
[end clip]

So, if I'm understanding this correctly, all viewports are Viewport objects, but some viewports in paperspace have _additional_ capabilities that are accessed via the PViewport properties. Have I got that right?

Trevor
0 Likes
Message 9 of 10

Anonymous
Not applicable
All viewports can be filtered as an acdbviewport. If a viewport in
paperspace is selected with autocad commands then the selected object may
show up as an acdbviewport but in the case of an irregular viewport it may
be an acbdpolyline. An irregular viewport will display as either a
acdbviewport or and acdbpolyline. When you select an irregular viewport and
check the properties you will notice two items. A polyline and a viewport.
With a standard viewport there will be only one item.

When I declare a viewport object I set it as ' DIM VP as AcadPViewport '
and not as a viewport. Using the AcadPViewport will catch any clipped or
irregular viewports. Once you have a collection of all the AcadViewports in
paperspace you can match the correct viewport with the boundary limits of
the acdbpolyline that was select in the case of a clipped viewport. I could
not find any way stright VBA or outside activex calls to determine the
relationship between the polyline selection and the corresponding viewport.
I had to itterate all the viewports and match them to the polyline.
Hopefully that makes more sense.
--
CB


wrote in message news:5577936@discussion.autodesk.com...
Wow, quite an explanation, thanks CB.

[clip]
"A pviewport supports clipping and other features that the legacy viewport
does not. You can not use vba to select a a pViewport intuitively. You can
not just select a pViewport on the screen. When selecting a Pviewport with
vba utilities you may get a polyline."
[end clip]

So, if I'm understanding this correctly, all viewports are Viewport objects,
but some viewports in paperspace have _additional_ capabilities that are
accessed via the PViewport properties. Have I got that right?

Trevor
0 Likes
Message 10 of 10

Anonymous
Not applicable
Okay, most of that makes sense. I guess the rest will come with practise and experience.

Many thanks, CB, for taking the time to explain that. Thanks also to you, Sean, for your assistance. Every little bit helps. 🙂

Trevor
0 Likes