# VisioLayoutExtensions

Layout and geometry helpers for Visio pages, shapes, and selections.

Class 

`OfficeIMO.Visio`

**Namespace**

`OfficeIMO.Visio`

**Assembly**

`OfficeIMO.Visio`

**Source revision**

`273d35d5ba8a` with working tree changes

**Source**

[VisioLayoutExtensions.cs:17](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Visio/Layout/VisioLayoutExtensions.cs#L17)

**Modifiers**

static

Layout and geometry helpers for Visio pages, shapes, and selections.

## Inheritance

- object
- VisioLayoutExtensions

Filter members 

Show inherited

## Methods

Align 2 overloads

`public static VisioShapeSelection Align(VisioShapeSelection selection, VisioHorizontalAlignment alignment)` [#](#method-align-officeimo-visio-visioshapeselection-officeimo-visio-visiohorizontalalignment)

[VisioLayoutExtensions.Selection.cs:22](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Visio/Layout/VisioLayoutExtensions.Selection.cs#L22)

Aligns selected shapes horizontally inside the current selection bounds.

Parameters

**selection OfficeIMO.Visio.VisioShapeSelection required**

Selection to align.

**alignment OfficeIMO.Visio.VisioHorizontalAlignment required**

Horizontal alignment.

Returns

`VisioShapeSelection`

`public static VisioShapeSelection Align(VisioShapeSelection selection, VisioVerticalAlignment alignment)` [#](#method-align-officeimo-visio-visioshapeselection-officeimo-visio-visioverticalalignment)

[VisioLayoutExtensions.Selection.cs:49](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Visio/Layout/VisioLayoutExtensions.Selection.cs#L49)

Aligns selected shapes vertically inside the current selection bounds.

Parameters

**selection OfficeIMO.Visio.VisioShapeSelection required**

Selection to align.

**alignment OfficeIMO.Visio.VisioVerticalAlignment required**

Vertical alignment.

Returns

`VisioShapeSelection`

`public static VisioPage CenterContent(VisioPage page)` [#](#method-centercontent-officeimo-visio-visiopage)

[VisioLayoutExtensions.cs:172](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Visio/Layout/VisioLayoutExtensions.cs#L172)

Centers top-level page shapes within the current page size.

Parameters

**page OfficeIMO.Visio.VisioPage required**

Page to update.

Returns

`VisioPage`

`public static VisioShapeSelection Distribute(VisioShapeSelection selection, VisioDistributionAxis axis)` [#](#method-distribute-officeimo-visio-visioshapeselection-officeimo-visio-visiodistributionaxis)

[VisioLayoutExtensions.Selection.cs:76](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Visio/Layout/VisioLayoutExtensions.Selection.cs#L76)

Distributes selected shapes by center point along the requested axis.

Parameters

**selection OfficeIMO.Visio.VisioShapeSelection required**

Selection to distribute.

**axis OfficeIMO.Visio.VisioDistributionAxis required**

Distribution axis.

Returns

`VisioShapeSelection`

`public static VisioShapeSelection DistributeHorizontally(VisioShapeSelection selection)` [#](#method-distributehorizontally-officeimo-visio-visioshapeselection)

[VisioLayoutExtensions.Selection.cs:105](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Visio/Layout/VisioLayoutExtensions.Selection.cs#L105)

Distributes selected shapes horizontally by center point.

Parameters

**selection OfficeIMO.Visio.VisioShapeSelection required**

Selection to distribute.

Returns

`VisioShapeSelection`

`public static VisioShapeSelection DistributeVertically(VisioShapeSelection selection)` [#](#method-distributevertically-officeimo-visio-visioshapeselection)

[VisioLayoutExtensions.Selection.cs:113](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Visio/Layout/VisioLayoutExtensions.Selection.cs#L113)

Distributes selected shapes vertically by center point.

Parameters

**selection OfficeIMO.Visio.VisioShapeSelection required**

Selection to distribute.

Returns

`VisioShapeSelection`

FitToContent 3 overloads

`public static VisioPage FitToContent(VisioPage page, double margin = 0.5, bool resizePage = true)` [#](#method-fittocontent-officeimo-visio-visiopage-double-boolean)

[VisioLayoutExtensions.cs:96](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Visio/Layout/VisioLayoutExtensions.cs#L96)

Moves top-level page shapes so content starts at the requested margin and optionally resizes the page to fit.

Parameters

**page OfficeIMO.Visio.VisioPage required**

Page to update.

**margin double = 0.5 optional**

Margin in inches around content.

**resizePage bool = true optional**

Whether to resize the page around the content.

Returns

`VisioPage`

`public static VisioPage FitToContent(VisioPage page, VisioFitToContentOptions options)` [#](#method-fittocontent-officeimo-visio-visiopage-officeimo-visio-visiofittocontentoptions)

[VisioLayoutExtensions.cs:105](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Visio/Layout/VisioLayoutExtensions.cs#L105)

Fits an imported page using explicit group-child, connector-route, translation, and resize policies. Rotation-aware shape bounds and connector label boxes are used.

Parameters

**page OfficeIMO.Visio.VisioPage required**

**options OfficeIMO.Visio.VisioFitToContentOptions required**

Returns

`VisioPage`

`public static VisioPage FitToContent(VisioPage page, double horizontalMargin, double verticalMargin, bool resizePage = true)` [#](#method-fittocontent-officeimo-visio-visiopage-double-double-boolean)

[VisioLayoutExtensions.cs:139](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Visio/Layout/VisioLayoutExtensions.cs#L139)

Moves top-level page shapes so content starts at the requested margins and optionally resizes the page to fit.

Parameters

**page OfficeIMO.Visio.VisioPage required**

Page to update.

**horizontalMargin double required**

Horizontal margin in inches.

**verticalMargin double required**

Vertical margin in inches.

**resizePage bool = true optional**

Whether to resize the page around the content.

Returns

`VisioPage`

`public static VisioShapeBounds GetConnectorContentBounds(VisioConnector connector)` [#](#method-getconnectorcontentbounds-officeimo-visio-visioconnector)

[VisioLayoutExtensions.ConnectorLabels.cs:269](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Visio/Layout/VisioLayoutExtensions.ConnectorLabels.cs#L269)

Gets connector route and label bounds in page inches.

Parameters

**connector OfficeIMO.Visio.VisioConnector required**

Returns

`VisioShapeBounds`

`public static VisioShapeBounds GetContentBounds(VisioPage page, bool includeGroupChildren = false, bool includeConnectors = true)` [#](#method-getcontentbounds-officeimo-visio-visiopage-boolean-boolean)

[VisioLayoutExtensions.cs:71](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Visio/Layout/VisioLayoutExtensions.cs#L71)

Gets bounds of visible page content, including shapes, explicit connector routes, and connector label boxes.

Parameters

**page OfficeIMO.Visio.VisioPage required**

Page to inspect.

**includeGroupChildren bool = false optional**

Whether nested group children should be included using their stored coordinates.

**includeConnectors bool = true optional**

Whether connector waypoints and label boxes should be included.

Returns

`VisioShapeBounds`

`public static VisioShapeBounds GetLabelBounds(VisioConnector connector)` [#](#method-getlabelbounds-officeimo-visio-visioconnector)

[VisioLayoutExtensions.ConnectorLabels.cs:281](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Visio/Layout/VisioLayoutExtensions.ConnectorLabels.cs#L281)

Gets the explicitly placed connector label bounds in page inches, or empty bounds when no label is placed.

Parameters

**connector OfficeIMO.Visio.VisioConnector required**

Returns

`VisioShapeBounds`

`public static VisioShapeBounds GetPageShapeBounds(VisioShape shape)` [#](#method-getpageshapebounds-officeimo-visio-visioshape)

[VisioLayoutExtensions.cs:28](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Visio/Layout/VisioLayoutExtensions.cs#L28)

Gets rotation-aware bounds in page coordinates, including every parent-group transform for a nested shape.

Parameters

**shape OfficeIMO.Visio.VisioShape required**

Returns

`VisioShapeBounds`

GetShapeBounds 3 overloads

`public static VisioShapeBounds GetShapeBounds(VisioShape shape)` [#](#method-getshapebounds-officeimo-visio-visioshape)

[VisioLayoutExtensions.cs:17](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Visio/Layout/VisioLayoutExtensions.cs#L17)

Gets the page-space bounds for a shape.

Parameters

**shape OfficeIMO.Visio.VisioShape required**

Shape to inspect.

Returns

`VisioShapeBounds`

`public static VisioShapeBounds GetShapeBounds(IEnumerable<VisioShape> shapes)` [#](#method-getshapebounds-collections-generic-ienumerable-officeimo-visio-visioshape)

[VisioLayoutExtensions.cs:36](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Visio/Layout/VisioLayoutExtensions.cs#L36)

Gets aggregate bounds for a shape sequence.

Parameters

**shapes System.Collections.Generic.IEnumerable<OfficeIMO.Visio.VisioShape> required**

Shapes to inspect.

Returns

`VisioShapeBounds`

`public static VisioShapeBounds GetShapeBounds(VisioShapeSelection selection)` [#](#method-getshapebounds-officeimo-visio-visioshapeselection)

[VisioLayoutExtensions.Selection.cs:11](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Visio/Layout/VisioLayoutExtensions.Selection.cs#L11)

Gets the bounds of a shape selection.

Parameters

**selection OfficeIMO.Visio.VisioShapeSelection required**

Selection to inspect.

Returns

`VisioShapeBounds`

RelayoutAsGrid 2 overloads

`public static VisioShapeSelection RelayoutAsGrid(VisioShapeSelection selection, int columns = 0, double horizontalSpacing = 0.5, double verticalSpacing = 0.5, bool routeInternalConnectors = true)` [#](#method-relayoutasgrid-officeimo-visio-visioshapeselection-int32-double-double-boolean)

[VisioLayoutExtensions.Selection.cs:125](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Visio/Layout/VisioLayoutExtensions.Selection.cs#L125)

Relays out selected shapes into a deterministic grid and optionally reroutes internal connectors.

Parameters

**selection OfficeIMO.Visio.VisioShapeSelection required**

Selection to relayout.

**columns int = 0 optional**

Number of columns. When zero, OfficeIMO uses a near-square grid.

**horizontalSpacing double = 0.5 optional**

Horizontal spacing between columns in inches.

**verticalSpacing double = 0.5 optional**

Vertical spacing between rows in inches.

**routeInternalConnectors bool = true optional**

Whether connectors whose endpoints are both selected should be rerouted orthogonally.

Returns

`VisioShapeSelection`

`public static VisioShapeSelection RelayoutAsGrid(VisioShapeSelection selection, VisioSelectionLayoutOptions? options)` [#](#method-relayoutasgrid-officeimo-visio-visioshapeselection-officeimo-visio-visioselectionlayoutoptions)

[VisioLayoutExtensions.Selection.cs:139](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Visio/Layout/VisioLayoutExtensions.Selection.cs#L139)

Relays out selected shapes into a deterministic grid and optionally reroutes internal connectors.

Parameters

**selection OfficeIMO.Visio.VisioShapeSelection required**

Selection to relayout.

**options OfficeIMO.Visio.VisioSelectionLayoutOptions? required**

Layout options.

Returns

`VisioShapeSelection`

`public static VisioShapeSelection RelayoutAsHorizontalStack(VisioShapeSelection selection, double spacing = 0.5, bool routeInternalConnectors = true)` [#](#method-relayoutashorizontalstack-officeimo-visio-visioshapeselection-double-boolean)

[VisioLayoutExtensions.Selection.cs:199](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Visio/Layout/VisioLayoutExtensions.Selection.cs#L199)

Relays out selected shapes as a horizontal row and optionally reroutes internal connectors.

Parameters

**selection OfficeIMO.Visio.VisioShapeSelection required**

Selection to relayout.

**spacing double = 0.5 optional**

Horizontal spacing between shapes in inches.

**routeInternalConnectors bool = true optional**

Whether connectors whose endpoints are both selected should be rerouted orthogonally.

Returns

`VisioShapeSelection`

`public static VisioShapeSelection RelayoutAsVerticalStack(VisioShapeSelection selection, double spacing = 0.5, bool routeInternalConnectors = true)` [#](#method-relayoutasverticalstack-officeimo-visio-visioshapeselection-double-boolean)

[VisioLayoutExtensions.Selection.cs:211](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Visio/Layout/VisioLayoutExtensions.Selection.cs#L211)

Relays out selected shapes as a vertical stack and optionally reroutes internal connectors.

Parameters

**selection OfficeIMO.Visio.VisioShapeSelection required**

Selection to relayout.

**spacing double = 0.5 optional**

Vertical spacing between shapes in inches.

**routeInternalConnectors bool = true optional**

Whether connectors whose endpoints are both selected should be rerouted orthogonally.

Returns

`VisioShapeSelection`

`public static VisioConnectorSelection ResizeLabelsToText(VisioConnectorSelection selection, OfficeFontInfo? fontInfo = null, double horizontalPadding = 0.12, double verticalPadding = 0.06, double minimumWidth = 0.45, double minimumHeight = 0.22, double? maximumWidth = null)` [#](#method-resizelabelstotext-officeimo-visio-visioconnectorselection-nullable-officeimo-drawing-officefontinfo-double-double-double-double-nullable-system-double)

[VisioLayoutExtensions.Text.cs:100](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Visio/Layout/VisioLayoutExtensions.Text.cs#L100)

Resizes selected connector label text boxes to fit their plain text using deterministic OfficeIMO.Drawing measurement.

Parameters

**selection OfficeIMO.Visio.VisioConnectorSelection required**

Connector selection.

**fontInfo OfficeIMO.Drawing.OfficeFontInfo? = null optional**

Font descriptor used for measurement. Uses connector text style, then Office default, when omitted.

**horizontalPadding double = 0.12 optional**

Horizontal padding in inches.

**verticalPadding double = 0.06 optional**

Vertical padding in inches.

**minimumWidth double = 0.45 optional**

Minimum resulting label width in inches.

**minimumHeight double = 0.22 optional**

Minimum resulting label height in inches.

**maximumWidth double? = null optional**

Optional maximum label width in inches. Text wraps by words when supplied.

Returns

`VisioConnectorSelection`

`public static VisioConnector ResizeLabelToText(VisioConnector connector, OfficeFontInfo? fontInfo = null, double horizontalPadding = 0.12, double verticalPadding = 0.06, double minimumWidth = 0.45, double minimumHeight = 0.22, double? maximumWidth = null)` [#](#method-resizelabeltotext-officeimo-visio-visioconnector-nullable-officeimo-drawing-officefontinfo-double-double-double-double-nullable-system-double)

[VisioLayoutExtensions.Text.cs:66](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Visio/Layout/VisioLayoutExtensions.Text.cs#L66)

Resizes a connector label text box to fit its plain text using deterministic OfficeIMO.Drawing measurement.

Parameters

**connector OfficeIMO.Visio.VisioConnector required**

Connector whose label box should be resized.

**fontInfo OfficeIMO.Drawing.OfficeFontInfo? = null optional**

Font descriptor used for measurement. Uses connector text style, then Office default, when omitted.

**horizontalPadding double = 0.12 optional**

Horizontal padding in inches.

**verticalPadding double = 0.06 optional**

Vertical padding in inches.

**minimumWidth double = 0.45 optional**

Minimum resulting label width in inches.

**minimumHeight double = 0.22 optional**

Minimum resulting label height in inches.

**maximumWidth double? = null optional**

Optional maximum label width in inches. Text wraps by words when supplied.

Returns

`VisioConnector`

ResizeToText 2 overloads

`public static VisioShape ResizeToText(VisioShape shape, OfficeFontInfo? fontInfo = null, double horizontalPadding = 0.25, double verticalPadding = 0.14, double minimumWidth = 0.5, double minimumHeight = 0.3)` [#](#method-resizetotext-officeimo-visio-visioshape-nullable-officeimo-drawing-officefontinfo-double-double-double-double)

[VisioLayoutExtensions.Text.cs:16](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Visio/Layout/VisioLayoutExtensions.Text.cs#L16)

Resizes a shape to fit its plain text using deterministic OfficeIMO.Drawing measurement.

Parameters

**shape OfficeIMO.Visio.VisioShape required**

Shape to resize.

**fontInfo OfficeIMO.Drawing.OfficeFontInfo? = null optional**

Font descriptor used for measurement. Uses Office default when omitted.

**horizontalPadding double = 0.25 optional**

Horizontal padding in inches.

**verticalPadding double = 0.14 optional**

Vertical padding in inches.

**minimumWidth double = 0.5 optional**

Minimum resulting width in inches.

**minimumHeight double = 0.3 optional**

Minimum resulting height in inches.

Returns

`VisioShape`

`public static VisioShapeSelection ResizeToText(VisioShapeSelection selection, OfficeFontInfo? fontInfo = null, double horizontalPadding = 0.25, double verticalPadding = 0.14, double minimumWidth = 0.5, double minimumHeight = 0.3)` [#](#method-resizetotext-officeimo-visio-visioshapeselection-nullable-officeimo-drawing-officefontinfo-double-double-double-double)

[VisioLayoutExtensions.Text.cs:46](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Visio/Layout/VisioLayoutExtensions.Text.cs#L46)

Resizes selected shapes to fit their plain text using deterministic OfficeIMO.Drawing measurement.

Parameters

**selection OfficeIMO.Visio.VisioShapeSelection required**

Selection to resize.

**fontInfo OfficeIMO.Drawing.OfficeFontInfo? = null optional**

Font descriptor used for measurement. Uses Office default when omitted.

**horizontalPadding double = 0.25 optional**

Horizontal padding in inches.

**verticalPadding double = 0.14 optional**

Vertical padding in inches.

**minimumWidth double = 0.5 optional**

Minimum resulting width in inches.

**minimumHeight double = 0.3 optional**

Minimum resulting height in inches.

Returns

`VisioShapeSelection`

`public static VisioPage ResolveConnectorLabelOverlaps(VisioPage page, double step = 0.18, int maxAttempts = 12, bool avoidShapes = true, bool avoidLabels = true, bool preferEndpointZones = false, bool avoidConnectorPaths = true, double positionStep = 0.08, int maxPositionShifts = 4, int optimizationPasses = 1)` [#](#method-resolveconnectorlabeloverlaps-officeimo-visio-visiopage-double-int32-boolean-boolean-boolean-boolean-double-int32-int32)

[VisioLayoutExtensions.ConnectorLabels.cs:20](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Visio/Layout/VisioLayoutExtensions.ConnectorLabels.cs#L20)

Moves connector label boxes away from page edges, unrelated shapes, and previously placed connector labels.

Parameters

**page OfficeIMO.Visio.VisioPage required**

Page whose connector labels should be adjusted.

**step double = 0.18 optional**

Search step in page units, expressed in inches.

**maxAttempts int = 12 optional**

Number of search rings to try around the current label position.

**avoidShapes bool = true optional**

Whether labels should avoid unrelated non-container shapes.

**avoidLabels bool = true optional**

Whether labels should avoid other connector labels.

**preferEndpointZones bool = false optional**

Whether labels should prefer common endpoint zones and avoid unrelated background zones.

**avoidConnectorPaths bool = true optional**

Whether labels should avoid unrelated connector paths.

**positionStep double = 0.08 optional**

Connector path-position search step, from 0.0 to 1.0.

**maxPositionShifts int = 4 optional**

Number of positive and negative connector path-position shifts to try.

**optimizationPasses int = 1 optional**

Number of whole-page label optimization passes to run after the initial placement sweep.

Returns

`VisioPage`

`public static VisioPage ResolveShapeOverlaps(VisioPage page, double step = 0.25, int maxAttempts = 24, bool includeContainers = false)` [#](#method-resolveshapeoverlaps-officeimo-visio-visiopage-double-int32-boolean)

[VisioLayoutExtensions.cs:192](https://github.com/EvotecIT/OfficeIMO/blob/273d35d5ba8ab8ce3f6f1238631241c0cea26d14/OfficeIMO.Visio/Layout/VisioLayoutExtensions.cs#L192)

Moves overlapping top-level shapes apart using a deterministic nearest-open-position search.

Parameters

**page OfficeIMO.Visio.VisioPage required**

Page to update.

**step double = 0.25 optional**

Search step in inches.

**maxAttempts int = 24 optional**

Number of search rings to try around each overlapping shape.

**includeContainers bool = false optional**

Whether container and background surface shapes should be moved and treated as obstacles.

Returns

`VisioPage`

## Inherited Methods

`public virtual bool Equals(object? obj)` [#](#method-equals-object)

Inherited from object

Parameters

**obj object? required**

Returns

`bool`

`public virtual int GetHashCode()` [#](#method-gethashcode)

Inherited from object

Returns

`int`

`public Type GetType()` [#](#method-gettype)

Inherited from object

Returns

`Type`

`public virtual string? ToString()` [#](#method-tostring)

Inherited from object

Returns

`string?`

<!-- PowerForge markdown artifact sha256:96839EE9789F8C6187511DF5E7AF4EF96F62FD35EB6FB8FD690F9EDFE25C0227 -->
