Visio Guy

Visio Discussions => Programming & Code => Topic started by: bhughes89 on April 17, 2018, 04:49:04 PM

Title: Ribbon Buttons for Multiple Connector Styles
Post by: bhughes89 on April 17, 2018, 04:49:04 PM
Hey all!

I want to add a few buttons to the Ribbon that allow the user to create dynamic connectors with predetermined line styles.

Ideally, I'd have one button per specific line style that I need. The buttons would pass the line style info to a macro or sub-routine that acts exactly as if the user pressed the Connector Tool on the Ribbon:

Is there a way to use VBA to do this?
Or maybe there's another better way to accomplish this task?

I already know how to customize the Ribbon using VBA, but I need some help figuring out how to mimic the Dynamic Connector Tool behavior.



Running Visio Standard 2016 with Windows 7 Enterprise on a 64-bit machine.

Thanks in advance for your help!


P.S. This is essentially a cross-post of someone else's topic from late February (http://visguy.com/vgforum/index.php?topic=8297) that got no replies. I am re-wording and re-posting the topic here, as I think it is more relevant to Programming & Code (and might actually get a few replies :D).
Title: Re: Ribbon Buttons for Multiple Connector Styles
Post by: Yacine on April 18, 2018, 02:13:30 PM
Challenging indeed.

I could think of the following scenario.

Each custom connector button implements a method that executes the code to draw a connector.
Ideally a direct call would be made (if known), but the direct call could be substituted by addressing the connector button as shown here:
The custom button would then start an event listener for the shape added event. It would set a variable at document level so you know which drawing mode is selected.
In the document_shape_added event handler you would check for the drawing mode variable and depending on its value reformat the connector to your need.

Eager to see what you come up with.
Regards,
Yacine
Title: Re: Ribbon Buttons for Multiple Connector Styles
Post by: wapperdude on April 18, 2018, 02:51:58 PM
First, I hate using events.  Invariably quite frustrating...for me. 

Nonetheless, an embellishment to Yacine's suggestion...
1)  each GUI button triggers a separate macro that handles the various attributes.  Attribute setting is done at the end of the macro, after a connector has been placed.  The code takes advantage of the fact that the connector in question is, by default, selected.
https://blog.bvisual.net/2011/03/14/how-to-run-vba-macros-from-a-ribbon-button-in-visio-2010/ (https://blog.bvisual.net/2011/03/14/how-to-run-vba-macros-from-a-ribbon-button-in-visio-2010/)

2) I think you might need mouse button up/down events to signal start of new connector and finish of connector.
https://msdn.microsoft.com/en-us/vba/visio-vba/articles/application-mousedown-event-visio (https://msdn.microsoft.com/en-us/vba/visio-vba/articles/application-mousedown-event-visio)


3) the macro needs a loop so it will start a new connector after each completed connector.

Just some thoughts...

Wapperdude



Title: Re: Ribbon Buttons for Multiple Connector Styles
Post by: metuemre on April 19, 2018, 11:49:29 AM
I think Yacine's suggestion is easier to implement. I attached a simple example that may be helpful.

Regards,
Title: Re: Ribbon Buttons for Multiple Connector Styles
Post by: Yacine on April 20, 2018, 05:33:44 AM
Veeery nice ;)
Title: Re: Ribbon Buttons for Multiple Connector Styles
Post by: bhughes89 on April 20, 2018, 04:03:09 PM
Thank you guys so much for your responses!
(can't believe how responsive you all are :D :D)

I read up on the references that Yacine and Wapper provided to get some technical background. I have been working with the docs posted by metuemre to finalize my solution, which I am hoping to post today.

(it's been taking a bit longer than I thought it would, but I will be implementing a dynamic splitButton control that updates it's label depending on the currently active line style - might not be exciting for you guys but I'm pretty stoked!;D)
Title: Re: Ribbon Buttons for Multiple Connector Styles
Post by: bhughes89 on April 20, 2018, 05:15:43 PM
Actually, I totally forgot I did have a few questions regarding the XML in metuemre's docs...


The full XML string produced by metuemre's doc:
<mso:customUI onLoad="OnRibbonLoad" xmlns:mso="http://schemas.microsoft.com/office/2009/07/customui">
  <mso:ribbon>
    <mso:qat/>
    <mso:tabs>
      <mso:tab id="customTab" label="CUSTOM TAB">
        <mso:group id="group1" label="Line Patterns" autoScale="true">
            <mso:splitButton id="customSplit">
             <mso:button id="Objects" imageMso="LineStyle2" label="Dash Type" />
                <mso:menu id="customMenu">
                   <mso:button id="Solid" onAction="OnAction" label="Solid" />
                   <mso:button id="Dash" onAction="OnAction"  label="Dash" />
                   <mso:button id="Dot" onAction="OnAction"   label="Dot" />
                   <mso:button id="DashDot" onAction="OnAction"  label="Dash Dot" />
                   <mso:button id="DashDotDot" onAction="OnAction"  label="Dash Dot Dot" />
                   <mso:button id="DashDashDot" onAction="OnAction"  label="Dash Dash Dot" />
                   <mso:button id="LongDashShortDash" onAction="OnAction"  label="Long Dash Short Dash" />
              </mso:menu>
             </mso:splitButton>
        </mso:group>
      </mso:tab>
    </mso:tabs>
  </mso:ribbon>
</mso:customUI>


snippet  snippet  snippet  snippet       ....... just trying to see how many more times i can say "snippet" in one post lol  :P