Adding image to container

Started by Totores, September 07, 2023, 10:20:25 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Totores

Morning all,
once again I seek assistance (tried but was unsuccessful).
On my template plan I want to place a container locked in place so that the position and size can't be changed (I know how to do this).
How do i insert a picture in the container so that the picture or map image resized itself to fit with-in the container size and shape?
with the container locked, when I insert the picture it still changes the container size.

Thanks

Yacine

Basically you want the container to resize your image? am I right?
Yacine

wapperdude

As far as locking container size, that works correctly for me.

Regarding resizing picture, that is doable, but takes a bit of code.
Visio 2019 Pro

Nikolay

For me locking container size works as well:


As for the automatic picture stretch/scale to fit the container size, there is no such feature, as far as I know.

wapperdude

Here's macro that will center and re-size the pic to fit into the container.  This is minimalist code.  It assumes that ideally there is only one container on the page, or at least, the 1st container that the macro finds is the desired container.  Next, it presumes that the container has been locked and will not adjust size to fit the shape.  Basically, then, it assumes that the container has been preset and locked, ready for the picture.  The container should not be selected.

The process begins by dropping the picture on the page, anywhere.  Doesnot have to be on or near the container.  Just leave it selected and then run the macro.  In my case, the image was rotated 90 degrees.  You should either comment the rotation line in the macro or set to a desired value.  Also, the picture size is hard coded to be 6x8.  Note, width and height are reversed in the test case due to the 90 degree rotation.


Sub ctrXpd()
    Dim vCntr As Visio.Shape       'variable for container
    Dim vImg As Visio.Shape       'variable for picture
   
    Set vImg = ActiveWindow.Selection(1)
    vImg.CellsSRC(visSectionObject, visRowLock, visLockAspect).FormulaU = "1"
    vImg.Cells("Angle").Formula = "-90 deg"                   'May need to comment out this line
    vImg.CellsSRC(visSectionObject, visRowXFormOut, visXFormWidth).FormulaU = "8 in"    'May need to reverse these values
    vImg.CellsSRC(visSectionObject, visRowXFormOut, visXFormHeight).FormulaU = "6 in"

    ActiveWindow.DeselectAll
   
    For Each vCntr In ActivePage.Shapes
        If vCntr.CellExists("User.msvStructureType", 0) Then      'simple test to see if shape is a container
            cntrPinX = vCntr.Cells("PinX").ResultStr(visNone)
            cntrPinY = vCntr.Cells("PinY").ResultStr(visNone)
            vImg.Cells("PinX").Formula = cntrPinX
            vImg.Cells("PinY").Formula = cntrPinY
            ActiveWindow.Zoom = -1
            Exit Sub
        End If
    Next
End Sub
Visio 2019 Pro