Sign up
Login
New
Trending
Archive
English
English
Sign up
Login
New Paste
Add Image
#target illustrator if (app.documents.length === 0) { alert("No document open"); exit(); } var doc = app.activeDocument; // ================= UI ================= var win = new Window("dialog", "CTP Sheet Optimizer"); win.alignChildren = "left"; // Sheet Panel var pSheet = win.add("panel", undefined, "Sheet Size"); pSheet.orientation = "grid"; pSheet.add("statictext", undefined, "Width:"); var sheetW = pSheet.add("edittext", undefined, "23"); sheetW.characters = 6; pSheet.add("statictext", undefined, "Height:"); var sheetH = pSheet.add("edittext", undefined, "36"); sheetH.characters = 6; // Design Source var pSource = win.add("panel", undefined, "Design Size From"); pSource.orientation = "column"; var rSel = pSource.add("radiobutton", undefined, "Selected Object"); var rArt = pSource.add("radiobutton", undefined, "Artboard"); rSel.value = true; // Spacing var pSpace = win.add("panel", undefined, "Margin / Gap (mm)"); pSpace.orientation = "grid"; pSpace.add("statictext", undefined, "Margin:"); var margin = pSpace.add("edittext", undefined, "10"); margin.characters = 6; pSpace.add("statictext", undefined, "Gap:"); var gap = pSpace.add("edittext", undefined, "5"); gap.characters = 6; // Rotation var rotateChk = win.add("checkbox", undefined, "Allow 90° Rotation"); rotateChk.value = true; // Result var pResult = win.add("panel", undefined, "Result"); pResult.orientation = "column"; var resultTxt = pResult.add("statictext", undefined, "", {multiline:true}); resultTxt.preferredSize.width = 260; resultTxt.preferredSize.height = 80; // Buttons var btnGroup = win.add("group"); var calcBtn = btnGroup.add("button", undefined, "Calculate"); btnGroup.add("button", undefined, "Cancel", {name:"cancel"}); // ================= LOGIC ================= calcBtn.onClick = function () { var sheetWidth = parseFloat(sheetW.text); var sheetHeight = parseFloat(sheetH.text); var m = parseFloat(margin.text) * 2.8346; // mm to pt var g = parseFloat(gap.text) * 2.8346; var dW, dH; if (rSel.value) { if (doc.selection.length === 0) { alert("Please select an object"); return; } var b = doc.selection[0].visibleBounds; dW = b[2] - b[0]; dH = b[1] - b[3]; } else { var ab = doc.artboards[doc.artboards.getActiveArtboardIndex()].artboardRect; dW = ab[2] - ab[0]; dH = ab[1] - ab[3]; } // inch to pt sheetWidth *= 72; sheetHeight *= 72; var usableW = sheetWidth - m; var usableH = sheetHeight - m; var col1 = Math.floor((usableW + g) / (dW + g)); var row1 = Math.floor((usableH + g) / (dH + g)); var total1 = col1 * row1; var total2 = 0; if (rotateChk.value) { var col2 = Math.floor((usableW + g) / (dH + g)); var row2 = Math.floor((usableH + g) / (dW + g)); total2 = col2 * row2; } var best = Math.max(total1, total2); resultTxt.text = "Normal Fit : " + total1 + " pcs\n" + "Rotated Fit: " + total2 + " pcs\n\n" + "BEST FIT : " + best + " pcs per sheet"; }; win.center(); win.show();
Settings
Title :
[Optional]
Paste Folder :
[Optional]
Select
Syntax :
[Optional]
Select
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Expiration :
[Optional]
Never
Self Destroy
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Status :
[Optional]
Public
Unlisted
Private (members only)
Password :
[Optional]
Description:
[Optional]
Tags:
[Optional]
Encrypt Paste
(
?
)
Create Paste
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Site Languages
×
English