Working with Projects and Layouts
The work you do in QuarkXPress is centered around Projects and Layouts. Most of the time you interact with a single layout (i.e. the active layout) but your work is saved on the disk in the form of a Project only. One project can have many layouts of different types. You can layouts of type print, digital or both in a single project. So, the project acts as a container for the layouts as well as all the resources (colors, style sheets, fonts etc.). This section shows you how to perform basic operations on the projects and layouts.
In the JavaScripting environment (i.e. qx.js), a QuarkXPress project is represented by the 'Project' class and the layouts in a project by the 'Layout' class.These are JavaScript classes so you need to create an instance of these classes to access their properties or methods.
You can do the followings using the 'Project' and 'Layout' classes:
-
Save or down-save the project
-
Close the project
-
Discover the location of the project on the disk
-
Query the resources available in a project
-
Add new layouts to a project
-
Delete a layout from the project
-
Duplicate a layout in the project
-
Discover the unique identity of the layout
-
Generate a PDF of a layout
Basic operations using the Project class
In this section we see code snippets for doing basic operations using the Project class.
How to close a project
Use the following script to close a project:
let curProj = app.activeProject();
curProj.closeProject();
In this script, we first get the reference to the active project. This is the instance of 'Project' class for the current project in the application. Once you get the reference, you can call any method on this object. If you have edits in the project it will not ask for you to save the project. If you want the user to confirm the saving of the project, you need to provide the closing flag.
Use the following code snippet to ask the user to confirm before closing the project:
let curProj = app.activeProject();
curProj.closeProject(app.constants.projectCloseTypes.QUERY_CLOSE_PROJECT);
How to save a project on the disk
Use the following script to save a project:
let curProj = app.activeProject();
p.saveProject("D:\\abc.qxp");
This script will save the project on Windows OS at D:\abc.qxp. All of the saveProject method parameters are optional for a project which is already saved on the disk. If
it is a new project then you must provide the location where you want to save it.
If you want to save the project in the previous version of the application, use the following code snippet.
let curProj = app.activeProject();
p.saveAsProject("D:\\abc.qxp", true);
How to add a new layout in the project
Use the following code snippet to add a new layout in the current project:
let curProj = app.activeProject();
let plo= new app.PrintLayoutOptions("500mm", "300mm", ["36", "36", "36", "36"], false, 5, "2mm", true, 6, true);
p.createLayout('FF', app.constants.layoutMediaTypes.PRINT_MEDIA_TYPE, plo);
This script first gets the reference to the current project and then initializes the
layout properties for the new layout. The layout properties can be get and set using
the PrintLayoutOptions class. You can also provide the measurement unit along with the property value. If the
measurement unit is missing, QuarkXPress will use the measurement unit from the layout
or application defaults.
How to discover resources in the project
All of the resources (a.k.a. assets) are stored at the project level. The following code snippet shows you how to query different kind of resources from the project.
Use the following code snippet to discover the paragraph style sheets used in this project:
let myProj = app.activeProject;
myProj.getAssets(app.constants.assetTypes.kAssetParaStyle);
This code snippet requests all of the paragraph style sheets. The getAmethod takes the type of asset as input. All of the asset types are defined in the
ssets app.constants.assetTypes namespace. For more details about available asset types, please see the QX.js API
Reference.
Basic operations using the Layout class
Most of the operations on a layout will be performed using the QXML DOM based APIs. The QXML DOM is retrieved directly from an 'app' object but if you already reference a layout object, then you can instead get the QXML DOM from that.
let myLayout = app.activeLayout();
let myDom = myLayout.getDOM();
// Do the operations using QXML DOM APIs.
To retrieve layout properties like page margins or gutter width of any layout, use this object.
let myLayout = app.activeLayout();
let plo= myLayout.getPrintLayoutOptions();
Use the following code snippet to duplicate a layout:
let myLayout = app.activeLayout();
myLayout.duplicate();
This code will duplicate a layout in the current project. To duplicate a layout with
a custom name, you must provide the name. You can provide the custom layout properties
using PrintLayoutOptions class but all the properties will not honored.
Another important operation is generating th PDF output of the layout. You do this using the Layout object. This is explained in the Introduction to QuarkXPress JavaScript objects section.