Dropping a shape inside another shape - Visio 2013

Started by MrSir, August 19, 2014, 10:34:53 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

MrSir

Hello

Im using COM Interop to generate diagrams with C#. I cant figure out how to drop a shape inside another shape, i cant seem to find any methods for this on the shape object.
How do i drop a shape inside another shape?

Regards MrSir


MrSir

Hello Jumpy

No i dont want to group the shapes, i want to place a shape inside another shape, like the attached picture.

Regards MrSir

aledlund

retrieve the pinx/piny of shape1 (the outer shape) and then assign those values to shape2.
al

Yacine

Astonishing simple. It definitely helps reading carefully the question ;)
Yacine

MrSir

Quote from: aledlund on August 20, 2014, 03:25:52 AM
retrieve the pinx/piny of shape1 (the outer shape) and then assign those values to shape2.
al

Thanks, i have tried with the following code:


public void encapsulateShape(int outerShapeId, int innerShapeId) {
    Shape outerShape = visioPage.Shapes.get_ItemFromID(outerShapeId);
    Shape innerShape = visioPage.Shapes.get_ItemFromID(innerShapeId);

    int xCoord = outerShape.get_Cells("PinX").get_ResultInt(VisUnitCodes.visMillimeters, (short)0.0);
    int yCoord = outerShape.get_Cells("PinY").get_ResultInt(VisUnitCodes.visMillimeters, (short)0.0);

    Console.WriteLine(xCoord + " - " + yCoord);
    Console.ReadKey();

    innerShape.SetCenter((double)xCoord, (double)yCoord);
}


But nothing happens, the shape is not moved. How do i move the shape?

Regards MrSir

Jumpy

#6
I will assume that you tested that outershape and innershape are assigned and that xcoord, ycoord contain values.

From that I don't know, why the shape doesn't move, but if it would move, I don't know if it would move o the center of the outer shape, because your X/Y coordinates are in milimeter and the build in Visio functions normally expect the values in inch.
And no matter which measurements you use Xcoord/ycoord should be doubles not integers.

Instead of using SetCenter you could set PinX/Y of the shape individually.

And the function only works when the LocPinX/Y are in the center of both shapes. If they are not, the formula for the exact values to place innershape get more complicated.

Last but not least you have to ensure that innershape has a higher Z-order so it will not be hidden behind outer shape.

Paul Herber

MrSir, I would really recommend downloading the Visio SDK, it has many examples of basic Visio coding like this.
Electronic and Electrical engineering, business and software stencils for Visio -

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