Visio Discussions > ShapeSheet & Smart Shapes

Efficient Image Management in Shapes



I'm looking for help with managing images efficiently in Visio when the image varies for each instance of a shape.

Image Position and Size
When importing an image into a group, it defaults to relative values within the group. To prevent stretching when the group size changes, I currently have to:

* Manually set the image dimensions (height, width) to specific millimeter values.
* Manually adjust the PinX and PinY values to position the image precisely.
This is time consuming. Is there anyway to get images to just default to millimter values on input? This would seem like a more obvious default to have anyway - who wants streatched images?

Grouping with the Basic Shape
Grouping the basic shape directly with the image seems to affect how formulas work within the shape. I think happens because it changes the Sheet.#! names without updating the formulae in the ShapeSheet.

To avoid this, I currenlty have to either:

* Open the group and insert the shape there, which is an extra step.
* Keep the image and the basic shape separate, which is annoying as everything should stay together as it's dragged around.
And More Generally
Are there any known good ways of managing images in shapes, when the image itself is effectively a variable that changes for each case of the shape?



--- Quote ---When importing an image into a group
--- End quote ---

How are you doing this?

As I have a pending need for this, here's a macro that ought to meet your needs.  Note, the Org Charting feature already has an image inserting methodology.

This macro must be run manually.  It will not trigger automatically upon picture drop.  Too many non-desired drop conditions to filter and eliminate.  It assumes that some shape (reasonable, 2D) is pre-selected.  It does not test if this has been done or not.  After selection, run macro.  It will bring up the insert picture diaglog.  Find and select desired picture.  Once that's completed, the macro resumes, resizing the image to fit into the target shape, centers the image, and then groups the two.

--- Code ---
Sub AddImageToShape()
'The sub does not automatically run.
'It will ask user to select a shape via insert diaglog
'It will re-size and center the image over the preselected
'target shape.
'It will create a group containing the target and image shapes
    Dim contShp As Visio.Shape
    Dim imgShp As Visio.Shape
    Dim shpsSeln As Visio.Selection
    Dim grpShp As Visio.Shape
'Assumes the target shape is selected before running macro
    Set contShp = ActiveWindow.Selection.Item(1)
    ActiveWindow.Select contShp, visSelect   'This makes the shape ACTIVE
    Visio.Application.DoCmd (1213)
    Visio.Application.DoCmd (1007)  'Opens insert picture dialog
    Set imgShp = ActiveWindow.Selection.Item(1)
    With imgShp
'        .CellsU("angle").Formula = "-90 deg"  'Optional to correct image orientation
        orgRat = .CellsU("Width").Result("") / .CellsU("Height").Result("")
        .CellsU("Width").FormulaU = contShp.CellsU("Width").Result("")
        .CellsU("Height").FormulaU = .CellsU("Width").Result("") / orgRat
        .CellsSRC(visSectionObject, visRowLock, visLockAspect).FormulaU = "1" ' Locks ratio for manual editing
        .CellsU("PinX").FormulaU = contShp.CellsU("PinX").Result("")
        .CellsU("PinY").FormulaU = contShp.CellsU("PinY").Result("")
    End With
    Visio.Application.DoCmd (1213)
'Optional group shapes.
    Set shpsSeln = ActiveWindow.Selection
    shpsSeln.Select contShp, visSelect
    shpsSeln.Select imgShp, visSelect
    Set grpShp = shpsSeln.Group
End Sub

--- End code ---


[0] Message Index

Go to full version