Using Stencil Icon in RibbonXML

Started by scotth1963, September 14, 2017, 02:01:44 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

scotth1963

I'm trying to use the LoadImage take a Stencil Item and use it as on Icon in RibbonXML. I keep getting no icons showing. I did get LoadPicture to properly load a jpg file and display it so I was thinking if there was a way to convert a Stencil Icon to an external jpg file and then use LoadPicture, that might work.

Unfortunately, I haven't seen any examples of that around.

I was able to get a list of all icons in an IPictureDisp Array call vsoPicArray so they can be displayed in an image control:

Sub LoadIcon(StencilNameIn As String)
    Dim vsoPage As Visio.Page
    Dim vsoStencil As Visio.Document
    Dim vsoMaster As Visio.Master
    Dim vsoShape As Visio.Shape
   
    Set vsoPage = Application.ActivePage
    ' Get a reference to the Master to use as the replacement shape.
    Set vsoStencil = Application.Documents(StencilNameIn)
    strStencilPathAndFileName = vsoStencil.Path + StencilNameIn
    ReDim vsoPicArray(vsoStencil.Masters.Count)
    iPicCount = 1
    For Each vsoMaster In vsoStencil.Masters
        vsoMasterName = vsoMaster.Name
        Set vsoShape = vsoMaster.PageSheet.Shapes(1)
        lstIcons.AddItem vsoMaster.Name
        Set vsoPicArray(iPicCount) = vsoShape.Picture
        iPicCount = iPicCount + 1
    Next

End Sub

I thought that I could use similar code to get the Stencil Image in LoadImage

Function LoadImage(ByVal strFName As String) As IPictureDisp
    Dim vsoPage As Visio.Page
    Dim vsoStencil As Visio.Document
    Dim vsoMaster As Visio.Master
    Dim vsoShape As Visio.Shape
    Dim IPic As IPictureDisp
    Dim filePath As String


'    Using Changeto NewShape
    Set vsoStencil = Application.Documents("MyStencil.vssx")
    Set vsoMaster = vsoStencil.Masters(strFName)
    Set vsoShape = vsoMaster.PageSheet.Shapes(1)
    Set IPic = vsoShape.Picture
    Set LoadImage = IPic

End Function

That does not work. I thought since I got the LoadPicture to work properly I would try to use SavePicture and modified as so:

Function LoadImage(ByVal strFName As String) As IPictureDisp
    Dim vsoPage As Visio.Page
    Dim vsoStencil As Visio.Document
    Dim vsoMaster As Visio.Master
    Dim vsoShape As Visio.Shape
    Dim IPic As IPictureDisp
    Dim filePath As String


'    Using Changeto NewShape
    Set vsoStencil = Application.Documents("MyStencil.vssx")
    Set vsoMaster = vsoStencil.Masters(strFName)
    Set vsoShape = vsoMaster.PageSheet.Shapes(1)
    Set IPic = vsoShape.Picture
   
    filePath = ThisDocument.Path + "\" + strFName + ".JPG"
    SavePicture IPic, filePath
    Set IPic = LoadPicture(filePath)
   
    Set LoadImage = IPic

End Function

the jpg file created is corrupted though. Is this a possible thing to use a Stencil Icon on the RibbonXML?

scotth1963

***************Resolved***********************
I was able to save a Stencil shape as a JPG using the following code. I need to put in checking for existence before creating and such but here is the working code
I leveraged code from http://visguy.com/vgforum/index.php?topic=1491.0:

Function LoadImage(ByVal strFName As String) As IPictureDisp
    Dim vsoPage As Visio.Page
    Dim vsoStencil As Visio.Document
    Dim vsoMaster As Visio.Master
    Dim vsoShape As Visio.Shape
    Dim IPic As IPictureDisp
    Dim filePath As String


'    Using Changeto NewShape
    Set vsoStencil = Application.Documents("MyStencil.vssx")
    Set vsoMaster = vsoStencil.Masters(strFName)
    Set vsoShape = vsoMaster.PageSheet.Shapes(1)
    Set IPic = vsoShape.Picture
   
    Application.Settings.SetRasterExportResolution visRasterUsePrinterResolution, 600#, 600#, visRasterPixelsPerInch
    Application.Settings.SetRasterExportSize visRasterFitToPrinterSize, 1.133333, 1.511667, visRasterInch
    Application.Settings.RasterExportColorFormat = visRasterRGB
    Application.Settings.RasterExportOperation = visRasterBaseline
    Application.Settings.RasterExportRotation = visRasterNoRotation
    Application.Settings.RasterExportFlip = visRasterNoFlip
    Application.Settings.RasterExportBackgroundColor = 16777215
    Application.Settings.RasterExportQuality = 100
    filePath = ThisDocument.Path + "\" + strFName + ".JPG"
    vsoShape.Export (filePath)
    Set IPic = LoadPicture(filePath)
   
    Set LoadImage = IPic

End Function