visSelTypeByLayer did not find shapes in groups???

Started by DieterS, February 06, 2011, 05:41:07 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

DieterS

Hi,
has anyone ever managed to get visSelTypeByLayer working with shapes that are group members in Visio 2007?
I've created two rectangles on a blank sheet put them onto a layer "LAY1" and grouped the two.
The following code did not find them - were it does if they are not part of a group.

Sub Run()
    Dim visSel As Visio.Selection
    Dim visSh As Visio.Shape
    Set visSel = ActivePage.CreateSelection(visSelTypeByLayer, , "LAY1")
    For Each visSh In visSel
        Debug.Print visSh.NameID
    Next
End Sub

I have tried nearly every combination of iteration modes, but without success.
Is this a bug or is it supposed to work this way?

Of course, I could ask each shape for it's layer assignment, but I'am working on large schematics with 6000+ shapes. This would consume a considerable amount of time. So it's preferable that visio is doing al the search work.

Dieter


vojo

I am nowhere near as fluent as others on the forum, but its been my experience in the past that you pretty much have to
assume the activepage and activewindow is good for nothing more than the reference/transition point between the user selection and the world of VBA.
I.e. since the activewindow.selection changes all over the place (including renumbering items...item 1 = XXX....some VBA lines... now item 1 = YYY)
you pretty much have build up up your selection by interrogating the shapes

For example, I did a macro that will take a shape and make copies on any arbitrary angle and distance.   I added an undo function in there
such that it removed the new shapes, left the original as is....and activewindow.selection blew up.   So had to copy the
source shape into a master_shape....operate on on that (copy/paste the master_shape)...build up a my selection...then group it.

I had to do similar for a macro that extruded an arbitrary 2D shape into 3D (angle and depth).

Also, functions like spatialneighbor are pretty worthless...better off doing your own test than to rely on that worthless function.
(no real doc on the precision, precision appears to be nonlinear - 0.1 has dramatically different affect than 0.11, etc.)

I will be the first to say that I am a novice VBA programmer (I wanted to solve a problem not become fluent in a language)....so there
may be better ways to do this.

aledlund

as an observation your call
CreateSelection(visSelTypeByLayer, , "LAY1")
is asking for selection by layer and you are passing it a string that appears to be a layer name("LAY1") when it should be asking for a layer object

You might check this out as an example....
http://msdn.microsoft.com/en-us/library/ff767064.aspx

al

DieterS

you are right, al
the docs says, that CreateSelection expects a layer object.
But the call is indeed also accepting a string containing a layer name.
The given code runs fine - if the objects are not within groups.
Since the parameter is actually a Variant, Visio seems to apply some smartness when interpreting the content.
The official docs are missing this point.

Dieter

aledlund

Dieter,
Are you also trying to get the names of the subshapes of a group? If that is what your attempting, you should first test that the shape you have gotten is a group shape ( if visSh.type = visTypeGroup), then make it a selection and loop through it just like you're doing with the parent shape.
al

DieterS

the basic question is: how to get m shapes out of n shapes very quickly?
The quickest way is letting Visio do the searching. m is mostly < 10 where n can be 10000+ shapes. And yes, we have customers with that huge drawings.
The user is free to structure the drawing as she wants. So the shapes in question may end up in a group. But they are on a layer. So they should be found easily.
These shapes are some kind of "marker" shapes. They have frequently to be found and just deleted (e.g. when saving the drawing). This done by and AddOn.
The code IS working right now by manually checking all shapes (recursive in case of a group).
I'am just searching for a faster way, because customers a complaining about performance as drawings are getting larger and larger.

Dieter

aledlund

When I'm working with a drawing that may require searching for shapes I try to take advantage of dictionaries tied to page events. When the user changes the page I inventory all of the shapes and save the shapeids and identifying information in dictionaries/collections so that I can search inside my code rather than constantly going back to the page/shapes/subshapes.
al