Layers are invisible planes that let you organize the objects on a page. You can group related objects into layers, and you can change the vertical order (or "stacking order") of those layers to change the appearance of the page. Master layers apply to all pages in a document, while local layers apply to a single page.
Each layer, or Layer object, is a member of the Page.Layers collection for the page on which it appears. The layers in a Page.Layers collection appear in the order in which they appear on that page — the first layer is the one at the top of the "stack," and the last layer is the one at the bottom. If layers are added, reordered, or deleted, the affected Page.Layers collection is immediately updated to reflect the new layer order of that page.
Corel DESIGNER and CorelDRAW providea number of properties, methods, and events for working with layers, the most useful of which are listed in the following table.
For detailed information on any property, method, or event, see the API documentation.
For more information on layer-related activities, see the following subtopics:
You can create a layer by using the Page.CreateLayer method. Creating a layer inserts a new layer at the top of the list of non-master layers.
The following VBA code creates a new layer called "My New Layer":
ActivePage.CreateLayer "My New Layer"
If you want, you can use event handlers to respond to events that are triggered by activating a layer:
Each layer is a member of the Page.Layers collection for the page on which it appears. The layers in a Page.Layers collection appear in the order in which they appear on that page — the first layer is the one at the top of the "stack," and the last layer is the one at the bottom. If layers are added, reordered, or deleted, the affected Page.Layers collection is immediately updated to reflect the new layer order of that page.
The Document.ActiveLayer property provides direct access to the active layer for a document, while the Page.ActiveLayer property provides direct access to the active layer for a page.
You can activate a layer by using the Layer.Activate method:
ActivePage.Layers("Layer 1").Activate
Activating a locked layer does not unlock it. Similarly, activating a hidden layer does not make it visible. For information on unlocking and displaying layers, see Locking and hiding layers.
You can also use event handlers to respond to events that are triggered by deactivating a layer:
Layer objects feature the properties Editable and Visible, which control (respectively) whether the layer is editable and whether its contents are visible. Both properties are Boolean. By setting both the properties to True, you unlock and display the layer for editing. By setting either property to False, however, you lock the layer such that it cannot be edited.
The following sample VBA code locks, but displays, the layer on the active page:
ActivePage.Layers("Layer 1").Visible = True ActivePage.Layers("Layer 1").Editable = False
The result of any changes to these properties is immediately displayed in the Object Manager.
The preceding example affects only the active page. You can access the layer settings for a given page by specifying a page from the Document.Pages collection, or by referencing the Document.ActivePage property. To make the changes to all pages in a document, use the Document.MasterPage property:
ActiveDocument.MasterPage.Layers("Layer 1").Visible = True
For more information on working with pages, see Working with pages.
You can rename a layer by editing its Name property.
The following VBA code renames "Layer 1" as "Layer with a New Name":
ActivePage.Layers("Layer 1").Name = "Layer with a New Name"
Files of all supported formats can be imported.
Files are imported at the Layer level because each imported object is assigned to a specified layer on a specified page. However, files are exported at the Document level because the range of exported objects can extend over multiple layers and multiple pages (see Exporting files from documents).
The Layer class has two file-import methods: Import and ImportEx.
The wide selection of supported file formats is due to the vast number of filters that are available to the application. Each filter lets you work with the files from another graphics application. To learn more about working with these filters, see Working with import filters and export filters.
Understanding the Layer.Import method
The Layer.Import method provides basic functionality for importing files.
The following VBA code imports the file C:\logotype.gif into the active layer at the center of the page:
ActiveLayer.Import "C:\logotype.gif"
Importing a file selects the contents of that file and deselects any other selected objects in the document. You can therefore reposition or resize the imported objects by getting the document selection:
ActiveDocument.Unit = cdrInch ActiveSelection.SetSize 3, 2
Some file formats can be imported by using one of several filters, so it is important to understand the benefits of each available filter. For example, when importing an Encapsulated PostScript (EPS) file, you can choose between the EPS filter and the PDF filter. The EPS filter lets you do the following:
To specify which filter to use, you can include the optional parameter Filter, as in the following VBA example:
ActiveLayer.Import "C:\map.eps", cdrPSInterpreted
Understanding the Layer.ImportEx method
The Layer.ImportEx method provides much better control over the import filter through its optional use of a StructImportOptions object. The following VBA code imports the specified file as a linked file:
Dim iFilt As ImportFilter Dim importProps As New StructImportOptions importProps.LinkBitmapExternally = True Set iFilt = ActiveLayer.ImportEx("C:\world-map.epsf", cdrAutoSense, importProps) iFilt.Finish
As previously discussed, each layer is a member of the Page.Layers collection for the page on which it appears.
You can delete a layer by calling its Delete method. Deleting a layer removes that layer from the document, taking with it all shapes on that layer on all pages in the document.
The following VBA code deletes the layer called "Layer 1":
ActivePage.Layers("Layer 1").Delete
If you want, you can use event handlers to respond to events that are triggered by deleting a layer: