Ribbon Buttons for Multiple Connector Styles

Started by bhughes89, April 17, 2018, 04:49:04 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

bhughes89

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:

  • click & hold in one spot to designate the start of the connector, drag to another spot, and release the mouse button to designate the end of the connector
    (alternatively, I'd settle for first click / second click to designate the start / end)
  • Dynamic Connector is created with the predetermined line style
  • the tool keeps running until the user either selects a different tool or presses ESC

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 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).

Yacine

#1
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
Yacine

wapperdude

#2
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/

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


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

Just some thoughts...

Wapperdude



Visio 2019 Pro

metuemre

I think Yacine's suggestion is easier to implement. I attached a simple example that may be helpful.

Regards,

Yacine

Yacine

bhughes89

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)

bhughes89

Actually, I totally forgot I did have a few questions regarding the XML in metuemre's docs...

  • Each line starts with mso: after the bracket (see full XML string below). What exactly does that do?
    (don't get me wrong, my experience with XML is very limited but all the code examples I have seen just start with the tag name like ribbon, tab, group, button, etc.)
  • On a different document where I am implementing Ribbon customizations, the XML string starts with snippet below as the first line. However, this snippet is not on metuemre's XML. Any idea what this snippet does and how necessary it is?
        <?xml version="1.0" encoding="UTF-8"?>
  • The snippet below is line 3 of metuemre's XML. Does this just hide the Quick Access Toolbar (if the user has previously created one)?
        <mso:qat/>
  • Is there a way to nest a code block inside of a list using BBC on this forum (tried a few times without success on this post ha)?


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