Move Layer

 

Version Info

Minimum Origin Version Required: Origin 8 SR2

Example

This example shows how to move one layer from one page to another page with Page::AddLayer method.

void wks_move_ex()
{
        // 1. prepare source worksheet page
        WorksheetPage wksSourcePage;
        wksSourcePage.Create("Origin");
        wksSourcePage.Rename("Source");
        wksSourcePage.AddLayer(); // add more one worksheet layer.
        
        Worksheet wks = wksSourcePage.Layers(0);
        wks.SetName("ABC");
        DataRange dr;
        dr.Add(wks, 0, "X");
        dr.Add(wks, 1, "Y");
        
        vector vx, vy;
        vx.Data(0.5, 100, 0.5);
        vy = vx * 10;
        dr.SetData(&vy, &vx);
        
        // 2. prepare destination worksheet page
        WorksheetPage wksDestPage;
        wksDestPage.Create("Origin");
        wksDestPage.Rename("Dest");
        
        // 3. Move worksheet from one page to another page
        printf("Before moving....\n");
        print_out_layer_names(wksSourcePage);
        print_out_layer_names(wksDestPage);
        
        // want move "ABC" layer from "Source" page to "Dest" page as the first one layer
        BOOL       bKeepSrcLayer = false;
        int        nNewLayerPos = 0;
        bool       bRet = wksDestPage.AddLayer(wks, DCTRL_COPY_DEFAULT, bKeepSrcLayer, nNewLayerPos); 

        printf("After moving....\n");
        print_out_layer_names(wksSourcePage);
        print_out_layer_names(wksDestPage);
        
}

static void print_out_layer_names(WorksheetPage& wksPage)
{
        int ii = 0;
        printf("Layers in %s page: \n", wksPage.GetName());
        foreach(Layer lay in wksPage.Layers)
        {
                printf("\tLayer %d = %s\n", ++ii, lay.GetName())
        }
}