Phenomenon with Shape.Line.LineWeight

Hello,
I would like to determine the line thickness of a shape.
If I draw a line in Visio and do not explicitly specify a line width, it is 0.75 pt. This is how it is displayed in the properties of the shape.

The problem is that the Shape.Line.LineWeight property does not always display the correct value.

Whenever you draw a new shape and the line weight is 0.75 pt by default, LineWeight = -1.7976931348623157E+308

In order for the correct value to be output, I have to set the line weight in Visio to 1.0 pt, for example, and then change it back to 0.75 pt.
Now the LineWeight value is also displayed correctly by Aspose.Diagram.

I have attached a sample file that you can use to reproduce the problem.
There are two lines. Both are 0.75 pt thick. The only difference is that the blue line is unchanged. For the red line, I have set the line width in Visio to 1.0 pt and then back to 0.75 pt. But the output is different.

Please use the following code to reproduce:

Diagram diagram = new Diagram("c://lines.vsdx");
Aspose.Diagram.Page page = diagram.Pages[0];

Aspose.Diagram.Shape blueline = null;
Aspose.Diagram.Shape redline = null;

foreach (Aspose.Diagram.Shape shape in page.Shapes)
{
	switch (shape.Name)
	{
		case "blueline":
			blueline = shape;
			break;
		case "redline":
			redline = shape;
			break;
	}
}

Console.WriteLine("Blueline LineWeight: " + blueline.Line.LineWeight.Value);
Console.WriteLine("Blueline LineWeight in pt: " + blueline.Line.LineWeight.Value * 72);
Console.WriteLine("Redline LineWeight: " + redline.Line.LineWeight.Value);
Console.WriteLine("Redline LineWeight in pt: " + redline.Line.LineWeight.Value * 72);

This is the output:
Blueline LineWeight: -1,79769313486232E+308
Blueline LineWeight in pt: -8
Redline LineWeight: 0,0104166666666667
Redline LineWeight in pt: 0,75

Do you have a tip for me on how I can use Aspose.Diagram to determine the line thickness so that it is always correct?

regards
Steve
lines.zip (10,1 KB)

@sgruth

Cause

The issue you’re encountering with the Shape.Line.LineWeight property returning an unexpected value (specifically -1.7976931348623157E+308) for newly drawn shapes in Visio is likely due to how Visio handles default line weights. When a line is drawn without explicitly setting a weight, it defaults to a specific value, but this may not be correctly reflected in the Aspose.Diagram API until the line weight is manually adjusted.

Solution

To ensure that the line weight is always correctly reported by Aspose.Diagram, you can implement a workaround by explicitly setting the line weight to a known value (like 1.0 pt) and then resetting it back to 0.75 pt. This forces the API to recognize and store the correct line weight.

Code

Here’s a modified version of your code that includes a check and sets the line weight if it’s not correctly reported:

Diagram diagram = new Diagram("c://lines.vsdx");
Aspose.Diagram.Page page = diagram.Pages[0];

Aspose.Diagram.Shape blueline = null;
Aspose.Diagram.Shape redline = null;

foreach (Aspose.Diagram.Shape shape in page.Shapes)
{
    switch (shape.Name)
    {
        case "blueline":
            blueline = shape;
            break;
        case "redline":
            redline = shape;
            break;
    }
}

// Check and set line weight for blueline if necessary
if (blueline.Line.LineWeight.Value == -1.7976931348623157E+308)
{
    blueline.Line.LineWeight.Value = 1.0; // Set to a known value
    blueline.Line.LineWeight.Value = 0.75; // Reset to desired value
}

Console.WriteLine("Blueline LineWeight: " + blueline.Line.LineWeight.Value);
Console.WriteLine("Blueline LineWeight in pt: " + blueline.Line.LineWeight.Value * 72);
Console.WriteLine("Redline LineWeight: " + redline.Line.LineWeight.Value);
Console.WriteLine("Redline LineWeight in pt: " + redline.Line.LineWeight.Value * 72);

Next Steps

  1. Test the modified code to see if the line weight for the blue line is now reported correctly.
  2. If the issue persists, check the Visio file for any inconsistencies or try recreating the shapes to see if that resolves the problem.
  3. If you continue to experience issues, please share the updated code and any new outputs for further assistance.

Please let me know if this resolves your issue!

@sgruth
Thanks for the template file and sample codes.
Please try this sample code to get inherit attributes for shape:

        Line blueLine = blueline.InheritLine;
        Line redLine = redline.InheritLine;
        Console.WriteLine("Blueline LineWeight: " + blueLine.LineWeight.Value);

Thanks.

Of course, this hint does not solve the problem. The value is displayed correctly in Visio. In this respect, it should also be possible to retrieve the value correctly via the Aspose API.

Thanks for your help. It works with InheritLine.

@sgruth
Thanks for following the suggested workaround and good know that your issue is sorted out now.
Should you have further queries or issue, feel free to write us back, we will assist you soon.