Author Topic: Help developing a new add-on  (Read 19849 times)

0 Members and 1 Guest are viewing this topic.

Nikolay

  • Hero Member
  • *****
  • Posts: 945
    • UnmanagedVisio
Re: Help developing a new add-on
« Reply #15 on: January 25, 2016, 09:56:11 AM »
Just to clarify - the item mentioned above does the job of the publishing tool:

Code
<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 :)

VisioDeveloper

  • Jr. Member
  • **
  • Posts: 24
Re: Help developing a new add-on
« Reply #16 on: January 25, 2016, 10:09:25 AM »
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:

Code
            
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.
« Last Edit: January 25, 2016, 10:30:34 AM by VisioDeveloper »

JohnGoldsmith

  • Sr. Member
  • ****
  • Posts: 349
    • John Goldsmith's visLog
Re: Help developing a new add-on
« Reply #17 on: January 25, 2016, 10:31:43 AM »
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
John Goldsmith - Visio MVP
http://visualsignals.typepad.co.uk/

VisioDeveloper

  • Jr. Member
  • **
  • Posts: 24
Re: Help developing a new add-on
« Reply #18 on: January 25, 2016, 11:02:00 AM »
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.

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:

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

Or something along those lines.

JohnGoldsmith

  • Sr. Member
  • ****
  • Posts: 349
    • John Goldsmith's visLog
Re: Help developing a new add-on
« Reply #19 on: January 26, 2016, 05: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
John Goldsmith - Visio MVP
http://visualsignals.typepad.co.uk/

VisioDeveloper

  • Jr. Member
  • **
  • Posts: 24
Re: Help developing a new add-on
« Reply #20 on: January 27, 2016, 11:00:41 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.

VisioDeveloper

  • Jr. Member
  • **
  • Posts: 24
Re: Help developing a new add-on
« Reply #21 on: February 08, 2016, 11:42:10 AM »
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

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.

JohnGoldsmith

  • Sr. Member
  • ****
  • Posts: 349
    • John Goldsmith's visLog
Re: Help developing a new add-on
« Reply #22 on: February 08, 2016, 05: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.)
John Goldsmith - Visio MVP
http://visualsignals.typepad.co.uk/

vojo

  • Hero Member
  • *****
  • Posts: 1515
Re: Help developing a new add-on
« Reply #23 on: February 09, 2016, 08:58:23 AM »
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.

JohnGoldsmith

  • Sr. Member
  • ****
  • Posts: 349
    • John Goldsmith's visLog
Re: Help developing a new add-on
« Reply #24 on: February 09, 2016, 09:25:37 AM »
You've got to watch out for those British guys with their bad Englosh :)
John Goldsmith - Visio MVP
http://visualsignals.typepad.co.uk/

VisioDeveloper

  • Jr. Member
  • **
  • Posts: 24
Re: Help developing a new add-on
« Reply #25 on: February 15, 2016, 01:24:18 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 :)

JohnGoldsmith

  • Sr. Member
  • ****
  • Posts: 349
    • John Goldsmith's visLog
Re: Help developing a new add-on
« Reply #26 on: February 16, 2016, 04:08:57 AM »
Great.  Thanks for the feedback.

Best regards

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

perry59

  • Full Member
  • ***
  • Posts: 208
Re: Help developing a new add-on
« Reply #27 on: March 23, 2016, 02: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!

Nikolay

  • Hero Member
  • *****
  • Posts: 945
    • UnmanagedVisio
Re: Help developing a new add-on
« Reply #28 on: March 23, 2016, 03: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 :)

perry59

  • Full Member
  • ***
  • Posts: 208
Re: Help developing a new add-on
« Reply #29 on: March 23, 2016, 04: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
« Last Edit: March 23, 2016, 04:54:34 PM by perry59 »