CHAPTER 5: Scripting with JavaScript Working with the perspective grid 52
Use perspective presets
Illustrator provides default grid-parameter presets for one-point, two-point, and three-point perspectives.
The presets are named
"[1P-NormalView]", "[2P-NormalView]", and "[3P-NormalView]".
This script shows how to select a preset programmatically:
//Set the default one-point perspective preset
app.activeDocument.selectPerspectivePreset("[1P-Normal View]");
//Set the default two-point perspective preset
app.activeDocument.selectPerspectivePreset("[2P-Normal View]");
//Set the default three-point perspective preset
app.activeDocument.selectPerspectivePreset("[3P-Normal View]");
You can create new perspective presets, export presets to files, and import presets from files. These scripts
shows how to export and import presets:
//Create a new document
var mydoc = app.documents.add();
//Export perspective presets to a file
var exportPresetFile = new File("C:/scripting/PGPresetsExported")
mydoc.exportPerspectiveGridPreset(exportPresetFile);
//Create a new document
var mydoc = app.documents.add();
//Import perspective presets from a file
var importPresetFile = new File("C:/scripting/PGPresets")
mydoc.importPerspectiveGridPreset(importPresetFile);
Show or hide the grid
This script shows or hides the Perspective Grid programmatically:
//Show the Perspective Grid defined in the document
app.activeDocument.showPerspectiveGrid();
//Hide the Perspective Grid defined in the document
mydoc.hidePerspectiveGrid();
Set the active plane
The perspective grid plane types are:
For a one-point perspective grid, only the left and floor plane are valid.
This script sets the active perspective plane:
Left plane
PerspectiveGridPlaneType.LEFTPLANE
Right plane
PerspectiveGridPlaneType.RIGHTPLANE
Floor plane
PerspectiveGridPlaneType.FLOORPLANE
Invalid plane
PerspectiveGridPlaneType.NOPLANE
Comments to this Manuals