G
Gilgil0886
Hi!
I was looking for this code for a long time, and couldn't find it.
Basically what I wanted to do is make all the shapes in a drawing
properly visible & centered.
Here's the code:
public void AutoZoom()
{
if (m_bFirstTime)
return;
double dMaxTop, dMinLeft, dMinBottom, dMaxRight;
double dViewLeft, dViewTop, dViewWidth, dViewHeight;
VisWindow.GetViewRect(out dViewLeft, out dViewTop, out dViewWidth,
out dViewHeight);
dMaxTop = dMinBottom = dViewTop - dViewHeight / 2;
dMaxRight = dMinLeft = dViewLeft + dViewWidth / 2;
foreach (Visio.Shape shape in VisPage.Shapes)
{
double dPinX = shape.get_CellsU("PinX").get_Result("inches");
double dPinY = shape.get_CellsU("PinY").get_Result("inches");
double dWidth = shape.get_CellsU("Width").get_Result("inches");
double dHeight =
shape.get_CellsU("Height").get_Result("inches");
double dLeft = dPinX - dWidth / 2;
double dRight = dPinX + dWidth / 2;
double dTop = dPinY + dHeight / 2;
double dBottom = dPinY - dHeight / 2;
if (dMaxTop < dTop)
dMaxTop = dTop;
if (dMaxRight < dRight)
dMaxRight = dRight;
if (dMinLeft > dLeft)
dMinLeft = dLeft;
if (dMinBottom > dBottom)
dMinBottom = dBottom;
}
// Center drawing
VisWindow.ScrollViewTo((dMinLeft + dMaxRight) / 2, (dMaxTop +
dMinBottom) / 2);
// Fit all shapes into view
double dFitY = (dMaxTop - dMinBottom) * 1.1 / dViewHeight; // Take
10% more...
double dFitX = (dMaxRight - dMinLeft) * 1.1 / dViewWidth;
VisWindow.ZoomBehavior = Visio.VisZoomBehavior.visZoomVisioExact;
double dZoom = VisWindow.Zoom / System.Math.Max(dFitY, dFitX);
// Don't zoom in too much...
if (dZoom < 1)
VisWindow.Zoom = dZoom;
}
Your comments are welcome...
Enjoy!
I was looking for this code for a long time, and couldn't find it.
Basically what I wanted to do is make all the shapes in a drawing
properly visible & centered.
Here's the code:
public void AutoZoom()
{
if (m_bFirstTime)
return;
double dMaxTop, dMinLeft, dMinBottom, dMaxRight;
double dViewLeft, dViewTop, dViewWidth, dViewHeight;
VisWindow.GetViewRect(out dViewLeft, out dViewTop, out dViewWidth,
out dViewHeight);
dMaxTop = dMinBottom = dViewTop - dViewHeight / 2;
dMaxRight = dMinLeft = dViewLeft + dViewWidth / 2;
foreach (Visio.Shape shape in VisPage.Shapes)
{
double dPinX = shape.get_CellsU("PinX").get_Result("inches");
double dPinY = shape.get_CellsU("PinY").get_Result("inches");
double dWidth = shape.get_CellsU("Width").get_Result("inches");
double dHeight =
shape.get_CellsU("Height").get_Result("inches");
double dLeft = dPinX - dWidth / 2;
double dRight = dPinX + dWidth / 2;
double dTop = dPinY + dHeight / 2;
double dBottom = dPinY - dHeight / 2;
if (dMaxTop < dTop)
dMaxTop = dTop;
if (dMaxRight < dRight)
dMaxRight = dRight;
if (dMinLeft > dLeft)
dMinLeft = dLeft;
if (dMinBottom > dBottom)
dMinBottom = dBottom;
}
// Center drawing
VisWindow.ScrollViewTo((dMinLeft + dMaxRight) / 2, (dMaxTop +
dMinBottom) / 2);
// Fit all shapes into view
double dFitY = (dMaxTop - dMinBottom) * 1.1 / dViewHeight; // Take
10% more...
double dFitX = (dMaxRight - dMinLeft) * 1.1 / dViewWidth;
VisWindow.ZoomBehavior = Visio.VisZoomBehavior.visZoomVisioExact;
double dZoom = VisWindow.Zoom / System.Math.Max(dFitY, dFitX);
// Don't zoom in too much...
if (dZoom < 1)
VisWindow.Zoom = dZoom;
}
Your comments are welcome...
Enjoy!