Author Topic: Develop an Addin for visio online?  (Read 2222 times)

0 Members and 1 Guest are viewing this topic.

Toxicboumboum

  • Jr. Member
  • **
  • Posts: 16
Develop an Addin for visio online?
« on: April 20, 2018, 04:05:35 AM »
Hi everyone
I built a macro for Visio 2013 and in a few months, I will have to use visio online.So I'd like to update my macro.
So my question is simple: is there a way to build a macro or an addin with vsto on visio online? (or any other way)

I make some searches and I find nothing and I don't have yet  any access to visio online

Surrogate

  • Hero Member
  • *****
  • Posts: 858
    • ShapeSheet™ Knowledge Base
Re: Develop an Addin for visio online?
« Reply #1 on: April 20, 2018, 05:10:28 AM »
What Visio Online plan you mean ?
If you get Plan 2 you can use your macro again !

Toxicboumboum

  • Jr. Member
  • **
  • Posts: 16
Re: Develop an Addin for visio online?
« Reply #2 on: April 22, 2018, 01:57:13 PM »
are you sure?
Not with visio 2016 but only with visio online, I could edit macro?
Because I found an article wich said that this feature wasn't exist with visio online

Nikolay

  • Hero Member
  • *****
  • Posts: 764
    • UnmanagedVisio
Re: Develop an Addin for visio online?
« Reply #3 on: April 22, 2018, 03:08:37 PM »
Well, unfortunately as of now you can't run VBA in the browser. VBA is developed for desktops;
so to run it in a browser, one would need a complete emulation layer over forms and desktop objects (like files).
Well, this layer does not exist.

You can run javascript in the browser though;
you might want to check for Visio Online API (but that won't work on the desktop).

Microsoft is yet to provide "Apps for Visio". Unfortunately I don't know when and if it's going to happen.
I think you can refer to "Apps for Office" as an example of what you could expect in 1-5 year timespan.
Unfortunately Microsoft Store does not accept apps for Visio as well yet (as they do not exist)

Maybe with coming of WebAssembly someone will create something capable of running VBA in the browser;
that person will be a hero. But most probably nobody will, and you'd better focus on javascript
« Last Edit: April 22, 2018, 03:31:58 PM by Nikolay »

Toxicboumboum

  • Jr. Member
  • **
  • Posts: 16
Re: Develop an Addin for visio online?
« Reply #4 on: April 24, 2018, 03:29:26 AM »
Ok thanks
I subscribe for a visio online trial and I think that I can't do what I'm doing with my visio 2016 on visio online
First, I use data shape like cost and in my accro I have some lines like:
Shape1ConnectorId = Shape1.ConnectedShapes _
    (visConnectedShapesIncomingNodes, "")
According to this link: https://blogs.msdn.microsoft.com/visio/2017/09/25/migrate-from-visio-web-access-to-visio-online/ , Javascript couldn't execute neither this kind of command nor set shape values
Am I right?
« Last Edit: April 24, 2018, 03:46:09 AM by Toxicboumboum »

vojo

  • Hero Member
  • *****
  • Posts: 1146
Re: Develop an Addin for visio online?
« Reply #5 on: April 24, 2018, 08:04:19 PM »
python, c++, or R?

what about using a container or viewer to pull down drawing into some light weight visio and do it there then post back up
(still has the benefit of sharing across users and such...aka visio SKU of a sharepoint).

Toxicboumboum

  • Jr. Member
  • **
  • Posts: 16
Re: Develop an Addin for visio online?
« Reply #6 on: April 25, 2018, 01:40:29 AM »
The idea is to not install visio anymore, only with visio online, we would like to be able to make the calculation we need
I have already written my macro in c#

Nikolay

  • Hero Member
  • *****
  • Posts: 764
    • UnmanagedVisio
Re: Develop an Addin for visio online?
« Reply #7 on: April 25, 2018, 01:49:23 AM »
Can you show the macro, so that we could suggest something reasonable?

Toxicboumboum

  • Jr. Member
  • **
  • Posts: 16
Re: Develop an Addin for visio online?
« Reply #8 on: April 25, 2018, 04:39:52 AM »
Yes of course:
The first macro help me to calculate the value inside my shape on the left depending on the values of the shapes which are connected to it by an incomming connection

Public Sub FindOffPageShapes()
Dim shp As Visio.Shape
Dim pagShape As Visio.Shape
   Dim Shape1 As Visio.Shape
    Dim lngShapeIDs() As Long
    Dim Shape2 As Visio.Shape
    Dim ConnectorsIds() As Long
    Dim Shape1ConnectorId() As Long
    Dim Connector As Visio.Shape
    Dim Tempo As Visio.Shape
    Dim lngShapeID As Long
    Dim i As Integer
    Dim j As Integer
    Dim K As Integer
    Dim Value As Double
    Dim value2 As Double
    Dim Value3 As Double
    Set pagShape = Visio.ActivePage.PageSheet
For l = 1 To 10
For Each shp In Visio.ActivePage.Shapes
   
    Set Shape1 = shp
   
    If Shape1.OneD = 0 Then
     Debug.Print (Shape1.Name)
        lngShapeIDs = Shape1.ConnectedShapes _
    (visConnectedShapesIncomingNodes, "")
    For i = 0 To UBound(lngShapeIDs)
    Set Shape2 = ActivePage.Shapes.ItemFromID(lngShapeIDs(i))
    Shape1ConnectorId = Shape1.ConnectedShapes _
    (visConnectedShapesIncomingNodes, "")
        If UBound(Shape1ConnectorId) > 0 Then
        Value3 = 0
            For j = 0 To UBound(Shape1ConnectorId)
            Set Connector = ActivePage.Shapes.ItemFromID(Shape1ConnectorId(j))
            Debug.Print CStr(Connector.Text)
            ConnectorsIds = Connector.GluedShapes(visGluedShapesOutgoing1D, "", Shape1)
                For K = 0 To UBound(ConnectorsIds)
                Set Tempo = ActivePage.Shapes.ItemFromID(ConnectorsIds(K))
                value2 = CDbl(Tempo.Text) * CDbl(Connector.Data1)
                Next
            Value3 = Value3 + value2
            Next
        Debug.Print CStr(Value3)
        Shape1.Data1 = CStr(Value3)
        Shape1.CellsU("prop.Cost").FormulaU = Chr(34) & CStr(Value3) & Chr(34)
       
        Else
        Value = 0
        ConnectorsIds = Shape1.GluedShapes(visGluedShapesIncoming1D, "", Shape2)
        For j = 0 To UBound(ConnectorsIds)
        Set Connector = ActivePage.Shapes.ItemFromID(ConnectorsIds(j))
        Value = CDbl(Shape2.Data1) * CDbl(Connector.Text)
        Debug.Print (Shape1.Name)
        Debug.Print (Connector.Name)
        Next
     Shape1.Data1 = CStr(Value)
     Shape1.CellsU("prop.Cost").FormulaU = Chr(34) & CStr(Value) & Chr(34)
     End If
     Next
    End If
Next shp
Next l
Visio.Application.Addons("VisRpt").Run ("/rptDefName=ProjectSorting /rptOutput=EXCEL")

The next macro generated a report in a new sheet to get all the connector with input and output shapes

Sub ExcelReport(ByVal pgCnt, shpCnt, ByRef cnxArry() As Variant)

    Dim i As Integer, j As Integer
    Dim p As Integer
    Dim m As Integer
    Dim XlApp As Object
    Dim XlWrkbook As Excel.Workbook
    Dim XlSheet As Excel.Worksheet
    Dim prpData(10, 10) As String
   
    Set XlApp = CreateObject("Excel.Application")
    Set XlWrkbook = XlApp.Workbooks.Add
    Set XlSheet = XlWrkbook.Worksheets("Sheet1")
   
 
    XlApp.Visible = False
    XlApp.ScreenUpdating = False
       

    XlSheet.Cells(1, 1) = "PAGE"
    XlSheet.Cells(1, 2) = "CONNECTOR"
    XlSheet.Cells(1, 3) = "FROM SHAPE"
    XlSheet.Cells(1, 4) = "TO SHAPE"

       
   
    For p = 1 To pgCnt
    m = 0
    j = 0
        If p = 1 Then
            XlWrkbook.Worksheets("Sheet" & p).Activate
        ElseIf p >= 2 Then
            XlWrkbook.Worksheets("Sheet" & p).Activate
            Set XlSheet = XlWrkbook.Worksheets("Sheet" & p)
           
           
            XlSheet.Cells(1, 1) = "PAGE"
            XlSheet.Cells(1, 2) = "CONNECTOR"
            XlSheet.Cells(1, 3) = "FROM SHAPE"
            XlSheet.Cells(1, 4) = "TO SHAPE"

        End If
       
        For i = 1 To shpCnt
            conShp = cnxArry(0, 0, 0, 0, 0, 0, 0, 0, p, i)
            If conShp = Empty Then
                m = m + 1
                GoTo Skippy
            End If
           
            XlSheet.Cells(i + 1 + j - m, 1) = cnxArry(0, 0, 0, 0, 0, 0, 0, 0, p, 0)
            XlSheet.Cells(i + 1 + j - m, 2) = cnxArry(0, 0, 0, 0, 0, 0, 0, 0, p, i)
            XlSheet.Cells(i + 1 + j - m, 3) = cnxArry(0, 0, 0, 0, 0, 0, 0, 1, p, i)
            XlSheet.Cells(i + 1 + j - m, 4) = cnxArry(0, 0, 0, 0, 0, 1, 1, 1, p, i)
            XlSheet.Cells(i + 1 + j - m, 5) = cnxArry(0, 0, 0, 1, 1, 1, 1, 1, p, i)

Skippy:
        Next i
NxtPg:
    Next p



    Dim LastCol As Long
    Dim LastRow As Long
    Dim q As Long
    Dim rowCell As Range
    Dim FirstRow As Range
    Dim myUsedRng As Range
    Dim xptSheet As Excel.Worksheet
   
    p = 0
    For Each xptSheet In XlWrkbook.Sheets
        p = p + 1
        xptSheet.Activate

        Set myUsedRng = xptSheet.UsedRange
        Set FirstRow = myUsedRng.Rows(1).Cells
 
        LastCol = myUsedRng.Columns.Count
        LastRow = myUsedRng.Rows.Count
       
        With myUsedRng
            .HorizontalAlignment = xlGeneral
            .VerticalAlignment = xlCenter
   
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlCenter
   
         'Add light borders around all individual used cells
            .Borders(xlEdgeLeft).Weight = xlThin
            .Borders(xlEdgeTop).Weight = xlThin
            .Borders(xlEdgeBottom).Weight = xlThin
            .Borders(xlEdgeRight).Weight = xlThin
            .Borders(xlInsideVertical).Weight = xlThin
            .Borders(xlInsideHorizontal).Weight = xlThin
   
         'Heavy outer border around the used worksheet region
            .Borders(xlEdgeLeft).Weight = xlMedium
            .Borders(xlEdgeTop).Weight = xlMedium
            .Borders(xlEdgeBottom).Weight = xlMedium
            .Borders(xlEdgeRight).Weight = xlMedium
   
         'Set used cell background fill to white
            .Interior.Color = RGB(255, 255, 255)
        End With
   
    ' Double line:  selection range used is top row of cells
        FirstRow.Borders(xlEdgeBottom).LineStyle = xlDouble
        FirstRow.Borders(xlEdgeBottom).Weight = xlThick
   
     'Set top row upper case, font bold, cell background fill to light yellow, and set column widths
        For Each rowCell In FirstRow
            rowCell = UCase(rowCell)
            rowCell.Font.Bold = True
            rowCell.Font.Color = RGB(0, 0, 200)
            rowCell.Font.Size = 9
            rowCell.Interior.Color = RGB(255, 255, 204)
            rowCell.EntireColumn.AutoFit
        Next rowCell
        If p <= pgCnt Then
            Call VisPushBack(myUsedRng, xptSheet.Name)
        End If
    Next xptSheet
    XlApp.ScreenUpdating = True


    XlApp.Visible = True


    XlWrkbook.Close SaveChanges:=False

End Sub

So any idea if I could say bye to Visio 2016?


Nikolay

  • Hero Member
  • *****
  • Posts: 764
    • UnmanagedVisio
Re: Develop an Addin for visio online?
« Reply #9 on: April 25, 2018, 05:36:58 AM »
The macro itself is not a problem, can be done in javascript;
however, "shape reporting" Visio built-in add-on and Excel you are using is a problem.

Both are not available out-of-the box in the browser. Would you consider replacing them with some javascript code?
(I guess that would be quite a lot of code actually)

The options (replacement) for excel/reports:
- SharePoint Excel Services (sheets)
- Google Sheets
- Javascript Excel parser (such as sheet.js)

I would estimate 1 week to re-write in javascript

Toxicboumboum

  • Jr. Member
  • **
  • Posts: 16
Re: Develop an Addin for visio online?
« Reply #10 on: April 25, 2018, 06:10:00 AM »
But I use some function which doesn't exist in javascript no?
I never use javascript  so I don't know how powerfull is this tool

Nikolay

  • Hero Member
  • *****
  • Posts: 764
    • UnmanagedVisio
Re: Develop an Addin for visio online?
« Reply #11 on: April 25, 2018, 06:30:58 AM »
Yes, you use Visio "shape report" function and Excel application.

1. Visio.Application.Addons("VisRpt").Run ("/rptDefName=ProjectSorting /rptOutput=EXCEL")

2. Set XlApp = CreateObject("Excel.Application")

These two lines are not possible in the browser. I.e. it is not actually about javascript, it is about the browser.

For (1), user must have Visio installed, for (2), user must have Excel installed.
Now imagine Android smartphone that runs the browser.
« Last Edit: April 25, 2018, 06:37:23 AM by Nikolay »

Toxicboumboum

  • Jr. Member
  • **
  • Posts: 16
Re: Develop an Addin for visio online?
« Reply #12 on: April 25, 2018, 06:44:58 AM »
Yes but for example, this kind of function :
ConnectorsIds = Connector.GluedShapes(visGluedShapesOutgoing1D, "", Shape1)


I can use it with javascript?

Nikolay

  • Hero Member
  • *****
  • Posts: 764
    • UnmanagedVisio
Re: Develop an Addin for visio online?
« Reply #13 on: April 25, 2018, 06:59:30 AM »
The names of the functions are different.
But many of them exists in the Visio online API as well.
Not sure about ConnectedShapes though.

Here is the reference:
https://dev.office.com/reference/add-ins/visio/visio-javascript-reference-overview?product=visio

You could check out my alternative svg export. It has connectedShapes, but documentation still kind of sucks  :-[
https://nbelyh.github.io/svgpublishdemo/AdvWorksOLTPSchemaVisio.html

Code for that thing (on shape click):
Code: [Select]
    var shape = diagram.shapes[id];
    if (shape.ConnectedTo) {
        shape.ConnectedTo.forEach( function(item) {
            d3.select("#" + item).selectAll("g").style("fill", "#Aff");
        });
    }
    if (shape.ConnectedFrom) {
        shape.ConnectedFrom.forEach( function(item) {
            d3.select("#" + item).selectAll("g").style("fill", "#fAf");
        });
    }

Toxicboumboum

  • Jr. Member
  • **
  • Posts: 16
Re: Develop an Addin for visio online?
« Reply #14 on: April 25, 2018, 07:02:19 AM »
Ok thank you
I'm gonna to check that this evenning