Layers

Last post 02-14-2012, 8:31 PM by DeanMc. 2 replies.
Sort Posts: Previous Next
  •  02-09-2012, 1:42 AM 360280

    Layers .NET

    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

     

     
  •  02-10-2012, 5:39 AM 360697 in reply to 360280

    Re: Layers

    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,


    Muhammad Ijaz
    Support Developer, Aspose Sialkot Team
    Contact Us
    http://www.aspose.com
    Your File Format Experts

    Keep in touch! We're on Twitter and Facebook
     
  •  02-14-2012, 8:31 PM 361661 in reply to 360697

    Re: Layers .NET

    Hi Muhammad

    Thanks for the sample code

    Cheers Dean

     
View as RSS news feed in XML