Storing Visio code snippets / macroces online

Started by Nikolay, December 07, 2013, 03:55:17 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Nikolay

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!

Paul Herber

#1
I've got a simpler version of this, purely local, in my utilities:
http://www.paulherber.co.uk/visio-utilities/
Super Utils -> Macro Store
Electronic and Electrical engineering, business and software stencils for Visio -

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

Nikolay

#2
Quote from: Paul Herber on December 07, 2013, 06:22:38 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...

Paul Herber

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 for Visio -

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

Nikolay

#4
Quote from: Paul Herber on December 09, 2013, 04:46:39 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.

Nikolay

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

... and Adieu VBA, Vive JavaScript?

Otherwise a very cool feature.
Yacine

Nikolay

#7
Quote from: Yacine on June 03, 2017, 11:17:21 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




wapperdude

#8
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
Visio 2019 Pro

Yacine

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

#10
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:

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 );
       }
});



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.