Author Topic: Storing Visio code snippets / macroces online  (Read 6829 times)

0 Members and 1 Guest are viewing this topic.

Nikolay

  • Hero Member
  • *****
  • Posts: 951
    • UnmanagedVisio
Storing Visio code snippets / macroces online
« on: December 07, 2013, 10:55:17 AM »
Hello Visio guys,  the following thoughts..

Now in Visio you can only save macro code in documents (in stencils also, but stencils are documents as well in principle)
This is fine, but may not be especially that practical, as to use a macro / command you have to have a document which contains it.

I think the following could make sense:

An online code repository for macroces or macro-commands / snippets can be done.
To not invent a wheel, the Github Gists site can be used as back-storage: http://gist.github.com
This is a service which allows you to create snippets online, and track history of changes; also it provides nice API for programmatic access (via REST)


In Visio (and maybe in other office apps?) it is possible to create an extension which would allow user to easily work with that from inside of Visio.
I.e. list "his" macroces, edit "his" macroces, search for macoces, apply them (see screenshot)

Possible features

- Storing all my macroces in the "cloud" and use it for all documents.
This has an advantage that all "my macroces" become immdiately available, not matter from where I start Visio.

- Since gists is a code repository, we get the history of code changes "for free", comments, popularity, and other social features.

- You could use a macro only for yourself and not show it to anyone, or share it with specific people or just everybody
(note that it will also become available online on the gists site!)

- You could do a full-text search on online base of code.
Could be useful to get the code piece you need.

- You should be able to apply macro without adding it to the document.
Means, the documents should can kept macro-free. Means, you should be able to just "apply" macro to e.g. "selected shapes", "selected page", "each files"
Maybe it makes sense to provide a possibility to create a "keyboard shortcut" or "button" out of a macro for ease of use.


Security considerations

Since the github repository is not anonymous, only developers will be able to change their own macroces; others will also able to contribute, but though "pull requests".
This could provide the first frontier of protection against malicious stuff.

The second frontier is that macroces are all plain text and you can always see what you are going to execute.

Also it is possible to e.g. limit execution engine to Visio API objects only, so that it does not allow creation of "foreign" objects using "CreateObject" for example.

The code can be in VB-script form (since there are tons of such code). It is also possible to allow other script engines in principle - like C# "script" for example (esp. with introduction of Roslyn) or Python.



Usage scenarios:

- Keeping "handy shortcut commands". E.g. I have scriplet which applies specific format/colors/style to a shape, then I select all shapes I need to format that way, click "Run for selected shapes" and my scriplet is executed for all such shapes, so the shapes are changed as needed, and no code is introduced into documents.

- Mass update of diagrams. For example, in scenario where I need to replace a specific shape on background for 100 files. I just make a small "script" in Visio, then apply it to 100 files.

- Easy discovery of code. I could be able to search online database of code.

- Easy sharing of scripts with others.


What do you think about all this?
Thanks!
« Last Edit: December 07, 2013, 11:03:05 AM by Nikolay »

Paul Herber

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2935
    • Paul Herber's website
Re: Storing Visio code snippets / macroces online
« Reply #1 on: December 07, 2013, 01:22:38 PM »
I've got a simpler version of this, purely local, in my utilities:
http://www.paulherber.co.uk/visio-utilities/
Super Utils -> Macro Store
« Last Edit: June 08, 2015, 02:20:25 AM by Paul Herber »
Electronic and Electrical engineering, business and software stencils and applications for Visio -

https://www.paulherber.co.uk/

Nikolay

  • Hero Member
  • *****
  • Posts: 951
    • UnmanagedVisio
Re: Storing Visio code snippets / macroces online
« Reply #2 on: December 07, 2013, 03:46:42 PM »
I've got a simpler version of this, purely local, in my utilities:
http://www.sandrila.co.uk/visio-utilities/
Super Utils -> Macro Store


Paul, thank you for response, honestly, I really appreciate it :)
And they say that in "internet era" people physically can't read more than one A4 sheet anymore.. :D

It's good that the functionality like that may make sense not only for me!

For example, we have clients with models in Visio; and a model is typically something like 100 diagrams,  and periodically they want to change something in those models.. I think it would be great to have sort of built-in scripting repository to simplify this task. So that you could test the script and then run it directly from Visio. This appears to make sense even for a single diagram! I mean, if I could e.g. select some shapes and just click APPLY, without introducing any macroces to the diagrams themselves, this would already make this world a better place :) For styles/colors/etc it works just out of the box (when you just click that in Visio menu) but for more complicated cases we are out of luck.

So the whole thing could be re-phrased probably as ability create some sort of "advanced" (configurable) macro-commands, stored online.
Even for the simplest case, like those direct Visio "commands not in the ribbon" it could still make sense for me...
« Last Edit: December 07, 2013, 03:50:40 PM by Nikolay »

Paul Herber

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2935
    • Paul Herber's website
Re: Storing Visio code snippets / macroces online
« Reply #3 on: December 09, 2013, 11:46:39 AM »
Hi Nikolay, I'm sure your application is much better than what I cobbled together, mine was just for my own uses that I thought might be useful to others. I will have a look at your application - when I get time!
I suspect there will be major macro security problems with macros stored online though, signed documents would no longer work. Maybe signed encrypted blocks of code could be used. But who would trust them beyond the macro's creator?
Interesting idea though.
Electronic and Electrical engineering, business and software stencils and applications for Visio -

https://www.paulherber.co.uk/

Nikolay

  • Hero Member
  • *****
  • Posts: 951
    • UnmanagedVisio
Re: Storing Visio code snippets / macroces online
« Reply #4 on: December 09, 2013, 12:08:05 PM »
Hi Nikolay, I'm sure your application is much better than what I cobbled together, mine was just for my own uses that I thought might be useful to others. I will have a look at your application - when I get time!
I suspect there will be major macro security problems with macros stored online though, signed documents would no longer work. Maybe signed encrypted blocks of code could be used. But who would trust them beyond the macro's creator?
Interesting idea though.


Paul, there is no such application yet  :D
I am just thinking if it makes sense to have something like this. As for the the security - please see my thoughts in "Security consideration"..

Thinking more globally, it probably could make sense for Microsoft to provide something like "Visio Store" for Visio where you could give/sell templates/shapes/addins/macroces (solutions) to the customers, using a "one-click" install.

The majority of users are not developers, they are in fact interested in functionality which is behind macroces and not in macroces themselves, so if this functionality can be wrapped as "application" which is represented as a "button" or "task pane" in Visio, that would be a good step forward.

I'm thinking of something like "Visio Apps", probably.
« Last Edit: December 09, 2013, 12:16:46 PM by Nikolay »

Nikolay

  • Hero Member
  • *****
  • Posts: 951
    • UnmanagedVisio
Re: Storing Visio code snippets / macroces online
« Reply #5 on: June 03, 2017, 03:49:56 AM »
Microsoft has recently implemented most of the things discussed here as a "Script Lab" project!
https://www.youtube.com/watch?v=V85_97G7VA4

Unfortunately Visio is left out, as always.
Hope they will do it also for Visio at some point of time :)

Yacine

  • Hero Member
  • *****
  • Posts: 2703
Re: Storing Visio code snippets / macroces online
« Reply #6 on: June 03, 2017, 06:17:21 AM »
... and Adieu VBA, Vive JavaScript?

Otherwise a very cool feature.
Yacine

Nikolay

  • Hero Member
  • *****
  • Posts: 951
    • UnmanagedVisio
Re: Storing Visio code snippets / macroces online
« Reply #7 on: June 03, 2017, 08:45:04 AM »
... and Adieu VBA, Vive JavaScript?

Otherwise a very cool feature.

Yes, that right.. Adieu VBA. AFAIR, they were trying to bury it for the last 10 years :)
And, well typescript is really better :) And yes, it works online!

Recently found out that web-editing is in beging tested - so javascript will probably the only choice in the future.
As soon as they enable javascript apps (office.js) to work with Visio...

https://techcommunity.microsoft.com/t5/Visio/Visio-Online-Create-Experience-Early-Preview/m-p/63051#M54



« Last Edit: June 03, 2017, 10:23:37 AM by Nikolay »

wapperdude

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3822
  • Ideas Visio-lized into solutions
Re: Storing Visio code snippets / macroces online
« Reply #8 on: June 03, 2017, 11:21:49 AM »
Guess you could see this coming.  Response to telecommuting, geographically spread corporations, even software piracy...the cloud, Office 365, et al.

Looks like you guys (Nilolay, Yacine) will be getting busier as this change become more common.   ;)

Wapperdude
« Last Edit: June 03, 2017, 11:57:16 AM by wapperdude »
Visio 2019 Pro

Yacine

  • Hero Member
  • *****
  • Posts: 2703
Re: Storing Visio code snippets / macroces online
« Reply #9 on: June 04, 2017, 05:53:55 AM »
Whilst I'm not so eager to switch from my old easy VBA to a language which requires much more writing (think alone all the semi-colons at the line ends), but there are certainly very great advantages:
- better OOP
- rather than implementing visio specific solutions for document sharing, interactive documents and so on, Visio can now use libraries which were not specially developed for it - with all the modern goodies.

Drawbacks:
- flatter learning curves. Beginner won't be capable of starting coding as it was the case with VBA. I wonder whether a macro recorder will be provided for typescript.

Questions:
- After all the efforts made by M$ to restrict the usage of scripts for security reasons, I wonder how an open exchange platform for scripts matches with this politics.
Yacine

Nikolay

  • Hero Member
  • *****
  • Posts: 951
    • UnmanagedVisio
Re: Storing Visio code snippets / macroces online
« Reply #10 on: June 04, 2017, 07:03:07 AM »
I don't think there is that much of a pain really, provided you hide all framework code,
and considering that in browser the code runs async... JS vs VBA:
Code
Visio.run(function (ctx) {
   var page = ctx.document.getActivePage();
   var shapes = page.shapes;
   shapes.load();
   return ctx.sync().then(function () {
        for(var i=0; i<shapes.items.length;i++) {
            var shape = shapes.items[i];
            console.log("Shape Text: " + shape.text );
       }
});

Code
Sub Foo()
    Set Page = ActivePage
    Set Shapes = Page.Shapes
    For i = 1 To Shapes.Count
        Set Shape = Shapes(i)
        Debug.Print "Shape Text:" & Shape.Text
    Next
End Sub

Learning curve: that's one of the reasons the Script Lab was built. It provides lots of samples

Security: Main concern about scripts was that they could harm your computer.
But, if they run inside of a sandbox (like in browser), and cannot interact with anything except shapes in a drawing for example, there is no such danger. There is no "FileSystemObject" in javascript in browser! One more thing - if we are talking about ScriptLab - the scripts are not "anonymous", they are created by some github member, who is normally not anonymous, but somebody you know or trust somehow; also it's open to the public, that means, if the script was malicious in some way, somebody would have noticed that probably alreayd and stated that in the place where the script is defined.
« Last Edit: June 04, 2017, 08:27:07 AM by Nikolay »