Selection bounding box not including subshapes

A

Andy

I'm selecting an area of diagram, which gives me a selection
containing some enclosed shapes. However, some of these shapes have
subshapes that extend some distance outside of their parent shape.

If I get the bounding box for the selection, it includes these
subshapes in the returned dimensions of the bounding box. I'm trying
to get a bounding box of only the parent shapes, much like the
dimensions of the selection box shown by Visio around the selected
shapes.
 
P

Paul Herber

I'm selecting an area of diagram, which gives me a selection
containing some enclosed shapes. However, some of these shapes have
subshapes that extend some distance outside of their parent shape.

If I get the bounding box for the selection, it includes these
subshapes in the returned dimensions of the bounding box. I'm trying
to get a bounding box of only the parent shapes, much like the
dimensions of the selection box shown by Visio around the selected
shapes.

menu Tools -> Options -> General
and turn off "Select shapes partially within area"
 
A

Andy

menu Tools -> Options -> General
and turn off "Select shapes partially within area"

That is already turned off. I'm getting the bounding box via VBA,
using the bounding box method of the selection. This seems to include
the subshapes regardless.
 
A

Andy

That is already turned off. I'm getting the bounding box via VBA,
using the bounding box method of the selection. This seems to include
the subshapes regardless.

Or is there a way I can get the alignment box size/position, than the
shapes height/width?
 
J

JuneTheSecond

Hi,

How would you like to calculate from the geometry of parent shape?
For example Left=PinX-LocPinX, Right=PinY-LocPinY+Width
 
A

Andy

Hi,

How would you like to calculate from the geometry of parent shape?
For example Left=PinX-LocPinX, Right=PinY-LocPinY+Width

I was hoping to do it without having to calculate it all myself, I
would have to allow for rotation and flipping.
 
J

JuneTheSecond

Andy,

DrawRegion may be useful, for ex.
Sub testDrawRegion()
Dim L As Double, B As Double, R As Double, T As Double
Dim shp As Visio.Shape, shpChild As Visio.Shape, shpReg As Visio.Shape,
shpRect As Visio.Shape
Dim I As Long, N As Long
Set shp = ActiveWindow.Selection(1)
For Each shpChild In shp.Shapes
N = shpChild.GeometryCount
For I = 0 To N - 1
shpChild.CellsSRC(visSectionFirstComponent + I, 0, 2).FormulaU =
True
Next
Next
Set shpReg = ActiveWindow.Selection.DrawRegion(0, 0)
For Each shpChild In shp.Shapes
N = shpChild.GeometryCount
For I = 0 To N - 1
shpChild.CellsSRC(visSectionFirstComponent + I, 0, 2).FormulaU =
False
Next
Next
L = shpReg.Cells("PinX") - shpReg.Cells("LocPinX")
R = L + shpReg.Cells("Width")
B = shpReg.Cells("PinY") - shpReg.Cells("LocPinY")
T = B + shpReg.Cells("Height")
Debug.Print L, B, R, T

Set shpRect = ActivePage.DrawRectangle(L, B, R, T)
shpRect.SendToBack
shpReg.Delete
End Sub
 
J

JuneTheSecond

Hi,

shpReg.BoundingBox visBBoxUprightWH, L, B, R, T
may be preferred than
L = shpReg.Cells("PinX") - shpReg.Cells("LocPinX")
R = L + shpReg.Cells("Width")
B = shpReg.Cells("PinY") - shpReg.Cells("LocPinY")
T = B + shpReg.Cells("Height")
 
P

Paul Herber

That is already turned off. I'm getting the bounding box via VBA,
using the bounding box method of the selection. This seems to include
the subshapes regardless.

Not always, I can create groups such that when part of a selection
subshapes are not included within the selection.
If it's important I'll tell you how.
 
A

Andy

Not always, I can create groups such that when part of a selection
subshapes are not included within the selection.
If it's important I'll tell you how.

Maybe if I describe what I'm trying to achieve,

I am selecting an area of my diagram (using the mouse) to bound the
selection. This then gives me a selection containing all the visible
shapes. However, in the same area there may be some hidden shapes
(controlled by layers & formulas in shapes). To detect this, I then
get the bounding area of the selection and find all the sahpes that
are within the selections bounding box. If there is a difference in
number, the user is given a warning to say there are hidden shapes not
included in the selection.

This works fine, until I have shapes that go outside there alignment
box. The bounding box returned for the selection seems to includes the
subshapes. This gives me a much larger area, that then includes shapes
I'm not interested in (outside the selections visible area), so gives
the user a false message.
 
P

Paul Herber

Maybe if I describe what I'm trying to achieve,

I am selecting an area of my diagram (using the mouse) to bound the
selection. This then gives me a selection containing all the visible
shapes. However, in the same area there may be some hidden shapes
(controlled by layers & formulas in shapes). To detect this, I then
get the bounding area of the selection and find all the sahpes that
are within the selections bounding box. If there is a difference in
number, the user is given a warning to say there are hidden shapes not
included in the selection.

This works fine, until I have shapes that go outside there alignment
box. The bounding box returned for the selection seems to includes the
subshapes. This gives me a much larger area, that then includes shapes
I'm not interested in (outside the selections visible area), so gives
the user a false message.

I see your point, but I think there will always be a problem with
this, grouped shapes and shapes with multiple geometry sections could
have parts of their shape all over the place. A shape could cover the
whole page but not be part of any selection.
 
A

Andy

I see your point, but I think there will always be a problem with
this, grouped shapes and shapes with multiple geometry sections could
have parts of their shape all over the place. A shape could cover the
whole page but not be part of any selection.

In my case that is not an issue, as the shapes used on my drawings are
restricted to my own set of shapes and there would be no grouping of
these shapes.

Currently I have chosen to calculate the bounding box for each of the
shapes within the selection. I have handled the rotation, which again
is restricted to 0,90,180,270. Although not yet dealt with the
possibility of flipping.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top