0

I would like to select an object just within 1 line instead of the whole schematic I have.

So far I used the selection by object ID

If Vshp.Name Like "*UG*" Then
Debug.Print Vshp.ID & " - " & Vshp.Master.Name
sel.Select Vshp, visSelect
'sel.Selection.Align visHorzAlignNone, visVertAlignMiddle, False
End If
Next

but it looks like everything I apply thereafter refers to the primarily selected shape, which is underneath.

https://learn.microsoft.com/en-us/office/vba/api/visio.selection.align

In the image, I marked the example of the area I would like to have selected. Then apply the changes. Unfortunately, I have no idea how to grab this particular section of my schematic.

Is there a way of selecting the bunch of objects for example by their color? Or something?

Geographos
  • 827
  • 2
  • 23
  • 57

1 Answers1

0

You can separate objects on page by layers. Each layer can have color. Visio layer properties window
You can use Create Selection method with option by layer. With syntax like

 Dim vsoLayer As Visio.Layer
    Dim vsoSelection As Visio.Selection
    Dim sh as visio.shape

    Set vsoLayer = ActivePage.Layers.ItemU("a")
    Set vsoSelection = ActivePage.CreateSelection(visSelTypeByLayer, visSelModeSkipSuper, vsoLayer)

Also you can select multiple layers with code

Dim vsoSelection1 As Visio.Selection
Set vsoSelection1 = Application.ActiveWindow.Page.CreateSelection(visSelTypeByLayer, visSelModeSkipSuper, "a;c")
Application.ActiveWindow.Selection = vsoSelection1

You wrote

I used the selection by object ID

There is selection by name, if shape name contain UG...


I took a close look at your picture.
Stranges I'm not sure that you can programmatically determine which branch which figures belong to.

For example NRTH-X-AF01BB! there are two lines on the input: yellow and red.
The output are two yellow lines.

I have found that it is better to manually assign shapes to certain layers...

Surrogate
  • 1,466
  • 2
  • 11
  • 13
  • Your solution triggers another question - how to create layers in Visio programmatically. – Geographos Apr 19 '23 at 15:51
  • No, it is just suggestion use layers! My codes are showing how select single and multiple existing layer(s)... – Surrogate Apr 19 '23 at 17:33
  • I would rather to avoid layers and use something like ordering from the very top – Geographos Apr 20 '23 at 13:59
  • What do you mean as _ordering from the very top_? – Surrogate Apr 20 '23 at 14:32
  • I wish I could send you my file and explain to you all the steps I need to resolve. Once I have the schematic, I need to have the elements selected not in the standard manner, but rather in sections (divided by colors or "levels" in which they have been drew). – Geographos Apr 20 '23 at 14:47
  • Unfortunately, I am not a telepath. I don't understand what `levels` are in your context? Post a simple document with no confidential information in the cloud and share the link – Surrogate Apr 20 '23 at 14:55
  • Please try to use this link: https://www.dropbox.com/s/fjsi5cpy61wl5bi/Sample%20scematic2E.vsdm?dl=0 – Geographos Apr 20 '23 at 14:57
  • Thank you for share your document, it helped for answer in [other thread](https://stackoverflow.com/questions/76056627/vba-visio-cannot-change-font-size-in-the-element)! But i dont understand 'level' meaning... – Surrogate Apr 21 '23 at 07:47
  • I mean, the particular "branch" of the schematic. As you can see, you have the main joint, from which a dozen or so branches come out. They're usually in one colour, in which I would like to base my selection for further alignment. – Geographos Apr 21 '23 at 07:50
  • I changed my answer a few years ago. But I just now realized that in your example, some shapes were not aligned correctly – Surrogate Apr 21 '23 at 20:30
  • Is there a chance to pick them up by color? How could I investigate to which group this color belongs to? – Geographos Apr 24 '23 at 09:22
  • You mean when use layers? If so, that not so complex! Just iterate layers, chech their colors, show user form where you can select some color... Just as idea – Surrogate Apr 24 '23 at 14:29