Visio Guy

Visio Discussions => Programming & Code => Topic started by: VisioDeveloper on January 22, 2016, 03:03:09 PM

Title: Help developing a new add-on
Post by: VisioDeveloper on January 22, 2016, 03:03:09 PM
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 (https://msdn.microsoft.com/en-us/library/office/aa168138(v=office.11).aspx). 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
Title: Re: Help developing a new add-on
Post by: JohnGoldsmith on January 22, 2016, 11:20:16 PM
Hi,

A few questions that come to mind are:
Best regards

John
Title: Re: Help developing a new add-on
Post by: 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 (http://visguy.com/vgforum/index.php?topic=6080.msg29198#msg29198) 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.
Title: Re: Help developing a new add-on
Post by: VisioDeveloper on January 23, 2016, 03:16:58 AM
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 (http://visguy.com/vgforum/index.php?topic=6080.msg29198#msg29198) 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:

(http://i.imgur.com/JICORvv.png)

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.
Title: Re: Help developing a new add-on
Post by: 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 (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.
Title: Re: Help developing a new add-on
Post by: VisioDeveloper on January 23, 2016, 06:19:28 PM
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 (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.
Title: Re: Help developing a new add-on
Post by: 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?

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.
Title: Re: Help developing a new add-on
Post by: VisioDeveloper on January 23, 2016, 11:43:53 PM
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.
Title: Re: Help developing a new add-on
Post by: 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?
Title: Re: Help developing a new add-on
Post by: VisioDeveloper on January 24, 2016, 10:42:11 AM
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.
Title: Re: Help developing a new add-on
Post by: VisioDeveloper on January 24, 2016, 04:53:52 PM
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
Title: Re: Help developing a new add-on
Post by: Nikolay on January 24, 2016, 09:10:42 PM
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}" ?>

Title: Re: Help developing a new add-on
Post by: 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 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
Title: Re: Help developing a new add-on
Post by: VisioDeveloper on January 25, 2016, 01:02:08 PM
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?
Title: Re: Help developing a new add-on
Post by: JohnGoldsmith on January 25, 2016, 02:08:03 PM
You're right, the full path does get persisted, but Visio goes through a number of steps to located the files (https://msdn.microsoft.com/en-us/library/aa201740%28v=office.10%29.aspx) and preserve the stencil / template relationship:
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:

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 (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.
Title: Re: Help developing a new add-on
Post by: Nikolay on January 25, 2016, 02:56:11 PM
Just to clarify - the item mentioned above does the job of the publishing tool:


<visio:PublishStencil MenuName="XXXX"  />


The additional options are available as attributes of that item (type "Ctrl+Space" in the above item to see auto-complete with help, copied from the publishing tool)
Note that this PublishStencil/PublishTemplate is a replacement for the publishing tool with most (all?) of it's functionality was re-implemented, including publishing of VSL addons and help files.

To be clear, you use either this, or the publishing tool. Not both :)
Title: Re: Help developing a new add-on
Post by: VisioDeveloper on January 25, 2016, 03:09:25 PM
Thanks John and Nikolay.

BTW, I've tried your suggestion to change the default connector but it seems like it's not as straightforward as i thought. I've renamed my custom connector to "Dynamic connector" and it works, but only when that connector was previously added to the page (as it adds it to the document stencil as well).

So i thought about dropping the connector in the page and deleting it when opening the template but even that workaround doesn't work very well: seems like there's a conflict when i try to select the Master with the name "Dynamic connector".

I ended up doing this:

           
Document visioStencil = Application.Documents.OpenEx("Stencil.vssx",(short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visAddDocked);
Master visioRectMaster = visioStencil.Masters[2];
Application.ActivePage.Drop(visioRectMaster, 0, 0);
Application.ActivePage.Shapes[1].Delete();


Which is horrible  :P

As for the template event, the only property i can find to work with it is the Document.Template which returns the full path but it seems like it always returns an empty string for me no matter which template i open. Any ideas?

Edit: Templates which modify the connector style seem to also override my custom connector.
Title: Re: Help developing a new add-on
Post by: JohnGoldsmith on January 25, 2016, 03:31:43 PM
For the Dynamic connector, yes, it does need to be in the document stencil of the template (not you're standalone one). 

One thing to check is that it the masters universal name (NameU) has also been changed as this is the one that Visio will look for.  You can set this in code if they're out of sync.  The UI only allows you to set the NameU the first time and then all subsequent changes only effect the local name (Name). 

If it was me, I would add the connector to the template, unless you've got a special use case in which case you'll have to do it in code and you have to ensure that a Dynamic connector there already.  The other thing I'm noticing, is that you're using a variable name of visioRectMaster.  Does this mean that it's a 2D shape?  I suspect Visio would also want the connector to be 1D (although I haven't tested that).

Do you have any more details about the template event - I'm not clear on what you're trying to do here.

Also, do feel free to start a new specific thread so that this one doesn't include too many issues :)

Best regards

John
Title: Re: Help developing a new add-on
Post by: VisioDeveloper on January 25, 2016, 04:02:00 PM
Quote from: JohnGoldsmith on January 25, 2016, 03:31:43 PM
For the Dynamic connector, yes, it does need to be in the document stencil of the template (not you're standalone one). 

One thing to check is that it the masters universal name (NameU) has also been changed as this is the one that Visio will look for.  You can set this in code if they're out of sync.  The UI only allows you to set the NameU the first time and then all subsequent changes only effect the local name (Name). 

If it was me, I would add the connector to the template, unless you've got a special use case in which case you'll have to do it in code and you have to ensure that a Dynamic connector there already.  The other thing I'm noticing, is that you're using a variable name of visioRectMaster.  Does this mean that it's a 2D shape?  I suspect Visio would also want the connector to be 1D (although I haven't tested that).


I guess that works too, if i want to keep the template clean i can always delete the connector anyway.

And nah, i just adapted an example and didn't bother to change the variable names.

Quote from: JohnGoldsmith on January 25, 2016, 03:31:43 PM
Do you have any more details about the template event - I'm not clear on what you're trying to do here.

Also, do feel free to start a new specific thread so that this one doesn't include too many issues :)

Best regards

John

I'm trying to add some events only when my template is opened. Basically i'm looking for the template identifier so i can do something like:


if (templateName.Equals("MyTemplate") {
    //add events here
}


Or something along those lines.
Title: Re: Help developing a new add-on
Post by: JohnGoldsmith on January 26, 2016, 10:59:58 AM
Hi,

One method is to add a User cell to your template's document ShapeSheet, named something like User.SolutionId.  Then generate a GUID and set that as the value.

You can then listen on startup for DocOpened and Created events, inspect that User cell for the known GUID and then fire off work or other event listening.  That way your code doesn't need to change when you template name does plus with the GUID it will be unique to your solution.

Best regards

John
Title: Re: Help developing a new add-on
Post by: VisioDeveloper on January 27, 2016, 04:00:41 PM
Quote from: JohnGoldsmith on January 26, 2016, 10:59:58 AM
Hi,

One method is to add a User cell to your template's document ShapeSheet, named something like User.SolutionId.  Then generate a GUID and set that as the value.

You can then listen on startup for DocOpened and Created events, inspect that User cell for the known GUID and then fire off work or other event listening.  That way your code doesn't need to change when you template name does plus with the GUID it will be unique to your solution.

Best regards

John

Thanks for the tip, that's certainly a more robust solution. Meanwhile i found out what the problem was with the Template property: I was using the DocumentOpened event instead of DocumentCreated.
Title: Re: Help developing a new add-on
Post by: VisioDeveloper on February 08, 2016, 04:42:10 PM
Quote from: JohnGoldsmith on January 25, 2016, 02:08:03 PM
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 (http://blogs.msdn.com/b/chhopkin/archive/2008/10/29/create-perfect-previews-for-your-templates.aspx)

Does this work with Visio 2013/1016?

Tried it and i can see the thumbnail when i have my template saved with the image i want to see, but as soon as i set LockPreview to True, delete the image and save the template it just stops working. All i see is the default "blank" template image (see attachment).

If this is a problem in Visio 2013/2016, i can always install a older version (i guess it works in 2007?) . Just want to confirm that the problem is not on my end.
Title: Re: Help developing a new add-on
Post by: JohnGoldsmith on February 08, 2016, 10:48:29 PM
Hi, No it does work for 2013/16.  are you saving after you change LockPreview to true? (sorry I didn't put that in the bullet point did I.)
Title: Re: Help developing a new add-on
Post by: vojo on February 09, 2016, 01:58:23 PM
coincidently, I had to do the same thing last night for templates (apparently visio 2013 doesn't remember preferences unless you make a template...not lot 2003).

Anyway, found the links to do this  (I don't think it was John's)...but took 8 times to work through the poorly worded convoluted instructions (and this is from a guy in England...go figure):  Used the word file to cover templates, drawing, etc.

bottom line...your not alone trying to make that work.
Title: Re: Help developing a new add-on
Post by: JohnGoldsmith on February 09, 2016, 02:25:37 PM
You've got to watch out for those British guys with their bad Englosh :)
Title: Re: Help developing a new add-on
Post by: VisioDeveloper on February 15, 2016, 06:24:18 PM
Quote from: JohnGoldsmith on February 08, 2016, 10:48:29 PM
Hi, No it does work for 2013/16.  are you saving after you change LockPreview to true? (sorry I didn't put that in the bullet point did I.)

that was it, i was forgetting to save it. Working fine now, thanks :)
Title: Re: Help developing a new add-on
Post by: JohnGoldsmith on February 16, 2016, 09:08:57 AM
Great.  Thanks for the feedback.

Best regards

John
Title: Re: Help developing a new add-on
Post by: perry59 on March 23, 2016, 07:34:32 PM
Nikolay,
I just wanted to say that your new addon template is AWSOME!
I don't want to sound ungrateful, but was wondering if you could add on thing?
That would be stub functions for drop-down menus like the one attached, with submenu groups.
I hacked some code I "borrowed" into your template which works, sort of, but occasionally I end up with multiple menus. I guess when visio closes, the menu is not unloading. The selections also do not grey out when there is no document open. But strangest of all, when I have the pull down menu AND your toolbars enabled, whenever I click a command it executes twice ???
This is on visio 2007 which unfortunately we are stuck with, if we had a later version I would just go with the ribbons.
Thanks again for your great VS addon!
Title: Re: Help developing a new add-on
Post by: Nikolay on March 23, 2016, 08:07:17 PM
Glad this is helpful :)

I would say command bar menus are kind of buggy in Visio 2003/2007, and really hard to deal with.
Toolbars are sort of okay, but menus are problematic.
It's now so much easier (for developers) with ribbons, that was really a good step forward.

The issue is rather historical. Before Visio 2000 was acquired by Microsoft, it already had menu customization,
and the model used was completely different from the one used in other office apps. And converting first into second did not go quite smoothly.
So now in Visio 2016 you have 3 parallel ways of customizing menus. Which is a mess, IMHO.
Besides, some built-in addons (UML/Database) may simply break the menus (reset them)

Anyways, there are some key things to take care of when developing menus:

1. ALWAYS set "Tag" property for the menu items, and set it to unique value for each control. This is MUST,
otherwise you risk to end up with "dead" menus (events will not fire, as visio re-binds only tagged items on context switch).
This one should save you from many troubles.

2. Remember controls in variables (do not throw them away). in c#, they are garbage collected.
And when that happens, you may end up with "dead" menus again.

If I have time, I'll try to add some sample code to the project :)
Title: Re: Help developing a new add-on
Post by: perry59 on March 23, 2016, 09:52:38 PM
You Da Man Nikolay!
Yeah, I'd rather go with the ribbons...maybe someday.
If the pull down menus remain problematic I may just dump them and stay with the toolbars, just make some more. Wish they could be bigger.
BTW, I just noticed this (see attached)
This occurs AFTER I have created a project with your VS template, your template installs and works great. something is amiss though.
creates a VSTO project, with installer but then can not open it again!
I'm using VS community 2015 v14.0.2472 update 1
ms office developer tools 2015 update 1
Wix 3.10
Visio 2007
Title: Re: Help developing a new add-on
Post by: Nikolay on March 23, 2016, 10:41:47 PM
That's odd.. can you send the project as zip (the "broken" one, in PM or to my email), so that I can check it / fix the template if needed?
Title: Re: Help developing a new add-on
Post by: perry59 on March 23, 2016, 10:59:14 PM
Quote from: Nikolay on March 23, 2016, 10:41:47 PM
That's odd.. can you send the project as zip (the "broken" one, in PM or to my email), so that I can check it / fix the template if needed?
Thanks Nikolay!
I should probably re-install your addon first to see if that changes anything.
I do not see a way to attach a file to a PM and did not see an email address on your profile.
Title: Re: Help developing a new add-on
Post by: perry59 on March 23, 2016, 11:16:49 PM
Uninstalling/reinstalling didn't help :o
Title: Re: Help developing a new add-on
Post by: Nikolay on March 23, 2016, 11:48:17 PM
Ups. Updated the profile (added email)

The wizard only creates the project... After project creation the extension itself not used anymore.
Means, you should be able to open the project even after uninstalling the extension.
Title: Re: Help developing a new add-on
Post by: perry59 on March 24, 2016, 02:58:00 PM
Quote from: Nikolay on March 23, 2016, 11:48:17 PM
Ups. Updated the profile (added email)

The wizard only creates the project... After project creation the extension itself not used anymore.
Means, you should be able to open the project even after uninstalling the extension.
I assumed such. But VS is only complaining about my visio projects. I created a couple other projects, windows form, class lib, and it reopened them without complaint. Maybe I should reinstall everything and try again.
BTW, I set up the visio project for 2007, i.e. no ribbon, no 2016 assemblies. Just 2007 toolbars.
Title: Re: Help developing a new add-on
Post by: perry59 on March 24, 2016, 03:03:13 PM
Quote from: Nikolay on March 23, 2016, 11:48:17 PM
Ups. Updated the profile (added email)
Looks like email though this board does not allow attachments either!
I'll attach it here. There's nothing proprietary in there yet.
well, scratch that idea too! the board will not allow anything larger that 500k  >:(
Is it just the .sln file you need to see?
Title: Re: Help developing a new add-on
Post by: perry59 on March 24, 2016, 03:11:42 PM
Ok, here's one.
Made a bare bones one, no setup project or panel, this should post.
I still get the "incompatible" error after its created and I try to re-open it.
Title: Re: Help developing a new add-on
Post by: perry59 on March 24, 2016, 03:55:17 PM
Ok, I made a discovery  ;D
I only get an "incompatible" project if I do NOT build the solution before exiting VS.
So, if I make a new project then close it without building, it will not load in VS again.
If I make a new project, then do a build, even though I have not touched the code, then it will open up again in VS just fine.
Title: Re: Help developing a new add-on
Post by: Nikolay on March 24, 2016, 04:37:53 PM
That's odd. Looks like a bug in generator, most probably has something to do with Visio 2007 and project versions.. Will look at it today.
Title: Re: Help developing a new add-on
Post by: perry59 on March 24, 2016, 04:44:30 PM
Quote from: Nikolay on March 24, 2016, 04:37:53 PM
That's odd. Looks like a bug in generator, most probably has something to do with Visio 2007 and project versions.. Will look at it today.
Thanks Nikolay! glad I could help ???
But at least I know I can use it as long as I do a build before closing VS.
Title: Re: Help developing a new add-on
Post by: VisioDeveloper on April 02, 2016, 06:11:50 PM
So today i've been having a pretty frustrating experience, and the worst thing is that i'm not even sure where the problem is coming from.

The wix installer creation was working well on the machine i was working on (windows 8.1, VS 2015) but i don't have that machine anymore and i can't rebuild the installer no matter what i do.
Right now i have 2 windows 10 machines with basically everything i had on the other one (VS 2015, latest VSTO, wix 3.11) but i always get the same error when i try to build the setup:

The "ResolveWixReferences" task was not found. Check the following:
1.) The name of the task in the project file is the same as the name of the task class.
2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface.
3.) The task is correctly declared with <UsingTask> in the project file, or in the *.tasks files located in the "C:\Program Files (x86)\MSBuild\14.0\bin" directory.
Setup C:\Program Files (x86)\MSBuild\Microsoft\WiX\v3.x\wix2010.targets Line 772


Tried a fresh install of VS, several wix versions and it doesn't work even with a newly created project. I also found this: https://github.com/wixtoolset/issues/issues/3872 and tried the solution described but no luck. One thing i also noticed is that the WixNetFxExtension and WixUIExtension references do not have a valid path even with a new project.

Right now i'm trying to create a VM to see if it's something to do with windows 10 compatibility.

Edit: Now i'm even more confused, the VM with an identical setup throws the same error. Am i forgetting something or did something break with an update?
Title: Re: Help developing a new add-on
Post by: Nikolay on April 02, 2016, 07:47:33 PM
I would say this is some WIX install problem..

Have you tried uninstalling WIX and then installing it again?
Here is very similar issue reported, it says that after reinstall all is okay:
http://windows-installer-xml-wix-toolset.687559.n2.nabble.com/quot-ResolveWixReferences-quot-task-was-not-found-td5082069.html

I'm running Windows 10, does not seem to experience this issue.

It looks like missing Wix2010 targets.. means that something targets different version of Visual Studio (VS 2010).
Title: Re: Help developing a new add-on
Post by: VisioDeveloper on April 02, 2016, 07:56:53 PM
Quote from: Nikolay on April 02, 2016, 07:47:33 PM
I would say this is some WIX install problem..

Have you tried uninstalling WIX and then installing it again?
Here is very similar issue reported, it says that after reinstall all is okay:
http://windows-installer-xml-wix-toolset.687559.n2.nabble.com/quot-ResolveWixReferences-quot-task-was-not-found-td5082069.html

I'm running Windows 10, does not seem to experience this issue.

It looks like missing Wix2010 targets.. means that something targets different version of Visual Studio (VS 2010).

I don't remember which version of wix i had in my original install, which one are you using? Tried v4.0.3922.0 but it doesnt seem to work with the template so i installed v3.11.0.321.

I did this just now:

- fresh install of windows 8.1
- Installed VS Community 2015 Update 2
- Installed wix v3.11.0.321 and VSTO

And when i create a new project from the template i get this:
(http://i.imgur.com/6kHmjxB.png)

I've reinstalled wix multiple times on different machines, maybe it's the latest versions?
Title: Re: Help developing a new add-on
Post by: VisioDeveloper on April 02, 2016, 09:17:23 PM
After hours and hours trying to solve this, turns out the problem is the wix version. 3.10 works but not the newer versions.
Can you confirm if this is related to the template or wix itself?
Title: Re: Help developing a new add-on
Post by: Nikolay on April 02, 2016, 10:08:28 PM
But the latest released version is 3.10 (3.10.2)? At least I don't see a later one..?
Title: Re: Help developing a new add-on
Post by: VisioDeveloper on April 03, 2016, 11:19:27 AM
Quote from: Nikolay on April 02, 2016, 10:08:28 PM
But the latest released version is 3.10 (3.10.2)? At least I don't see a later one..?

Just checked again and i was downloading the weekly releases (not stable), I probably should of paid attention to that. My fault!
Title: Re: Help developing a new add-on
Post by: Nikolay on April 03, 2016, 03:40:20 PM
No problem, I'm glad it worked :)
As soon as WIX team releases the version, hopefully this bug with "references" will be gone.

BTW, I was able to reproduce the issue you wrote about before - if you don't build/save the solution and just create new and then close, then project file is broken (VSTO info gets removed).
Looks like some new bug-or-feature of VS2015 Update 1... Will try to update the extension to take care of that or if not possible try to rise an issue by MS..
For now, it looks that if you build/save the project at least once after creating and before closing, then all is fine.