Changes to a protected shape

I’ve added a mastershape on a page. With this shape, the width, height, aspect ratio and rotation are locked. Then an attempt was made to make the shape wider.

In Visio, the width did not appear to have changed. However, when you select the shape, the selection area is wider than the shape appears to be. The width displayed for the shape, however, is the updated width. So, visually, the shape has not changed, but Visio displays the updated values and the selection area is now exactly the same size as the updated values.

I then tried using the Shape.Protection method to check whether it was even possible to change the width of the shape. However, all the lock properties of the Protection method have the value ‘Undefined’.

VisioProtectedWidth.png (7,1 KB)

In the screenshot, you can see how this phenomenon appears in my case. The protected shape is originally 180 mm wide. I had changed the width to 183 mm using Aspose.Diagram. The selection is now wider than the shape, and the modified value is displayed as the size, even though the shape does not appear to have become any wider.

How can I find out whether the width of a shape is locked?
Is there a way to remove this protection and still change the value?

Hello,

Thank you for the detailed description and screenshot. Let me address your questions:

1. How to check if width/height is locked

You can check the protection state via Shape.Protection.LockWidth.Value and Shape.Protection.LockHeight.Value. If these return Undefined, it means the protection cell is not explicitly set in the ShapeSheet — the shape may still be protected at the master level or via the page’s default protection settings.

To properly check, also inspect:

// Check master-level protection
if (shape.Master != null)
{
    var masterProt = shape.Master.PageSheet?.Protection;
    // Check LockWidth, LockHeight here
}

2. How to unlock width/height

Use the following C# code (Aspose.Diagram for .NET):

// Explicitly set protection to false (unlocked)
shape.Protection.LockWidth.Value = false;   // BOOL.False
shape.Protection.LockHeight.Value = false;  // BOOL.False

// Also check these if the shape behaves unexpectedly:
shape.Protection.LockAspect.Value = false;    // aspect ratio lock
shape.Protection.LockRotate.Value = false;    // rotation lock

Important: The syntax (BOOL)0 is C/C++ cast syntax and will cause a compilation error in C#. Please use false or BOOL.False instead.

For Java:

shape.getProtection().getLockWidth().setValue(BOOL.FALSE);
shape.getProtection().getLockHeight().setValue(BOOL.FALSE);

3. Please share the following

After trying the code above:

  1. Your full test code (including file loading and saving)
  2. The resulting Visio file or a screenshot showing the shape behavior after unlock
  3. Any error messages if the problem persists

This will help us determine whether the issue is with protection unlocking or something else (e.g., the master shape overriding your changes).

It seems that the protection is set in the MasterShape. However, your suggestion to remove the protection from the PageSheet does not work.
A PageSheet does not have a ‘Protection’ property.

Your second suggestion, regarding setting the shape’s lock properties, doesn’t work either. The lock properties are read-only; they have no setters.

This is the vssx file and this is the source code.

Rahmen.zip (9,5 KB)

Diagram diagram = new Diagram();
string rahmen = "Hintergrund";
var masterId = diagram.AddMaster("Rahmen.vssx", rahmen);

Aspose.Diagram.Page newPage = new Aspose.Diagram.Page();
newPage.Name = "Page with Frame";

// Set pagesize to A4
int PageWidth = 210;
int PageHeight = 297;
DoubleValue PageWithMeasured = new DoubleValue(PageWidth, MeasureConst.MM);
DoubleValue PageHeightMeasured = new DoubleValue(PageHeight, MeasureConst.MM);
newPage.PageSheet.PageProps.PageWidth.Value = PageWithMeasured.Value; //8.27; // A4 width in inch
newPage.PageSheet.PageProps.PageHeight.Value = PageHeightMeasured.Value; //11.69; // A4 heigth in inch
newPage.PageSheet.PrintProps.PrintPageOrientation.Value = PrintPageOrientationValue.Portrait;
diagram.Pages.Add(newPage);

var shapeId = newPage.AddShape(0, 0, rahmen);
Aspose.Diagram.Shape theShape = newPage.Shapes.GetShape(shapeId);

theShape.XForm.PinX.Value = 111.5 / 25.4;
theShape.XForm.PinY.Value = 148.5 / 25.4;
theShape.XForm.Width.Value = 183 / 25.4; // This value is set to 180 by default and cannot be changed due to security restrictions. 
theShape.XForm.Height.Value = 283 / 25.4;

diagram.Save("PageWithFrame.vsdx", SaveFileFormat.Vsdx);

Please show me how to disable the protection and set the width to 183 / 25.4.

In the meantime, I have at least found a way to set the protection in MasterShape. As a test, I set every protection setting to false.
I also set every protection setting to false for the page’s shape.
Unfortunately, neither of these measures helped. When I now make the shape wider, only the selection becomes wider, but not the shape itself.

This is the current code.

Diagram diagram = new Diagram();
string rahmen = "Hintergrund";
var masterId = diagram.AddMaster("Rahmen.vssx", rahmen);
Aspose.Diagram.Master masterByIdIsNull = diagram.Masters.GetMaster(masterId);

Aspose.Diagram.Master masterByName = diagram.Masters.GetMasterByName("Hintergrund");
foreach (Aspose.Diagram.Shape shapeOfMaster in masterByName.Shapes)
{
    shapeOfMaster.Protection.LockAspect.Value = BOOL.False;
    shapeOfMaster.Protection.LockBegin.Value = BOOL.False;
    shapeOfMaster.Protection.LockCalcWH.Value = BOOL.False;
    shapeOfMaster.Protection.LockCrop.Value = BOOL.False;
    shapeOfMaster.Protection.LockCustProp.Value = BOOL.False;
    shapeOfMaster.Protection.LockDelete.Value = BOOL.False;
    shapeOfMaster.Protection.LockEnd.Value = BOOL.False;
    shapeOfMaster.Protection.LockFormat.Value = BOOL.False;
    shapeOfMaster.Protection.LockFromGroupFormat.Value = BOOL.False;
    shapeOfMaster.Protection.LockGroup.Value = BOOL.False;
    shapeOfMaster.Protection.LockHeight.Value = BOOL.False;
    shapeOfMaster.Protection.LockMoveX.Value = BOOL.False;
    shapeOfMaster.Protection.LockMoveY.Value = BOOL.False;
    shapeOfMaster.Protection.LockRotate.Value = BOOL.False;
    shapeOfMaster.Protection.LockSelect.Value = BOOL.False;
    shapeOfMaster.Protection.LockTextEdit.Value = BOOL.False;
    shapeOfMaster.Protection.LockThemeColors.Value = BOOL.False;
    shapeOfMaster.Protection.LockThemeEffects.Value = BOOL.False;
    shapeOfMaster.Protection.LockVtxEdit.Value = BOOL.False;
    shapeOfMaster.Protection.LockWidth.Value = BOOL.False;
}

Aspose.Diagram.Page newPage = new Aspose.Diagram.Page();
newPage.Name = "Page with Frame";

// Set pagesize to A4
int PageWidth = 210;
int PageHeight = 297;
DoubleValue PageWithMeasured = new DoubleValue(PageWidth, MeasureConst.MM);
DoubleValue PageHeightMeasured = new DoubleValue(PageHeight, MeasureConst.MM);
newPage.PageSheet.PageProps.PageWidth.Value = PageWithMeasured.Value; //8.27; // A4 width in inch
newPage.PageSheet.PageProps.PageHeight.Value = PageHeightMeasured.Value; //11.69; // A4 heigth in inch
newPage.PageSheet.PrintProps.PrintPageOrientation.Value = PrintPageOrientationValue.Portrait;
diagram.Pages.Add(newPage);

var shapeId = newPage.AddShape(0, 0, rahmen);
Aspose.Diagram.Shape theShape = newPage.Shapes.GetShape(shapeId);
theShape.Protection.LockAspect.Value = BOOL.False;
theShape.Protection.LockBegin.Value = BOOL.False;
theShape.Protection.LockCalcWH.Value = BOOL.False;
theShape.Protection.LockCrop.Value = BOOL.False;
theShape.Protection.LockCustProp.Value = BOOL.False;
theShape.Protection.LockDelete.Value = BOOL.False;
theShape.Protection.LockEnd.Value = BOOL.False;
theShape.Protection.LockFormat.Value = BOOL.False;
theShape.Protection.LockFromGroupFormat.Value = BOOL.False;
theShape.Protection.LockGroup.Value = BOOL.False;
theShape.Protection.LockHeight.Value = BOOL.False;
theShape.Protection.LockMoveX.Value = BOOL.False;
theShape.Protection.LockMoveY.Value = BOOL.False;
theShape.Protection.LockRotate.Value = BOOL.False;
theShape.Protection.LockSelect.Value = BOOL.False;
theShape.Protection.LockTextEdit.Value = BOOL.False;
theShape.Protection.LockThemeColors.Value = BOOL.False;
theShape.Protection.LockThemeEffects.Value = BOOL.False;
theShape.Protection.LockVtxEdit.Value = BOOL.False;
theShape.Protection.LockWidth.Value = BOOL.False;

theShape.XForm.PinX.Value = 111.5 / 25.4;
theShape.XForm.PinY.Value = 148.5 / 25.4;
theShape.XForm.Width.Value = 183 / 25.4; // This value is set to 180 by default and cannot be changed due to security restrictions. 
theShape.XForm.Height.Value = 283 / 25.4;

diagram.Save("PageWithFrame.vsdx", SaveFileFormat.Vsdx);

By the way, I couldn’t retrieve the master using the MasterId.

var masterId = diagram.AddMaster("Rahmen.vssx", rahmen);
Aspose.Diagram.Master masterByIdIsNull = diagram.Masters.GetMaster(masterId);

The master object was null. If you look at the collection, there is a master there, but it has a different ID to the one returned by the method diagram.AddMaster(). Why is that?

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): DIAGRAMNET-53969

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@sgruth
Please try this sample code and the output vsdx
PageWithFrame.zip (9.0 KB)

:

var shapeId = newPage.AddShape(0, 0, rahmen);
Aspose.Diagram.Shape theShape = newPage.Shapes.GetShape(shapeId);

 //add these line codes
  theShape.Protection.LockWidth.Value = BOOL.False;
  theShape.Protection.LockHeight.Value = BOOL.False;
  theShape.Protection.LockAspect.Value = BOOL.False;
  theShape.Protection.LockRotate.Value = BOOL.False;


theShape.XForm.PinX.Value = 111.5 / 25.4;
theShape.XForm.PinY.Value = 148.5 / 25.4;
theShape.XForm.Width.Value = 183 / 25.4; // This value is set to 180 by default and cannot be changed due to security restrictions. 
theShape.XForm.Height.Value = 283 / 25.4;