When I use a macro to create a new page, the layers of the provious page appear on the new one.
The macro below was recorded by creating af new document, adding two layers to the first page, adding a new page and one more and finally adding a new layer to this third page.Now Page 1 contains Layers 1 to 3 (and the Guides layer), Page 2 has Layer 1 and Page 3 Layers 1 and 2,all as intended.I then delete the created document and run the newly created macro. Surprise: The layers Layer 2 and Layer 3from Page 1 also apper on Pages 2 and 3, the latter now having two layers named Layer 2.This is, of course, unwanted, but I cant figure out why this occurs. Any suggestions?Best wishesHolger NielsenSub Macro7() ' Recorded 2017-11-14 Dim createopt As StructCreateOptions Set createopt = CreateStructCreateOptions With createopt .Name = "TestPageLayerCreation" .Units = cdrMillimeter .PageWidth = 210# .PageHeight = 297# .Resolution = 300# .ColorContext = CreateColorContext2("sRGB IEC61966-2.1,ISO Coated v2 (ECI),Dot Gain 15%", BlendingColorModel:=clrColorModelCMYK) End With Dim doc1 As Document Set doc1 = CreateDocumentEx(createopt) Dim lr1 As Layer Set lr1 = ActivePage.CreateLayer("Layer 2") Dim lr2 As Layer Set lr2 = ActivePage.CreateLayer("Layer 3") Dim p1 As Page Set p1 = doc1.InsertPagesEx(1, False, ActivePage.Index, 8.267717, 11.692913) Dim p2 As Page Set p2 = doc1.InsertPagesEx(1, False, p1.Index, 8.267717, 11.692913) Dim lr3 As Layer Set lr3 = p2.CreateLayer("Layer 2")End Sub
In my limited experience, adding pages using VBA also creates the layers that were present on the previous page.
I observe that even with something as simple as this:
Sub add_a_page() ActiveDocument.AddPages 1End Sub
Since you are creating a new document, you might add the pages first, then create the layers you want on the different pages.
Hi Eskimo
Thanks for your response, I am glad you agree with what I have noticed.
But why was it made like that? The programmers at Corel understood, that pages can have different sizes, but why should they insist that layers from a previous page should also be useful on a new one? I consider this a bug, because this behavior does not occur, if the page is added manually by clicking the New Page icon.
You suggest to create the pages first, but I prefer to complete a page before turning to the next, so instead I delete the unwanted layers. I have edited the macro to demonstrate how the layers appear, see the subs below.
An oddity: No layer seems to have index number 1, the Guides layer has index 0, and I would have supposed the default layer "Layer 1" to have index 1, but no, its index is 2.
Hm, I can't figure out to change the font of the code below to Courier...
Sub ReportPageLayers(pg As Page) Dim lr As Layer Debug.Print pg.Name For Each lr In pg.Layers Debug.Print lr.Index; lr.Name Next lr Debug.PrintEnd SubSub DeletePageLayers(pg As Page) Dim lr As Layer For Each lr In pg.Layers If lr.Index > 0 Then lr.Delete Next lr Debug.PrintEnd SubSub TestPageCreation() Dim createopt As StructCreateOptions Dim doc As Document, pg1 As Page, pg2 As Page, pg3 As Page, lr As Layer Set createopt = CreateStructCreateOptions With createopt .Name = "TestPageLayerCreation" .Units = cdrMillimeter .PageWidth = 210# .PageHeight = 297# .Resolution = 300# .ColorContext = CreateColorContext2("sRGB IEC61966-2.1,ISO Coated v2 (ECI),Dot Gain 15%", BlendingColorModel:=clrColorModelCMYK) End With Set doc = CreateDocumentEx(createopt) Set pg1 = ActivePage ReportPageLayers pg1 pg1.Layers("Layer 1").Name = "Frame layer" ReportPageLayers pg1 Set lr = pg1.CreateLayer("Second layer") ReportPageLayers pg1 Set lr = pg1.CreateLayer("Third layer") ReportPageLayers pg1 Set pg2 = doc.InsertPagesEx(1, False, pg1.Index, 8.267717, 11.692913) ReportPageLayers pg2 DeletePageLayers pg2 ReportPageLayers pg2 Set pg3 = doc.InsertPagesEx(1, False, pg2.Index, 8.267717, 11.692913) ReportPageLayers pg3 Set lr = pg3.CreateLayer("New layer on page 3") ReportPageLayers pg3End Sub
Holger Nielsen said:But why was it made like that? The programmers at Corel understood, that pages can have different sizes, but why should they insist that layers from a previous page should also be useful on a new one? I consider this a bug, because this behavior does not occur, if the page is added manually by clicking the New Page icon.
I don't know the history of this, but my VBA experience with CorelDRAW is limited to <2 years.
If I go back to CorelDRAW X3, then manually creating a New Page using the button in the UI does in fact create the same layers in the new page as were in the previous page. In X5, it does not - so I am guessing that something changed in how it works in the regular user interface.