Invert a selection (Visio Drawing Control)

P

peter.bittner

Hi!

I am using the Visio Drawing Control from within an application I write
in C#.

I want to invert the current selection (select all unselected, deselect
all selected shapes), but I can't find a way to get to know the state
of "selected" or "not selected" when I iterate through all shapes, e.g.

for (int i = 1; i <= Visio.App.ActivePage.Shapes.Count; i++)
{
Shape shp = Visio.App.ActivePage.Shapes;
if (shp " is selected " )
Visio.App.ActiveWindow.Select(shp,
(short) VisSelectArgs.visDeselect);
else
Visio.App.ActiveWindow.Select(shp,
(short) VisSelectArgs.visSelect);
}

Can I only do this through getting the current selection? I can't get
this to work either:

Selection sel = Visio.App.ActiveWindow.Selection;
Visio.App.ActiveWindow.SelectAll();

for (int i = 1; i <= sel.Count; i++)
for (int j = 1; j <= sel.Shapes.Count; j++)
Visio.App.ActiveWindow.Select(sel.Shapes[j],
(short) VisSelectArgs.visDeselect);

(The code above litterally does nothing since "j <=
sel.Shapes.Count" irritatingly always evaluates to false.)

Or is there a ready-to-use command I can send to Visio (well, to the
drawing control) to invert the selection of the active window or
document?

Peter
 
J

JuneTheSecond

My idea is to make a collection.
Though it is in VBA, you might see the outline.
Sub test()
Dim mySelection As Collection
Set mySelection = New Collection
Dim shp As Visio.Shape

For Each shp In ActiveWindow.Selection
mySelection.Add shp
Next

ActiveWindow.SelectAll

For Each shp In mySelection
ActiveWindow.Select shp, visDeselect
Next
End Sub
 
M

Mark Nelson [MS]

Peter, sel.Shapes.Count means get the number of sub-shapes that exist
within each of the shapes in the selection. If the selected shapes are not
groups, this will return zero. Think of a Selection as being equivalent to
a Shapes collection. Sel.Shapes is the same as Shapes.Item(i).Shapes.

Try using something similar to June's code below.

--
Mark Nelson
Office Graphics - Visio
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.

JuneTheSecond said:
My idea is to make a collection.
Though it is in VBA, you might see the outline.
Sub test()
Dim mySelection As Collection
Set mySelection = New Collection
Dim shp As Visio.Shape

For Each shp In ActiveWindow.Selection
mySelection.Add shp
Next

ActiveWindow.SelectAll

For Each shp In mySelection
ActiveWindow.Select shp, visDeselect
Next
End Sub
--
JuneTheSecond



Hi!

I am using the Visio Drawing Control from within an application I write
in C#.

I want to invert the current selection (select all unselected, deselect
all selected shapes), but I can't find a way to get to know the state
of "selected" or "not selected" when I iterate through all shapes, e.g.

for (int i = 1; i <= Visio.App.ActivePage.Shapes.Count; i++)
{
Shape shp = Visio.App.ActivePage.Shapes;
if (shp " is selected " )
Visio.App.ActiveWindow.Select(shp,
(short) VisSelectArgs.visDeselect);
else
Visio.App.ActiveWindow.Select(shp,
(short) VisSelectArgs.visSelect);
}

Can I only do this through getting the current selection? I can't get
this to work either:

Selection sel = Visio.App.ActiveWindow.Selection;
Visio.App.ActiveWindow.SelectAll();

for (int i = 1; i <= sel.Count; i++)
for (int j = 1; j <= sel.Shapes.Count; j++)
Visio.App.ActiveWindow.Select(sel.Shapes[j],
(short) VisSelectArgs.visDeselect);

(The code above litterally does nothing since "j <=
sel.Shapes.Count" irritatingly always evaluates to false.)

Or is there a ready-to-use command I can send to Visio (well, to the
drawing control) to invert the selection of the active window or
document?

Peter
 
P

peter.bittner

Mark,

can I perform a deselect with a selection item only?

My problem in the code above is that I need to extract the shapes out
of each selection (which is obviously wrong as you suggest -- the
selection item itself more or less already represents the selected
shape or so). I Need to do this, because I only know how to deselect
using a shape instance!

Is there no way to get the shape itself, the shape represented by the
selection?

Peter

Peter, sel.Shapes.Count means get the number of sub-shapes that exist
within each of the shapes in the selection. If the selected shapes are not
groups, this will return zero. Think of a Selection as being equivalent to
a Shapes collection. Sel.Shapes is the same as Shapes.Item(i).Shapes.

Try using something similar to June's code below.

--
Mark Nelson
Office Graphics - Visio
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.

JuneTheSecond said:
My idea is to make a collection.
Though it is in VBA, you might see the outline.
Sub test()
Dim mySelection As Collection
Set mySelection = New Collection
Dim shp As Visio.Shape

For Each shp In ActiveWindow.Selection
mySelection.Add shp
Next

ActiveWindow.SelectAll

For Each shp In mySelection
ActiveWindow.Select shp, visDeselect
Next
End Sub
--
JuneTheSecond



Hi!

I am using the Visio Drawing Control from within an application I write
in C#.

I want to invert the current selection (select all unselected, deselect
all selected shapes), but I can't find a way to get to know the state
of "selected" or "not selected" when I iterate through all shapes, e.g.

for (int i = 1; i <= Visio.App.ActivePage.Shapes.Count; i++)
{
Shape shp = Visio.App.ActivePage.Shapes;
if (shp " is selected " )
Visio.App.ActiveWindow.Select(shp,
(short) VisSelectArgs.visDeselect);
else
Visio.App.ActiveWindow.Select(shp,
(short) VisSelectArgs.visSelect);
}

Can I only do this through getting the current selection? I can't get
this to work either:

Selection sel = Visio.App.ActiveWindow.Selection;
Visio.App.ActiveWindow.SelectAll();

for (int i = 1; i <= sel.Count; i++)
for (int j = 1; j <= sel.Shapes.Count; j++)
Visio.App.ActiveWindow.Select(sel.Shapes[j],
(short) VisSelectArgs.visDeselect);

(The code above litterally does nothing since "j <=
sel.Shapes.Count" irritatingly always evaluates to false.)

Or is there a ready-to-use command I can send to Visio (well, to the
drawing control) to invert the selection of the active window or
document?

Peter
 
P

peter.bittner

June,

wow, that works perfectly!

So, the answer to my latest question/posting is:
Extract shapes from a selection using 'foreach (Shape shp in
theSelection)'!

Thanks again!
Peter

My idea is to make a collection.
Though it is in VBA, you might see the outline.
Sub test()
Dim mySelection As Collection
Set mySelection = New Collection
Dim shp As Visio.Shape

For Each shp In ActiveWindow.Selection
mySelection.Add shp
Next

ActiveWindow.SelectAll

For Each shp In mySelection
ActiveWindow.Select shp, visDeselect
Next
End Sub
--
JuneTheSecond



Hi!

I am using the Visio Drawing Control from within an application I write
in C#.

I want to invert the current selection (select all unselected, deselect
all selected shapes), but I can't find a way to get to know the state
of "selected" or "not selected" when I iterate through all shapes, e.g.

for (int i = 1; i <= Visio.App.ActivePage.Shapes.Count; i++)
{
Shape shp = Visio.App.ActivePage.Shapes;
if (shp " is selected " )
Visio.App.ActiveWindow.Select(shp,
(short) VisSelectArgs.visDeselect);
else
Visio.App.ActiveWindow.Select(shp,
(short) VisSelectArgs.visSelect);
}

Can I only do this through getting the current selection? I can't get
this to work either:

Selection sel = Visio.App.ActiveWindow.Selection;
Visio.App.ActiveWindow.SelectAll();

for (int i = 1; i <= sel.Count; i++)
for (int j = 1; j <= sel.Shapes.Count; j++)
Visio.App.ActiveWindow.Select(sel.Shapes[j],
(short) VisSelectArgs.visDeselect);

(The code above litterally does nothing since "j <=
sel.Shapes.Count" irritatingly always evaluates to false.)

Or is there a ready-to-use command I can send to Visio (well, to the
drawing control) to invert the selection of the active window or
document?

Peter
 

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