how to export every layer as a separate SVG? almost working..

I’m trying export every layer as a separate SVG. I’ve found this working script that creates text on each layer..

 

' creates text of the layername on each layer (create a few layers and then run this.)

Sub LayerNamed()

Dim lyr As Layer

Dim n As Long

n = 0

For Each lyr In ActivePage.Layers

lyr.CreateArtisticText 0, n, lyr.Name

n = n + 1

Next lyr

End Sub

 

that works fine, but I can’t figure out how to get my export script to select and export ONLY the shapes on each layer and not ALL the shape..

I end up with “layer1.svg”, “layer2.svg” , “layer3.svg” BUT they have all of the layers. So every svg is the same.  I can't work out the proper command to select only the layer and then export it etc..

 

Sub ExportSVG()

 

Dim lyr As Layer

Dim n As Long

Dim TT As String

n = 0

 

For Each lyr In ActivePage.Layers

 

    Dim OrigSelection As ShapeRange

    Set OrigSelection = ActiveSelectionRange

    Dim expopt As StructExportOptions

    Set expopt = CreateStructExportOptions

    expopt.UseColorProfile = False

   Dim expflt As ExportFilter

 

    Set expflt = ActiveDocument.ExportEx("C:\Temp\" & lyr.Name & ".svg", cdrSVG, cdrAllPages, expopt)

    expflt.Finish

 

  n = n + 1

Next lyr

End Sub