Visio Guy

Visio Discussions => Programming & Code => Topic started by: perry59 on July 26, 2021, 03:24:37 PM

Title: issue with addin and stencils
Post by: perry59 on July 26, 2021, 03:24:37 PM
I have an addin that that I built using Nikolay's awesome template. When it installs it also "publishes" stencils and templates to folders in the addin's directory.
they show up there just fine, but visio is still looking at old directories. I thought "publishing" would set visio's file locations to the addins location.
Is that not the case? How do I get the addin to change visio's file locations to the correct place?
Thanks
Title: Re: issue with addin and stencils
Post by: JohnGoldsmith on July 27, 2021, 03:22:21 PM
Hi,
These are two independent mechanisms:You should use one or the other but not both (for the same solution).
If your stencils and templates are coming from your install directory and being surfaced in the UI via Publishing, then you can delete those paths from the respective File Locations fields.  Does that work for you?
Using the Publishing route is usually a better option if you're using an installer as it allows you to create language specific versions of your files (only surfacing the correct one for the current language), to separate the physical location of the file from the path that the user sees in the UI.  It also allows for an easier uninstall/update experience as the content files get uninstalled along with the addin.
Does that answer your question?
Best regards
John
Title: Re: issue with addin and stencils
Post by: perry59 on July 27, 2021, 04:04:02 PM
I'm not even sure I understand the answer!
I thought surfacing was something you did with an old bowling ball?
When my installer (Wix based) runs it creates a directory for my application. In that directory is the VSTO file, config file, etc. it also create two subfolders for stencils and templates and does copy the applicable files there.
when visio starts it does not show these templates and stencils in the UI and the paths are not appended to existing paths in options->file locations.
I thought that in the past that the installation did do this, the only thing I remember changing is putting the stencils/templates in their own subfolders rather than dumping them into the applications directory.
I don't think my installer does anything with "path discovery".
Perry
Title: Re: issue with addin and stencils
Post by: Nikolay on July 27, 2021, 04:23:25 PM
Quotewhen visio starts it does not show these templates and stencils in the UI

There is no need to modify options => file locations. The installer does not touch them (and it is not supposed to, these are considered user settings)
The stencils are registered using component publishing (adding registry entries).
Even if you clear all the fields in the "path" dialog, the installed stencils / templates should still stay available.

If you are not seeing them, that could be another Visio feature - you have "metric" stencils and "imperial" template (or vice versa).
Try naming your stencils the way they end with "<yourname>_m.vssx" or "<yourname>_u.vssx" (add suffix _m or _u depending on the type you want your stencil to show up).

I believe this is a feature of Visio 2013 and above, but may be mistaking.
Probably a warning could be added for the case stencils do not end with _u or _m and Visio 2013 and above is targeted.

Also, you need to specify menu path where you want your stencils to show up, i.e. to surface.
I mean, in the installer, in the <visio:PublishStencil ...> element. If you don't have <visio:PublishStencil> then please add it, this is doing the registration.
Means, the installer does not automatically register all stencils, only those which you register with the construct above. Could look something like this:

<File Name="StencilA_m.vssx">
  <visio:PublishStencil MenuPath="My Solution\Stencil A" />
</File>

If you create a blank project and add stencils directly in the project wizard, it adds this code automatically.
Title: Re: issue with addin and stencils
Post by: perry59 on July 27, 2021, 05:11:12 PM
my typical publish statement in "product.wxs" looks like this:

<Component>
        <File Name="Components.vss">
          <visio:PublishStencil MenuPath="VisioElectrical\Stencils\Components" />
        </File>
</Component>

I wonder if the problem my stencils and templates still have the "old" suffix's, i.e. vss instead of vssx?
perhaps I should explicitly open each one and re-save them in the "new" format and edit my wxs file?

Thanks
Perry
Title: Re: issue with addin and stencils
Post by: Nikolay on July 27, 2021, 05:55:59 PM
That looks fine.. i would try renaming the file to stencil_m.vss first, this if AFAIK the most common case.

It may be also new template (vstx) vs old stencil (vss).
But basically it "should work" :)
Title: Re: issue with addin and stencils
Post by: perry59 on July 27, 2021, 06:07:20 PM
I'll try appending the "_u" to my stencils when I get home tonight and see how that does and let you know in the morning.
Thanks Nikolay!
Title: Re: issue with addin and stencils
Post by: perry59 on July 27, 2021, 06:30:22 PM
I played around with this a little at work. One thing I noticed that I did not like is the "_U" shows up when browsing stencils.
it does not do that for the ones installed by microsoft, strange.
Title: Re: issue with addin and stencils
Post by: Nikolay on July 27, 2021, 08:05:37 PM
This is because the stencils are not installed. You probably just specified the path in the application settings. That is, it looks like Visio discovers you stencils using "path discovery", not installation / registration.
When you install a stencil, you specify a name for it in menu in the "menu path" parameter.
This name is basically what you should see in the menu ("Components" in the case below, "VisioElectrical" and "Stencils" should become parent menu items)

<visio:PublishStencil MenuPath="VisioElectrical\Stencils\Components" />

To test that installation works properly, I would to clear the "path" Visio settings, so that they are blank.

Please note that the stencils with "_U" will show up if you select "US Units" when creating a diagram; stencils with "_M" will show if you select "Metric Units" when creating a diagram.
Title: Re: issue with addin and stencils
Post by: perry59 on July 27, 2021, 08:20:54 PM
Ok. I only renamed them, did not do a re-build and re-install. That's probably the problem.
I'll try that when I get home.
Thanks Nikolay!
Title: Re: issue with addin and stencils
Post by: Nikolay on July 27, 2021, 08:31:12 PM
I just did some testing, just to show what it looks like in pictures.
The code includes 4 items: two stencils (metric/us), two templates (metric/us)

      <!-- metric stencil -->
      <Component>
        <File Name="Stencil_1_M.vss">
          <visio:PublishStencil MenuPath="Demo Stencil Folder\Subfolder\Stencil 1 (metric)" />
        </File>
      </Component>
      <!-- metric template -->
      <Component>
        <File Name="Template_1_M.vst">
          <visio:PublishTemplate MenuPath="Demo Stencil Folder\Subfolder\Template 1 (metric)" />
        </File>
      </Component>
      <!-- us stencil -->
      <Component>
        <File Name="Stencil_1_U.vss">
          <visio:PublishStencil MenuPath="Demo Stencil Folder\Subfolder\Stencil 1 (US)" />
        </File>
      </Component>
      <!-- us template -->
      <Component>
        <File Name="Template_1_U.vst">
          <visio:PublishTemplate MenuPath="Demo Stencil Folder\Subfolder\Template 1 (US)" />
        </File>
      </Component>


In the templates you have both (according to the menu path, Templates (tab) => Demo Folder => Subfolder =>
(https://i2.paste.pics/570227c8fea34ec262b724bc8ac56954.png)

If you create a metric diagram like this:
(https://i2.paste.pics/a465511e6c10fdb393e0f3eb1a299b4f.png)

Then in the menu you have metric stencil (ending with "_m"). Note that "_m" is not displayed, instead the content of the "menu path" is displayed.
(https://i2.paste.pics/70db232e68e46a76b398fab0951c18ab.png)

Note: there is JUST ONE stencil, although two were registered.
If you select a US template, then you'll see the second stencil in the menu.

The demo project is attached (stencils/templates only no addins)

I believe this whole behavior may be even a bug of some sort.
That is, the thing that in Visio 2013 and above in case a registered stencil has neither "_m" nor "_u" suffix it is not displayed by Visio at all.
I would expect such stencils to show in BOTH cases actually, like it worked in Visio 2010 and below.

In Visio itself, all built-in stencils have either _u or _m prefix (starting with version 2013). My path for example: C:\Program Files (x86)\Microsoft Office\root\Office16\Visio Content\1033
They are just registered by alternative names so taht code like "Documents.Open "Basic.vss" works (note that there are other parameters in <PublishStencil> including this "alternate name" as well.
Visio should be able to find stencil if opened from VBA by any of those names (without path)
Title: Re: issue with addin and stencils
Post by: perry59 on July 27, 2021, 08:36:12 PM
Thanks Nikolay, you da man!
I'll try that out as soon as I can :)
Title: Re: issue with addin and stencils
Post by: JohnGoldsmith on July 28, 2021, 10:39:49 AM
Glad you're fixed and will try and be clearer next itme :)
Best regards
John
Title: Re: issue with addin and stencils
Post by: Paul Herber on July 28, 2021, 08:43:01 PM
The naming for stencils using _M for metric and _U for US (Imperial) units goes back to early days, I had Visio 2000 and it was in use then.
P.S. the spec I remember used uppercase M and U, don't know how important that is, but I've always used uppercase.
Title: Re: issue with addin and stencils
Post by: Paul Herber on July 28, 2021, 08:45:56 PM
"Documents.Open "Basic.vss"

Interesting thought, what if another stencil "Basic.vss" gets installed?
Title: Re: issue with addin and stencils
Post by: perry59 on July 29, 2021, 05:20:54 PM
It seems fine now, I did change the extensions on stencils and templates to the newer .vssx and .vstx but I don't think that was an issue.
The issue I think was, the visio 2007 UI was so ingrained in me I was not looking for the templates in the right place in the 2016 UI.
they are there :o
Thanks for the help!