Getting shape's in a layer

J

jarlen

Hey
I'm building a Visio diagram that's mostly handled through macros. Most of
the features is simulated by making layers in-/visible. But as the diagram
gets larger the performance drops drastically, and one of the problems is
that I can't seem to get a list of all shapes in a layer, so what I do now is
to look at ALL shapes in the diagram, and go through all of the layers they
are part of, to check if they are part of the layer I'm working with. Doing
this takes a while, even with loops in a macro, isn't there any way to do
this faster?
 
P

Paul Herber

Hey
I'm building a Visio diagram that's mostly handled through macros. Most of
the features is simulated by making layers in-/visible. But as the diagram
gets larger the performance drops drastically, and one of the problems is
that I can't seem to get a list of all shapes in a layer, so what I do now is
to look at ALL shapes in the diagram, and go through all of the layers they
are part of, to check if they are part of the layer I'm working with. Doing
this takes a while, even with loops in a macro, isn't there any way to do
this faster?

That is the normal, correct way to do it,, however, iterating through
the shapes shouldn't take too long, even with hundreds of shapes on a
page.

Another way would be to make all layers invisble except for the
required layer(s), then select all shapes and iterate through the
selection.

Individual macros have an overhead for Undo and setting up document
references so re-writing the macros might be worth while.
 
S

sbmack7

That is the normal, correct way to do it,, however, iterating through
the shapes shouldn't take too long, even with hundreds of shapes on a
page.

Another way would be to make all layers invisble except for the
required layer(s), then select all shapes and iterate through the
selection.

Individual macros have an overhead for Undo and setting up document
references so re-writing the macros might be worth while.

jarlen,

To add to what Paul has said, most Visio novices make the assumption
that a Layer is a "container" of Shapes. In Shape selection using VB,
a Layer is not considered a container. Rather more like a property of
the Shape. So you can't cycle through a Layer with For Each loops
like you would expect to. However a Group is a Shape that contains
other Shapes. So you can cycle through a Group using For Each and
operate on every Shape member of the Group. So you could create a
Group with the same Shape objects as layer to do what you want. The
guys here have more efficient ways of doing things. But understanding
Layers is the point I want to make here.

BTW, I was a novice caught up in Layer confusion until guys like Paul
set me straight.

SteveM
 
J

jarlen

Ok, it seems to me like it takes a while, I have a few hundred shapes.
I got about 100 different boxes and stuff, that I'm showing all of the time,
what I'm switching on/off is their connectors , and datagraphics for both
connectors, and all the other shapes.

I'm not sure what you mean by this:
"> Individual macros have an overhead for Undo and setting up document
references so re-writing the macros might be worth while."

Are you talking about references to objects in my diagram, like shapes and
layers?
In the beginning of the function I save the reference for the layer I'm
working with, and I then save the individual shapes and the layers they are
part of, while iterating through it all (only on shape and one layer saved at
the time), I'm not sure I can put down the reference count any.
 
S

sbmack7

Ok, it seems to me like it takes a while, I have a few hundred shapes.
I got about 100 different boxes and stuff, that I'm showing all of the time,
what I'm switching on/off is their connectors , and datagraphics for both
connectors, and all the other shapes.

I'm not sure what you mean by this:
"> Individual macros have an overhead for Undo and setting up document
references so re-writing the macros might be worth while."

Are you talking about references to objects in my diagram, like shapes and
layers?
In the beginning of the function I save the reference for the layer I'm
working with, and I then save the individual shapes and the layers they are
part of, while iterating through it all (only on shape and one layer saved at
the time), I'm not sure I can put down the reference count any.

Paul Herber said:
On Mon, 4 Aug 2008 04:13:00 -0700, jarlen
That is the normal, correct way to do it,, however, iterating through
the shapes shouldn't take too long, even with hundreds of shapes on a
page.
Another way would be to make all layers invisble except for the
required layer(s), then select all shapes and iterate through the
selection.
Individual macros have an overhead for Undo and setting up document
references so re-writing the macros might be worth while.

I've been away from Visio for a while. But I was able to dig out a
couple of examples for you. Here's one in which the Shapes associated
with a Layer are Selected:

Sub ShapesInLayer()
Dim vShp As Shape
Dim vsoSelection1 As Visio.Selection
' RedShapes is the name of th e Layer
Set vsoSelection1 =
Application.ActiveWindow.Page.CreateSelection(visSelTypeByLayer,
visSelModeSkipSuper, "RedShapes")
For Each vShp In vsoSelection1
vShp.Name = vShp.CellsSRC(Visio.visSectionProp, 0,
visCustPropsValue)
Debug.Print vShp.Name & " " & vShp.NameU
Next
End Sub

In the above case the technique is to use a Selection as the Shape
"container"

Here's an example of a Group being a Shape that is also a container of
Shapes:

For Each vShape In grpShape.Shapes
shapeNum = vShape.Name
vShape.CellsSRC(Visio.visSectionUser, 2, visUserValue) =
modelVars(shapeNum).Activity
vShape.DataGraphic = ActiveDocument.Masters("DG_IsBasic")
Next

A lot of good sample code can be found here:

http://visio.mvps.org/VBA.htm

Note that at that site, there are 2 examples of selecting Shapes in a
Layer. The first one doesn't work properly.

Also note that a DataGraphic is NOT explicitly assigned to a Layer
with its parent Shape. So if you cycle through a Layer to hide the
Shapes, the DataGraphic Objects will remain on the screen. So when
you cycle through the Shapes, you must also set the Shape DataGraphic
to Nothing.

Lastly, the are many ways to do things in Visio. Different guys have
different methods. Given that the Visio Help System stinks, I think
most guys do trial and error until they got something that works and
then stick with it.

'SteveM
 
J

John... Visio MVP

A lot of good sample code can be found here:
http://visio.mvps.org/VBA.htm

Note that at that site, there are 2 examples of selecting Shapes in a
Layer. The first one doesn't work properly.

'SteveM


Interesting site, but that guy needs to get his act together, the website is
long overdo for an update. ;-)

So were you able to determine why the second example does not work properly?

John... Visio MVP
http://Visio.MVPS.org
 
J

jarlen

sbmack > Your first example is just what I need. As per your note I need the
"shapes by layer" exactly to be able to hide/show datagraphics, if it were
just the shapes themselves, I'd just hide/show the layer. Thanks for the
example, it seems to work fine.
I've looked at the site you linked to, but I'm not too happy about it. Like
you say, the first of his examples describing my problem doesn't work,
because he selects all the shapes on the page containing the layer. Not just
the shapes in the layer itself. :)
 
S

sbmack7

Interesting site, but that guy needs to get his act together, the websiteis
long overdo for an update.  ;-)

So were you able to determine why the second example does not work properly?

John... Visio MVPhttp://Visio.MVPS.org

John,

That was a while ago. But I think the For Each code acted on Shapes
that were not part of the Layer. Rather than do a diagnosis, I just
used a different strategy.

SteveM
 

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