Joining 2 shapes without a dynamic connector

Started by AntmanLFE, May 01, 2014, 01:38:02 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

AntmanLFE

I have created an addon that places 2 custom shapes onto a page although i am having an issue connecting them together. Let me try to explain.

The main shape i will refer to as shape1 has several labelled connection points on it. For instance the first connection point name is "Connections.UI01A"

I them place down a shape known as shape2 which has a single connection point whose name is "Connections.Row_1"

What i would like to do is place and join these 2 connection points on top of each other and join them together.

Any tips or direction on how i may be able to do this? Ive tried searching although that tends to come up with results using dynamic connectors as opposed to the 2 shapes being directly joined.

(Im working in c# although vb is suitable as well :) )

Paul Herber

Add a connection point to each shape at a common point where they are to be joined.
Make one connection point type=1 and the other to type=2.
Dragging one shape will pull the other with it, however, dragging the other will disconnect it.
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

vojo


AntmanLFE

So my main shape has connection point type 0 (Inward) and the second shape as a connection point type 1 (Outword)

I have tried recording a macro and replicating it programatically although i keep running into "Inappropriate source object for this action"
Understandable the macro is referencing an id so i have had to modify it as it itself wont run twice if i separate the shapes and run the macro again

I have tried this a few ways although i always get the same error.

Here is one failed attempt

IVisio.Cell vsoCell1, vsoCell2;

vsoCell1 = shape1.get_CellsSRC(
                (short)IVisio.VisSectionIndices.visSectionConnectionPts, 0, 0);

vsoCell2 = shape2.get_CellsSRC(
                (short)IVisio.VisSectionIndices.visSectionConnectionPts, 0, 0);

vsoCell2.GlueTo(vsoCell1);


wapperdude

Not sure which version you're using, or if it matters, but, in V2007, ran macro recorder to create initial macro.  Then, cleaned up the macro.  Here's resulting macro:

Sub ConnShapes()
    Dim vsoCell1, vsoCell2 As Cell
    ActiveWindow.DeselectAll
    Set vsoCell1 = ActiveWindow.Page.Shapes.ItemFromID(2).CellsSRC(visSectionConnectionPts, 1, 0)
    Set vsoCell2 = ActiveWindow.Page.Shapes.ItemFromID(1).CellsSRC(visSectionConnectionPts, 0, 0)
    vsoCell1.GlueTo vsoCell2
End Sub

Seems to run fine.  One issue is that the shape ID's are hard coded.
HTH
Wapperdude
Visio 2019 Pro

wapperdude

#5
It's possible to extend the process to catenate additional shapes, i.e., make a shape train.  For example, for 3 shapes you would have:

Sub ConnShapes()
    Dim vsoCell1, vsoCell2, vsoCell3 As Cell
    ActiveWindow.DeselectAll
    Set vsoCell2 = ActiveWindow.Page.Shapes.ItemFromID(2).CellsSRC(visSectionConnectionPts, 1, 0)
    Set vsoCell1 = ActiveWindow.Page.Shapes.ItemFromID(1).CellsSRC(visSectionConnectionPts, 0, 0)
    Set vsoCell3 = ActiveWindow.Page.Shapes.ItemFromID(3).CellsSRC(visSectionConnectionPts, 1, 0)
    vsoCell2.GlueTo vsoCell1
   
    Set vsoCell2 = ActiveWindow.Page.Shapes.ItemFromID(2).CellsSRC(visSectionConnectionPts, 0, 0)
    vsoCell3.GlueTo vsoCell2
End Sub

The key is to reset vsoCell2.  (Note: I've changed the definitions from my original reply such that there's a consistency in the cell numbering).

Anyway, it works.

Wapperdude
Visio 2019 Pro

AntmanLFE

Thanks for the reply.

I managed to get it to work consistently. The main problem i was having which i eventually found was that the shape was in an extra group. After i stepped down to the first sub shape i was able to successfully get the connection points to glue together.