Cannot change any connectors from square to rounded corners

Started by Autom8It, May 16, 2023, 10:43:02 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Autom8It

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

Surrogate

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


Autom8It

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:


  • Iterating through all the connector lines in a file
  • Changing the attribute/value

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

Yacine

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

wapperdude

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. 
Visio 2019 Pro

Autom8It

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

Yacine

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

Autom8It

Strange? If a new diagram is created then all the ShapeSheet dimensions are millimeters. Not an inch in sight. Why is that?

Surrogate

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

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?

wapperdude

...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]
Visio 2019 Pro

Autom8It

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.

Autom8It

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!

Yacine

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
Yacine

wapperdude

Actually, there is at least one source of code snippets that's been around for a long time:  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/
Visio 2019 Pro

Yacine

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