Visio Guy

Visio Discussions => General Visio => Topic started by: Autom8It on May 16, 2023, 10:43:02 AM

Title: Cannot change any connectors from square to rounded corners
Post by: Autom8It on May 16, 2023, 10:43:02 AM
Hi Folks - I have a wiring diagram for a solar installation that has many connector lines, for which I cannot select Format Shape -> Line -> "Rounding presets" or change "Rounding size" for a line/connector.

However, in the ShapeSheet I can change the "Rounding" value from "0.0000 mm" to "5mm" and that works.

This is tedious to do manually for many connector lines. Is there a programmatic way to change this?
Advice and some sample code would be greatly appreciated!

Thanks
Title: Re: Cannot change any connectors from square to rounded corners
Post by: Surrogate on May 16, 2023, 11:19:42 AM
Quote from: Autom8It on May 16, 2023, 10:43:02 AMIs there a programmatic way to change this?
Yes, you can do it with code!
But there is no universal way:  the code depends on the shape...

Title: Re: Cannot change any connectors from square to rounded corners
Post by: Autom8It on May 16, 2023, 11:27:33 AM
Great, I can code but have never done so in Visio, but will figure it out with a bit of help.
Are there any sample code snippets that you can point me to or share for the following:


If You can help me with this I'm sure I can figure it out from there. I just have no clue how to start.
Thanks
Title: Re: Cannot change any connectors from square to rounded corners
Post by: Yacine on May 16, 2023, 12:17:08 PM
You can autom8it ( ;) )and it is pretty easy, but there could be an easier way.
Go to your document stencil, look for the standard connector master, open and edit it to your like, close. Now the connectors should all reflect the changes of the master - unless they've been modified individually.
This applies of course to ALL connectors. That can be something that you may not want. --> use different masters?


Otherwise, running code make sure to determine which connectors to format. eg a user cell "conn_type" with different values (type1, 2, whatever)
So when iterating over the shapes of the drawing you only need to check for this field.
Title: Re: Cannot change any connectors from square to rounded corners
Post by: wapperdude on May 16, 2023, 02:47:35 PM
Yacine method should work as described.  But, if you don't want all connectors to change, then that method wouldn't be appropriate.

I am curious when you say
QuoteI cannot select Format Shape -> Line -> "Rounding presets" or change "Rounding size" for a line/connector.
.  Just exactly what are you doing?  All connectors to be changed must be selected.  After selection, right click one of the selected shapes and from pop-up, select the Format Shapes entry.  Alternatively, go to UI ribbon, Home tab > Line > Line Options and that calls the Format Shape window.  From the new window work your way to line rounding and select desired value...or enter custom value.  That should work. 
Title: Re: Cannot change any connectors from square to rounded corners
Post by: Autom8It on May 16, 2023, 03:24:14 PM
Hi Surrogate - I could not even select one connector, right-click Format Shape -> Line -> "Rounding presets" or change "Rounding size". Nothing changed. The controls wouldn't allow a change. The connector corners just remained right-angled. I wasn't trying this with multiple connectors.

So I tried two connectors: selected two -> ribbon -> Line dropdown. There's no pop-up window as you mention, but I assume you meant select Line Options, which opens the Format Shape dialog/column on the right, right? Same result - cannot change the Rounding preset or the Rounding size fields - won't allow it, nada happens.

Yacine's method worked: I found a "Dynamic Connector" in the document stencil and changed the ShapeSheet "Rounding" Property to 5mm, which updated all connector corners. Thanks!

However, when "Rounding presets" is changed the dimension in the Rounding size field shows inches (huh?) although Page Setup -> Page Properties is set to Millimeters, the ShapeSheet for the page shows dimensions in millimeters, and all dimensions in Windows Settings are metric.

I cannot find a metric/imperial setting for the Master Dynamic Connector in the document stencil. Any idea where to set metric or imperial dimensions for all Shapes in the document or for all stencils? I'm not even sure if this is where this is set though. Any pointers would be welcome.

Thanks
Title: Re: Cannot change any connectors from square to rounded corners
Post by: Yacine on May 16, 2023, 06:04:43 PM
If you only put a number in the cell, Visio assumes you're using internal units, which happen to be inches.
Write: 5mm
to get the desired unit.
Title: Re: Cannot change any connectors from square to rounded corners
Post by: Autom8It on May 16, 2023, 07:50:41 PM
Strange? If a new diagram is created then all the ShapeSheet dimensions are millimeters. Not an inch in sight. Why is that?
Title: Re: Cannot change any connectors from square to rounded corners
Post by: Surrogate on May 16, 2023, 09:18:29 PM
Quote from: Autom8It on May 16, 2023, 07:50:41 PMWhy is that?
I live in Russia. I have stencils with metric and imperial dimensions.
The Russian-language stencils are in subfolder 1049 and have metric dimensions. These documents have name containing the suffix '_M'.
(https://i.imgur.com/ZcpcvPg.png)
My guess: maybe you dropped an imperial-sized shape (from stencil with the name containing the suffix '_U') onto the page and that shape has default dimensions in inches?
Title: Re: Cannot change any connectors from square to rounded corners
Post by: wapperdude on May 17, 2023, 01:06:47 AM
...and to do this with code...

This is basic code structure for VBA.  Select the shapes you want to change, run the macro.  It checks if you've selected something.  Takes the selected objects and places them in a selection collection, and then iterates through the collection.  Each member of the collection has its line color and rounding changed.  Both are hard coded into the macro.  Edit macro and put in desired values.  Delete line color line or just comment it out.

When completed, the macro deselects everything.


Sub iterateSel()
    Dim vShp As Visio.Shape
    Dim selObj As Visio.Selection
   
    Set selObj = ActiveWindow.Selection
    If selObj.Count = 0 Then
        MsgBox "You must select one or more shapes first."
    Else
        For Each vShp In selObj
            vShp.CellsSRC(visSectionObject, visRowLine, visLineColor).FormulaU = "RGB(0,0,255)"
            vShp.CellsSRC(visSectionObject, visRowLine, visLineRounding).FormulaU = "31.5 pt"
        Next
    End If

    ActiveWindow.DeselectAll
   
End Sub
[code]
Title: Re: Cannot change any connectors from square to rounded corners
Post by: Autom8It on May 17, 2023, 06:17:37 AM
Quote from: Surrogate on May 16, 2023, 09:18:29 PM
Quote from: Autom8It on May 16, 2023, 07:50:41 PM
maybe you dropped an imperial-sized shape (from stencil with the name containing the suffix '_U') onto the page and that shape has default dimensions in inches?

Thanks. I only have a 1033 folder. A few years back I downloaded a stencil of electrical circuit breakers from a manufacturer website, and then evolved these into a set that I use, but the originals were almost definitely imperial dimensions. My blank document was started with metric dimensions, but I think the imported stencil/shapes' dimensions have somehow affected the dimensions of connectors that I have drawn between these shapes. I'll have a deep dive into my master stencil and see if there's anything that can be changed.
Title: Re: Cannot change any connectors from square to rounded corners
Post by: Autom8It on May 17, 2023, 06:20:57 AM
Quote from: wapperdude on May 17, 2023, 01:06:47 AM
This is basic code structure for VBA.

Thanks so much for the sample code. This gives me a starting point from which I can start learning about the APIs and do much more.
Other than digging around this forum, if you know of a Visio code repository that can be scavenged for code snippets, please will you post that.
Much appreciated!
Title: Re: Cannot change any connectors from square to rounded corners
Post by: Yacine on May 17, 2023, 09:15:39 AM
Quote from: Autom8It on May 17, 2023, 06:20:57 AM
Other than digging around this forum, if you know of a Visio code repository that can be scavenged for code snippets, please will you post that.
Much appreciated!


Would be much appreciated indeed, but there isn't any.
My tip for Google: "stuff to search" site:visguy.com
Title: Re: Cannot change any connectors from square to rounded corners
Post by: wapperdude on May 17, 2023, 03:13:44 PM
Actually, there is at least one source of code snippets that's been around for a long time:  http://visio.mvps.org/VBA/ (http://visio.mvps.org/VBA/).  This is now managed by Visio MVP, John Marshall.

I believe that the Visio SDK free download, also has code examples.

Another tool to help learn is the macro recorder.

As Yacine mentions, the forum has tons of examples, and there's googling, or is that binging?  I frequently start a search with "Visio vba some keyword/topic"

Ed Note:  Speaking of John Marshall Visio MVP, his website as some intereesting feature, e.g., History of Visio.  See https://johnvisiomvp.ca/ (https://johnvisiomvp.ca/)
Title: Re: Cannot change any connectors from square to rounded corners
Post by: Yacine on May 18, 2023, 08:05:42 AM
There are several sites where we wanted to start a repository. Github, Stackoverflow.
This could be the occasion to continue with the project.
Github is probably the most trendy and easiest.

We could set up a kind of FAQ / HowTos

- Ways to get a handle on a shape
- How to iterate over all the shapes
- How to iterate over certain shapes
- How to modify properties of a shape and its sub-shapes
- How to automate Visio from Access/Excel
- etc.


The nice thing is that it doesn't need to be perfect. It can grow with time.
Users can write wishes.
Submissions can be improved.


Some categorization would help find stuff faster.
Title: Re: Cannot change any connectors from square to rounded corners
Post by: Autom8It on May 18, 2023, 10:00:53 AM
The MVPS site that Wapperdude listed above has a lot of helpful code and links to many other sites, some of which are now dead links. Thanks for the pointer.

Github would be great place to copy/move the code as it has the benefit of version control and branching as code is improved and features added, to avoid static old code that may use functions that become deprecated over time. Shapes, stencils and templates can be similarly managed, with different people contributing. It "open sources" some of this content using a platform bult specifically for this.

Stackoverflow is also a good idea as it probably ensures longevity beyond the old Vision static websites with tips, which I read are slowly disappearing (the dead links are evidence of that).

This would be a good topic to launch as a separate thread. It would be very informative to get the opinions and ideas of the MVPs and other folks who have vast experience with Visio.
Title: Re: Cannot change any connectors from square to rounded corners
Post by: Surrogate on May 18, 2023, 10:25:01 AM
Quote from: Autom8It on May 18, 2023, 10:00:53 AM
The MVPS site that Wapperdude listed above has a lot of helpful code and links to many other sites, some of which are now dead links. Thanks for the pointer.
Last year we tried to create a useful resource
Quote from: Surrogate on June 06, 2022, 08:08:58 AM
I added a little more information, with a readme.md to each repository:
https://github.com/Visio-Resources/Shapes-n-stencils (https://github.com/Visio-Resources/Shapes-n-stencils#readme) (based on the chapter 3rd-party additions for Microsoft Visio from the article Stuff about Visio (https://paulherber.co.uk/stuff-about-visio/) by Paul Herber (https://paulherber.co.uk/contact5.php))
https://github.com/Visio-Resources/Snippets-n-Libraries (https://github.com/Visio-Resources/Snippets-n-Libraries#readme)
https://github.com/Visio-Resources/developing-solutions (https://github.com/Visio-Resources/developing-solutions#readme)
https://github.com/Visio-Resources/Links (https://github.com/Visio-Resources/Links#readme)
We also have friendly versions on git-pages (like this (https://visio-resources.github.io/Shapes-n-stencils/)), but now these versions are not synchronized.
Unsorted collection of small macros by Surrogate (https://github.com/Surrogate-TM/surrogate-tm.github.io/tree/master/own/macro)
Some of the code has English comments, some of it is in Russian, and some files have no comments at all
Title: Re: Cannot change any connectors from square to rounded corners
Post by: Yacine on May 18, 2023, 12:48:25 PM
https://github.com/Visio-Resources/Snippets-n-Libraries/blob/main/VBA%20Handle%20on%20shapes.md
Title: Re: Cannot change any connectors from square to rounded corners
Post by: Surrogate on May 18, 2023, 01:40:19 PM
Quote from: Yacine on May 18, 2023, 12:48:25 PM
https://github.com/Visio-Resources/Snippets-n-Libraries/blob/main/VBA%20Handle%20on%20shapes.md
Cool !
Can you add some info about selection with CreateSelection method (https://learn.microsoft.com/en-us/office/vba/api/visio.page.createselection)?
My short article via Google Translate (https://gist-github-com.translate.goog/Surrogate-TM/bd55e2870e21e68dc44a5e661a4bc2cb?_x_tr_sl=ru&_x_tr_tl=en&_x_tr_hl=ru&_x_tr_pto=wapp)...
Title: Re: Cannot change any connectors from square to rounded corners
Post by: vojo on May 21, 2023, 06:28:35 PM
FWIW, I am not sure what you are trying to do

If its "curving" corners of some multisegment line,  you can do that with format or shapesheet cell
if its some sort of curved ends, you can select line ends in format or make your own line ends
   (Others are far more fluent than me...it can be done but takes alot of trial and error).

you have a before and after example???