Sg 2.9
Document
Packages RSS
About
News
Gallery
Scripts
Tutorials
Download
Reference
Forum
Users
License
Twitter

The Document item refers to an Illustrator document.

The currently active document can be accessed through the global document variable.

An array of all open documents is accessible through the global documents variable.

Constructors

Opens an existing document.

Sample code:

var file = new File('/path/to/poster.ai');
var poster = new Document(file);
    Parameters:
  • file: File — the file to read from
  • colorModel: String — the document's desired color model ('gray', 'rgb', 'cmyk') — optional, default: 'cmyk'
  • dialogStatus: String — how dialogs should be handled ('none', 'on', 'partial-on', 'off') — optional, default: 'none'
    Throws:
  • FileNotFoundException

Creates a new document.

Sample code:

// Create a new document named 'poster'
// with a width of 100pt and a height of 200pt:
var doc = new Document('poster', 100, 200);;
// Create a document with a CMYK color mode
// and show Illustrator's 'New Document' dialog:
var doc = new Document('poster', 100, 200, 'cmyk', 'on');
    Parameters:
  • title: String — the title of the document
  • width: Number — the width of the document
  • height: Number — the height of the document
  • colorModel: String — the document's desired color model ('gray', 'rgb', 'cmyk') — optional, default: 'cmyk'
  • dialogStatus: String — how dialogs should be handled ('none', 'on', 'partial-on', 'off') — optional, default: 'none'

Operators

    Returns:
  • Boolean

Properties

The selected items contained within the document. Read-only.

    Returns:
  • Array of Item, also accessible by name

The currently active Illustrator path style. All selected items and newly created items will be styled with this style.

The point of the lower left corner of the imageable page, relative to the ruler origin.

The point of the ruler origin of the document, relative to the bottom left of the artboard.

The size of the document. Setting size only works while reading a document!

    Returns:
  • String ('gray', 'rgb', 'cmyk')

Specifies if the document has been edited since it was last saved. When set to true, closing the document will present the user with a dialog box asking to save the file.

    Returns:
  • Boolean

The file associated with the document. Read-only.

    Returns:
  • File
    Returns:
  • FileFormat

An object contained within the document which can be used to store data. The values in this object can be accessed even after the file has been closed and opened again. Since these values are stored in a native structure, only a limited amount of value types are supported: Number, String, Boolean, Item, Point, Matrix.

Sample code:

document.data.point = new Point(50, 50);
print(document.data.point); // {x: 50, y: 50}
    Returns:
  • Object

Document Hierarchy

The layers contained within the document.

Sample code:

// When you create a new Document it always contains
 // a layer called 'Layer 1'
 print(document.layers); // Layer (Layer 1)
 // Create a new layer called 'test' in the document
 var newLayer = new Layer();
 newLayer.name = 'test';
 print(document.layers); // Layer (test), Layer (Layer 1)
 print(document.layers[0]); // Layer (test)
 print(document.layers.test); // Layer (test)
 print(document.layers['Layer 1']); // Layer (Layer 1)
Read-only.

    Returns:
  • Array of Layer, read-only, also accessible by name

The layer which is currently active. The active layer is indicated in the Layers palette by a black triangle. New items will be created on this layer by default. Read-only.

    Returns:
  • Layer — The layer which is currently active

The symbols contained within the document. Read-only.

    Returns:
  • Array of Symbol, read-only, also accessible by name

The symbol which is selected in the Symbols menu. Read-only.

The swatches contained within the document.

Sample code:

var firstSwatch = document.swatches[0];
var namedSwatch = document.swatches['CMYK Blue'];
Read-only.

    Returns:
  • Array of Swatch, read-only, also accessible by name

The artboards contained in the document.

The document views contained within the document. Read-only.

The document view which is currently active. Read-only.

The stories contained within the document. Read-only.

The selected text as a text range.

Sample code:

var range = document.selectedTextRange;
// Check if there is a selected range:
if(range) {
	range.characterStyle.fontSize += 15;
}
Read-only.

Functions

Activates this document, so all newly created items will be placed in it.

    Parameters:
  • focus: Boolean — When set to true, the document window is brought to the front, otherwise the window sequence remains the same. Default is true. — optional

Returns all items that match a set of attributes, as specified by the passed map. For each of the keys in the map, the demanded value can either be true or false.

Sample code:

// All selected paths and rasters contained in the document.
var selectedItems = document.getItems({ 
 type: [Path, Raster], 
 selected: true
});
// All visible Paths contained in the document.
var visibleItems = document.getItems({
 type: Path,
 hidden: false
});
    Parameters:
  • attributes: ItemAttributes — an object containing the various attributes to check for.
    Returns:
  • Array of Item, also accessible by name

Saves the document.

Closes the document.

Forces the document to be redrawn.

Places a file in the document.

Sample code:

var file = new File('/path/to/image.jpg');
var item = document.place(file);
    Parameters:
  • file: File — the file to place
  • linked: Boolean — when set to true, the placed object is a link to the file, otherwise it is embedded within the document — optional

Invalidates the rectangle in artwork coordinates. This will cause all views of the document that contain the given rectangle to update at the next opportunity.

    Parameters:
  • file: File
  • ask: Boolean
    Returns:
  • Boolean

Selects all items in the document.

Deselects all selected items in the document.

    Parameters:
  • point: Point
  • request: String ('all', 'anchors', 'points', 'end-anchors', 'end-points', 'guides', 'paths', 'text-items', 'texts', 'selection', 'all-except-guides', 'paintables', 'all-except-fills', 'all-except-handles', 'all-except-guides-and-fills', 'all-except-guides-and-locked') — optional
  • tolerance: Number — the hit-test tolerance in view coordinates (pixels at the current zoom factor). correct results for large values are not guaranteed — optional, default: 2
    Parameters:
  • point: Point
  • tolerance: Number

Text reflow is suspended during script execution. when reflowText() is called, the reflow of text is forced.

Checks whether the document is valid, i.e. it hasn't been closed.

Sample code:

var doc = document;
print(doc.isValid()); // true
doc.close();
print(doc.isValid()); // false
    Returns:
  • Booleantrue if the document is valid, false otherwise

Clipboard Functions

Cuts the selected items to the clipboard.

Copies the selected items to the clipboard.

Pastes the contents of the clipboard into the active layer of the document.

AltStyle によって変換されたページ (->オリジナル) /