Author Topic: Adding image to container  (Read 1118 times)

0 Members and 1 Guest are viewing this topic.

Totores

  • Newbie
  • *
  • Posts: 7
Adding image to container
« on: September 07, 2023, 05:20:25 PM »
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

  • Hero Member
  • *****
  • Posts: 3208
Re: Adding image to container
« Reply #1 on: September 08, 2023, 04:15:10 AM »
Basically you want the container to resize your image? am I right?
Yacine

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4837
  • Ideas Visio-lized into solutions
Re: Adding image to container
« Reply #2 on: September 08, 2023, 09:36:07 AM »
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

  • Hero Member
  • *****
  • Posts: 1285
    • UnmanagedVisio
Re: Adding image to container
« Reply #3 on: September 08, 2023, 11:11:31 AM »
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

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4837
  • Ideas Visio-lized into solutions
Re: Adding image to container
« Reply #4 on: September 08, 2023, 09:26:21 PM »
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.

Code
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