Help developing a new add-on

Started by VisioDeveloper, January 22, 2016, 03:03:09 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

VisioDeveloper

Hello,

I've been developing a new add-on for visio and since this is my first experience in office add-on development it's been a long road but i'm starting to get the hang of it (well mostly).

So apparently i was unaware of the different ways available to extend the functionality of visio as described here. Anyway, I've been developing a standalone .exe which may or not may be the best option for what i'm trying to achieve. The addon is working great so far, but i'm worried i'm doing things in a "hackish" kind of way which may cause problems in the long run.

My objective right now is to implement a custom tab in visio with a checkbox where i can disable/enable the add-on. Ideally Visio should start with the add-on disabled. Is this possible with a standalone executable? Would it make sense to switch over and develop the add-on in a .vsl file or COM add-on? I've just found out about ClickOnce and being able to publish it with this technology would be a huge plus.

I'm also having problems with Application level events. They work but for some reason when i minimize Visio i'm unable to restore the window. Weird.

Any pointers in the right direction would be appreciated.

Thanks.

Edit: Seems like there is also VSTO? Well now i'm even more confused

JohnGoldsmith

Hi,

A few questions that come to mind are:

       
  • what languages you're comfortable in (or want to learn)
  • what version/s of Visio you're targeting
  • how widely do you want you solution to be distributed (ie is it just for you, or to be used by many people)
  • what task/s should it perform (is a tool, to be used with many template types, or a specific solution that will support a single template)
  • what other applications / resources will it need to interact with
Best regards

John
John Goldsmith - Visio MVP
http://visualsignals.typepad.co.uk/

Nikolay

#2
If you use Visual Studio, you can put my addin wizard in use:

Discussion here on this forum (have done latest update just recenlty)
http://visguy.com/vgforum/index.php?topic=6080.0

Website:
http://unmanagedvisio.com/products/visual-studio-project-templates-to-create-visio-add-ins/

Visual Studio Gallery:
https://visualstudiogallery.msdn.microsoft.com/d73b91cf-eaf3-4d54-acb5-4a85bec3c1fe

Looks like most of features you ask for you will get out of the box.

- Addin type: can be COM (shared addin) or VSTO
- Language: can be C# or VB
- Installation: can be OneClick or MSI (built with WIX), featuring ONE installer for per user / per machine and x86/x64 versions of Visio, also Visio 2003-2016 support (2003 with COM version only). Note that you may want to learn about ClickOnce limitations as well, for example it can't install templates/stencils (by "install" I mean make them available on Visio start page/in context menus, i.e. ClickOnce can't "publish" templates/stencils - MSI can). Choosing per user/per machine install means that you can select "per-user install" when no UAC prompt will be shown and not admin rights are asked and addin is installed into User's profile, or "admin install" with UAC prompt and installation to Program Files.
- UI: ribbon designer/manual xm ribbonl/command bars, code generated by wizard addresses the problem with "my button stopped working after minimize" (known issue with re-binding command bar controls)
- Addin initially disabled: can be set with attribute "Enable=2" (MSI version of the installer). Although I don't see much sense in this (maybe you actually want to dynamically disable/hide addin button, not the addin itself?) - in this case you can select "dynamic ui" option - visual studio ribbon designer does not support that, but the wizard does (with custom ribbon xml)

Visual Studio 2010-2015 are supported. And it's free of course.

VisioDeveloper

Quote from: JohnGoldsmith on January 22, 2016, 11:20:16 PM
Hi,

A few questions that come to mind are:

       
  • what languages you're comfortable in (or want to learn)
  • what version/s of Visio you're targeting
  • how widely do you want you solution to be distributed (ie is it just for you, or to be used by many people)
  • what task/s should it perform (is a tool, to be used with many template types, or a specific solution that will support a single template)
  • what other applications / resources will it need to interact with
Best regards

John

I'm using C#, targeting mainly Visio 2013 and possibly 2016 in the future. This is to be used by many people. If by templates you're referring to stencils, it will only support 1 stencil and ideally this can easily be upgraded with new stencil versions. I will need however to have a couple of "templates" with swimlanes that will be set as the background of each page (this is chosen by the user). It will also interact with Word, but only to export data from Visio.


Quote from: Nikolay on January 23, 2016, 12:39:46 AM
If you use Visual Studio, you can put my addin wizard in use:

Discussion here on this forum (have done latest update just recenlty)
http://visguy.com/vgforum/index.php?topic=6080.0

Website:
http://unmanagedvisio.com/products/visual-studio-project-templates-to-create-visio-add-ins/

Visual Studio Gallery:
https://visualstudiogallery.msdn.microsoft.com/d73b91cf-eaf3-4d54-acb5-4a85bec3c1fe

Looks like most of features you ask for you will get out of the box.

- Addin type: can be COM (shared addin) or VSTO
- Language: can be C# or VB
- Installation: can be OneClick or MSI (built with WIX), featuring ONE installer for per user / per machine and x86/x64 versions of Visio, also Visio 2003-2016 support (2003 with COM version only). Note that you may want to learn about ClickOnce limitations as well, for example it can't install templates/stencils (by "install" I mean make them available on Visio start page/in context menus, i.e. ClickOnce can't "publish" templates/stencils - MSI can). Choosing per user/per machine install means that you can select "per-user install" when no UAC prompt will be shown and not admin rights are asked and addin is installed into User's profile, or "admin install" with UAC prompt and installation to Program Files.
- UI: ribbon designer/manual xm ribbonl/command bars, code generated by wizard addresses the problem with "my button stopped working after minimize" (known issue with re-binding command bar controls)
- Addin initially disabled: can be set with attribute "Enable=2" (MSI version of the installer). Although I don't see much sense in this (maybe you actually want to dynamically disable/hide addin button, not the addin itself?) - in this case you can select "dynamic ui" option - visual studio ribbon designer does not support that, but the wizard does (with custom ribbon xml)

Visual Studio 2010-2015 are supported. And it's free of course.

I'm using VS Community 2015 and i've tried the wizard on 2 different computers but i got this:



Using the same version of VS in both (windows 8.1 and windows 10). Maybe i'm missing something.

I intend to install templates/stencils and i only knew about OneClick. Thanks for the information, i will definitively check it out. Does it also support updates?

As for the UI, i've already managed to create a ribbon with ribbon designer. Not sure what kind of limitations i would have vs a xml ribbon. And yes, now that i think about it, doesn't make much sense to start with the addin disabled.

btw, about the minimizing Visio i was having... simply adding this line:

application.MarkerEvent += new EApplication_MarkerEventEventHandler(Application_MarkerEvent);

Makes Visio unable to restore after being minimized. Just tested it with nothing running but that event and the problem persists.

One last thing: can anyone explain what exactly are the pros and cons of creating a standalone .exe vs a VSTO addin (or COM)? That's one of the few the things i haven't been able to find information about. Because so far what i'm able to do everything i want but since i've started having this problem and found out about VSTO i'm wondering if my approach is the root of these kind of problems. I need my solution to be robust and as extensible as possible.

Thanks for the help so far.

Nikolay

QuoteUsing VS Community 2015 and i've tried the wizard on 2 different computers but i got this:
Do you get this when you create a project, or when you install the extension itself?

It looks like it tries to create VSTO project, but VSTO is not installed. In this case, the wizard should show an error (warning) actually and not fail (it does for me)
Anyways, to resolve: either select "COM" project type in the wizard or install VSTO for Visual Studio 2015
http://aka.ms/GetLatestOfficeDevTools

Basically I've checked that wizard does not allow you to create a project if you don't have needed features installed, but obviously need to verify once more.

Your minimizing is also something different from what I was assuming.

VisioDeveloper

Quote from: Nikolay on January 23, 2016, 08:20:00 AM
QuoteUsing VS Community 2015 and i've tried the wizard on 2 different computers but i got this:
Do you get this when you create a project, or when you install the extension itself?

It looks like it tries to create VSTO project, but VSTO is not installed. In this case, the wizard should show an error (warning) actually and not fail (it does for me)
Anyways, to resolve: either select "COM" project type in the wizard or install VSTO for Visual Studio 2015
http://aka.ms/GetLatestOfficeDevTools

Basically I've checked that wizard does not allow you to create a project if you don't have needed features installed, but obviously need to verify once more.

Your minimizing is also something different from what I was assuming.

I get the error when trying to create a project and i already have VSTO installed. COM works fine. When i try to create a VSTO project with the default project template it also works fine.

Nikolay

#6
Thank you for the info! I'll try to fix the issue.

Do I understand you correctly:
- You have Visual Studio 2015 Community installed (which version exactly - Update 1?)
- You have VSTO tools installed (which version - Visual Studio 2015 Tools for Office Update 1?)
- You have Visio installed (which Visio version exactly - Visio 2013 Pro?)

Also, could you please try to uninstall/install the extension?

QuoteCan anyone explain what exactly are the pros and cons of creating a standalone .exe vs a VSTO addin (or COM)?

With VSTO/COM you can do all things you can with EXE.

AFAIK, because EXE runs out-of-process, with EXE:

- You cannot have ribbon UI or dynamic UI (enable/disable buttons depending on selected shape type for example), because callbacks require the addin to be in-process.
- You cannot have your own windows inside of Visio, because they require the window handler to be in-process.
- You may hit some performance issues (it is slower when you call Visio API), because all the data you pass to/from Visio will be marshalled.

Basically, in case of EXE integration is calling your EXE with arguments.

VisioDeveloper

Quote from: Nikolay on January 23, 2016, 10:00:11 PM
Thank you for the info! I'll try to fix the issue.

Do I understand you correctly:
- You have Visual Studio 2015 Community installed (which version exactly - Update 1?)
- You have VSTO tools installed (which version - Visual Studio 2015 Tools for Office Update 1?)
- You have Visio installed (which Visio version exactly - Visio 2013 Pro?)

Also, could you please try to uninstall/install the extension?

VS 2015 Update 1, VSTO Tools 2015 Update 1 and visio 2013 and i'm currently on this machine i'm using visio 2016. On the other i have Visio 2013 and exactly the same thing happens.

Nikolay

Thank you!  Should be fixed now (just uploaded fixed version)

Could you please try to update to 1.0.5?

VisioDeveloper

Quote from: Nikolay on January 24, 2016, 02:30:37 AM
Thank you!  Should be fixed now (just uploaded fixed version)

Could you please try to update to 1.0.5?

Working now, thanks!

I'll rewrite my addin using VSTO and report back if i have any issues.

VisioDeveloper

So i've just re-written the addin with VSTO. Everything is working perfectly and now the application events work without issues.  ;)

Now my next objective is to create new "templates" with my custom stencil and have them appear when opening Visio. I'm not sure if these should be templates because they are really only background pages which all share the same stencil.
The stencil is mostly competed, there's just an issue of changing the default connector which i'm not sure if it's possible in an official way. My workaround is to have the connector in the stencil which is not very practical and does not integrate well with Visio.

Anyway, how can i add templates to the "Featured" and "Categories" sections?

As for publishing, i'm inclined to use WiX but i have a question: does it support updates? That's one thing that really stood out for me when looking at ClickOnce but not being able to install templates/stencils seems like a deal breaker with this solution for me.

Thanks again to Nikolay for the amazing tools you're providing, makes my life much easier  ;D

Nikolay

#11
As far as I can tell you can't go with ClickOnce in you want to provide templates on start page/in categories.

Although we discussed awhile ago a way though registry here: http://visguy.com/vgforum/index.php?topic=6053.0
Maybe in the future I'll incorporate that into the setup project in some way.

With WIX that should be possible (basically it does the same as the "solution publishing tool" does).
If you have them ready, then the easiest way is to specify them directly in the wizard (it will include them in installer).
By default, they will be put under category named after the add-in.

But you can do that afterwards as well by editing the installer file, but in this case it will be xml editing.

Note taht if you create default setup with "create sample stencils", there is a sample stencil and template generated and put into setup, to illustrate the point.
If you select yours stencils, they should be put into setup instead. Anyways, the part of the setup you are interested in is:


      <Component>
        <File Name="Stencil_1.vss">
          <visio:PublishStencil MenuPath="ExtendedVisioAddin1\Stencil 1" />
        </File>
      </Component>

      <Component>
        <File Name="Template_1.vst">
          <visio:PublishTemplate MenuPath="ExtendedVisioAddin1\Template 1" />
        </File>
      </Component>
      ....


To add your files (for example, MyStenil1.vss, MyStenil2.vss, MyTemplate.vst), you can copy your files to the project directory, and replace that with:


      <Component>
        <File Name="MyStencil1.vss">
          <visio:PublishStencil MenuPath="MyStencil1" />
        </File>
      </Component>

      <Component>
        <File Name="MyStencil2.vss">
          <visio:PublishStencil MenuPath="MyStencil2" />
        </File>
      </Component>

      <Component>
        <File Name="MyTemplate.vst">
          <visio:PublishTemplate MenuPath="MyTemplate" />
        </File>
      </Component>
      ....


You can do it also other way around, like specify path to your files using Src="...."
The <PublishStencil> and <PublishTemplate> elements are specific for Visio. The "MenuPath" item specifies where you want to see your template/stencil in Visio.
Anyways, there are many options available for those, you can look them up here (that project became part of this one now):

http://unmanagedvisio.com/products/visio-wix-installer-project-template/

The MSI update is supported, but not in the automatic way provided by ClickOnce (means, your users will have to install new version by hand).
The new version will replace the old one though (will uninstall old one automatically).

To allow that you'll have to do a bit of XML editing in the new version   - change the version number, and the product id to new values.
These ones:


<?define Version="PUT-NEW-VERSION-HERE"?>
<?define ProductCode = "{PUT-NEW-GUID-HERE}" ?>


JohnGoldsmith

#12
Hi,

I think Nikolay has answered your questions, but I just thought I'd add a note about stencils and templates and surfacing them in the UI.  ClickOnce is great for delivery, but with VSTO, you don't get the same Visual Studio UI as say a standard ClickOnce exe in terms of data files.  This means that it's a lot harder to get them onto the target machine.  I believe you can add the files to your publish\ folder and edit the manifests accordingly, but you then need to go through a number of hoops using mage to resign the manifests.

Visio has two methods of getting your solution stencils and templates to appear in the UI - one is 'Publishing', which, as Nikolay mentioned, uses the registry to maintain a record of the available resources and the other is 'path discovery', where the user (or set via code) tells Visio where to look (via File / Options / Advanced / File locations...) for content files.  The former has a number of advantages, such as multi-language support, separation of menu path (in the UI) from the physical file location, but the latter is clearly easier to implement.

In terms of using a template, it has the advantage of allowing you to specify page settings that new drawing pages will be based on, workspace inforamtion, like which stencils should be open and docked in a new drawing, and, allows you to either add a persisent event to the template or add some unique information that allows your code to detect when your template has been opened.

Re your connector, if the user uses the connector tool to connect two shapes, it will first look in the drawing's document stencil to see if it contains a master named "Dynamic connector".  If it does, it will use that, and if not it will add one to the doc stencil.  If you name your own connector accordingly and then save it in the template's document stencil then Visio will use your custom connector rather than the built in one.

Anyway, hope that's helpful.

Best regards

John
John Goldsmith - Visio MVP
http://visualsignals.typepad.co.uk/

VisioDeveloper

Is there a easy way to change the path of the stencil referenced by the template to a relative path or a reference to the installed stencil in visio?

I've created a template and the stencil path seems to be hardcoded in the template:

windows.xml
...
    <Window ID='1' WindowType='Stencil' WindowState='67109889' WindowLeft='0' WindowTop='-10' WindowWidth='247' WindowHeight='859' Document='C:\Users\Username\Documents\My Shapes\Stencil.vssx' ParentWindow='0'>
...


It will probably work in 99% of cases anyway if i change the path of the stencil to the installation folder but it breaks if the user changes the installation path.

Also, if possible i would like to change the category name and the thumbnails both for the "Featured" and "Categories" tabs.

Quote from: JohnGoldsmith on January 25, 2016, 10:52:35 AM
Hi,

I think Nikolay has answered your questions, but I just thought I'd add a note about stencils and templates and surfacing them in the UI.  ClickOnce is great for delivery, but with VSTO, you don't get the same Visual Studio UI as say a standard ClickOnce exe in terms of data files.  This means that it's a lot harder to get them onto the target machine.  I believe you can add the files to your publish\ folder and edit the manifests accordingly, but you then need to go through a number of hoops using mage to resign the manifests.

Visio has two methods of getting your solution stencils and templates to appear in the UI - one is 'Publishing', which, as Nikolay mentioned, uses the registry maintain a record of the available resources and the other is 'path discovery', where the user (or set via code) tells Visio where to look (via File / Options / Advanced / File locations...) for content files.  The former has a number of advantages, such as multi-language support, separation of menu path (in the UI) from the physical file location, but the latter is clearly easier to implement.

In terms of using a template, it has the advantage of allowing you to specify page settings that new drawing pages will be based on, workspace inforamtion, like which stencils should be open and docked in a new drawing, and, allows you to either add a persisent event to the template or add some unique information that allows your code to detect when your template has been opened.

Re your connector, if the user uses the connector tool to connect two shapes, it will first look in the drawing's document stencil to see if it contains a master named "Dynamic connector".  If it does, it will use that, and if not it will add one to the doc stencil.  If you name your own connector accordingly and then save it in the template's document stencil then Visio will use your custom connector rather than the built in one.

Anyway, hope that's helpful.

Best regards

John

Thank you for the template event and connector tips, haven't thought of that. :)

As for the published stencils/templates... how does that work behind the scenes exactly? If there's no easy to reference the stencil in the template maybe that can be achieved with the registry?

JohnGoldsmith

#14
You're right, the full path does get persisted, but Visio goes through a number of steps to located the files and preserve the stencil / template relationship:

       
  • When Visio is about to open a file from the workspace list, it first examines the file's stored path.
  • If the path is exactly the same as the stored path for the file that contains the workspace list, Visio assumes that these files were meant to be in the same folder.
  • Visio uses the current workspace file's folder to locate files.
If you're using 'publishing' then you can change the category name using the Solution Publishing tool which is part of the SDK.  There will be a WiX equivilent, but it might help you to point the publishing tool at a generated msi to see the correct properties.  (the tool also contains a useful chm help file which is worth browsing).

In terms of icons/thumbnails, you can't, as far as I'm aware, set the folder/category icon, but you can set the template icon.  For the template icon, Visio will automatically generate an icon (that's stored in the template) as it's saved.  If you open the document ShapeSheet of the template you'll find two cells - PreviewQuality and LockPreview.  What you can do is:


       
  • Resize you template page to be a square aspect ratio
  • Draw or import (including images) the icon you want on the first page
  • Set PreviewQuality to 1 (detailed)
  • Set LockPreview to FALSE
  • Save the file (this saves the icon preview)
  • Set LockPreview to TRUE (this prevents further saves overwriting the icon)
  • Delete any shapes on the first page you don't want and return page size to original
  • Save the file
Note that if you're still not getting the resolution you're after, Chris Hopkins has an article on a registry setting that increases the resolution further: http://blogs.msdn.com/b/chhopkin/archive/2008/10/29/create-perfect-previews-for-your-templates.aspx

For publishing, Visio has a known set of GUIDs defining document and resource types (templates, stencils, addons, help files etc).  This is set in the PublishComponent table of the msi either using the SDK tool or via WiX as per Nikolay's project.  On installation the msi writes to some known locations in the registry and also changes another registry value to indicate to Visio that there's been a change.  Visio maintains a cache file of all of the content that it's aware of and the next time Visio opens it reads that the Change value has changed and updates the cache file with your new content.  The cache file records the physical location of the files on disk and the menu path that you've defined - so it knows where your files are and what you'd like them to be called.

The older path discovery method is just an array of paths that Visio surveys every time it opens.  Both work, but 'publishing' offers a lot more flexiblity.
John Goldsmith - Visio MVP
http://visualsignals.typepad.co.uk/