Visio Guy

Visio Discussions => Programming & Code => Topic started by: Visisthebest on April 14, 2022, 07:59:24 PM

Title: Keeping the aspect ratio lock working with VBA
Post by: Visisthebest on April 14, 2022, 07:59:24 PM
When I set the Aspect Ratio lock on a shape:

Shape.CellsSRC(visSectionObject, visRowLock, visLockAspect).FormulaU = "1"

it works with the UI but not if I set shape width directly, with

Shape.CellsU("Width).FormulaU = "1 in"

for instance. The aspect ratio is changed. Is there a way to change the size via VBA of a shape where the Aspect Ratio lock just corrects the other dimension automatically to keep the aspect ratio unchanged?
Title: Re: Keeping the aspect ratio lock working with VBA
Post by: Yacine on April 15, 2022, 09:10:54 AM
This is definitely a bug!

As work around you may check for this protection (shp.Cells("LockAspect").ResultIU = 1) and correct the other dimension accordingly.

As this would be tedious to write in your regular code and you may forget it, a function could help

eg instead of targeting the width or height directly, you would call a "setWidth" / "setHeight" function.
Title: Re: Keeping the aspect ratio lock working with VBA
Post by: Visisthebest on April 15, 2022, 10:03:36 AM
Good to know this is a bug, I just added an aspect ratio correction to my code but was indeed surprised that the aspect ratio isn't enforced for code changing width or height.
Title: Re: Keeping the aspect ratio lock working with VBA
Post by: Paul Herber on April 15, 2022, 10:43:03 AM
I suppose it is a bug of a sort, but it's probably designed behaviour right from the start, so changing it might break stuff.
Title: Re: Keeping the aspect ratio lock working with VBA
Post by: Yacine on April 15, 2022, 12:40:25 PM
Jein (= Ja and Nein = Yes and No).
Whilst there will always be situations where you'll need to prevent stuff to break, you still have a (kind of) responsibility of keeping the logic understandable and consistent.
In this case, at least a warning, would notify the user of unsuitable commands.
Not the finest of what they've done so far.