Layers

Can someone please provide code on how to Add / Remove a shape to / from a Layer.

In VBA I use:

Function MoveLayer(MyFromLayer As String, MyToLayer As String, MyShape As String)
Dim TheShape As Shape
Dim TheLayers As Layers
Dim FromLayer As Layer
Dim ToLayer As Layer

Set TheLayers = ActivePage.Layers
Set ToLayer = TheLayers(MyToLayer)
Set FromLayer = TheLayers(MyFromLayer)
Set TheShape = ActivePage.Shapes(MyShape)

ToLayer.Add TheShape, 0
FromLayer.Remove TheShape, 0

End Function

I assume you'd use LayerCollection.Add, but I'm unsure how to go about it.

Thanks in advance ~ Dean

Hi Dean,

You can use the following code to add / remove shapes to / from layers.

'Find a particular shape and add/remove it to/from layers

For Each shape As Aspose.Diagram.Shape In diagram.Pages(0).Shapes

If shape.Name.ToLower() = "shape1" Then

'Add shape1 in first two layers. Here "0;1" are indexes of the layers

Dim layer As LayerMem = shape.LayerMem

layer.LayerMember.Value = "0;1"

ElseIf shape.Name.ToLower() = "shape2" Then

'Remove shape2 from all the layers

Dim layer As LayerMem = shape.LayerMem

layer.LayerMember.Value = ""

ElseIf shape.Name.ToLower() = "shape3" Then

'Add shape3 in first layer. Here "0" is index of the first layer

Dim layer As LayerMem = shape.LayerMem

layer.LayerMember.Value = "0"

End If

Next shape

diagram.Save("Drawing1.vdx", SaveFileFormat.VDX)

Best Regards,

Hi Muhammad

Thanks for the sample code

Cheers Dean

This procedure doesn’t seem to work with Visio 2013 VSDX files. Is there a different process now?

I have the shapes on a layer that has Visible set to false, but when saving to a png these layers are visible.

Cheers

Dean

Hi Dean,

Thank you for providing the details. We have tested a sample VSDX drawing against the given scenario. We managed to replicate the shape visibility when it’s layer is set to false. We have logged this issue under ticket id DIAGRAMNET-50286 in our issue tracking system. However, we recommend you to share your problematic VSDX drawing too. It will be for confirmation purposes. Your request has also been linked to this issue. We’ll keep you informed regarding any available updates. We’re sorry for the inconvenience caused.

Hi Imran

Thanks for the update.

As requested, I have attached a simple VSDX file with 1 shape, where the first sub shape is on a visible layer (Show), and the subsequent sub shapes are on a non-visible layer (Hide).

Also, the rendering to a png looks “rough” compared to a VDX.

What is the best quality image type and settings to use?

Cheers

Dean

Hi Dean,


Thank you for supplying sample Visio drawing. We have logged it against the ticket id DIAGRAMNET-50286 in our issue tracking system. The Resolution, ImageBrightness and SmoothingMode properties allow to improve the output images to increase the quality of the output. Also, please try to set the resolution to 300 or more to see if it produces the output according to your requirement.

[C#]
Diagram diagram = new Diagram(@“C:\temp\EOC.vsdx”);
ImageSaveOptions options = new ImageSaveOptions(SaveFileFormat.PNG);
options.Resolution = 300;
options.ImageBrightness = 0.45f;
diagram.Save(@“C:\temp\output.png”, options);

We hope, this helps.

Hi Dean,

Thank you for being patient. We have a good news for you that the issue id DIAGRAMNET-50286 has now been resolved. If there is no issue in the QA phase, then this fix will be included in the next version of Aspose.Diagram for .NET 4.6.0. Its release date is not final yet. We'll inform you via this forum thread as soon as the new release is published.

The issues you have found earlier (filed as DIAGRAMNET-50286) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

The issues you have found earlier (filed as ) have been fixed in this Aspose.Words for JasperReports 18.3 update.