Copy link to clipboard
Copied
I'm trying to create multiple gradientstops but i can only create one.... please help...
My script sofar:
var omf = 2.834645;
var x=0;
var y=0;
var verschuivingx = 0;
var verschuivingy = 0;
var size= 0;
docPreset = new DocumentPreset;
docPreset.width = 100*omf;
docPreset.colorMode = DocumentColorSpace.CMYK
docPreset.previewMode = DocumentPreviewMode.OverprintPreview;
docPreset.rasterResolution = DocumentRasterResolution.HighResolution;
docPreset.title = "testgradient";
docPreset.rulerUnits = RulerUnits.Millimeters;
docPreset.height = (100*omf);
docPreset.name = "testgradient";
var doc = app.documents.addDocument(DocumentColorSpace.CMYK,docPreset);
app.activeDocument.layers[0].name = "testgradient";
var line = doc.pathItems.add();
line.setEntirePath(Array(Array(((x+167.922261870534+verschuivingx)*omf),((y+99.0916493732019+size - verschuivingy)*omf)),Array(((x+39.8638983011982+verschuivingx)*omf),((y+99.0916493732019+size - verschuivingy)*omf)),Array(((x+39.8638983011982+verschuivingx)*omf),((y+215.861121388216+size - verschuivingy)*omf)),Array(((x+167.922261870534+verschuivingx)*omf),((y+215.861121388216+size - verschuivingy)*omf))));
line.pathPoints[0].leftDirection = Array(((x+167.922261870534+verschuivingx)*omf),((y+99.0916493732019-verschuivingy)*omf));
line.pathPoints[0].rightDirection = Array(((x+167.922261870534+verschuivingx)*omf),((y+99.0916493732019-verschuivingy)*omf));
line.pathPoints[1].leftDirection = Array(((x+39.8638983011982+verschuivingx)*omf),((y+99.0916493732019-verschuivingy)*omf));
line.pathPoints[1].rightDirection = Array(((x+39.8638983011982+verschuivingx)*omf),((y+99.0916493732019-verschuivingy)*omf));
line.pathPoints[2].leftDirection = Array(((x+39.8638983011982+verschuivingx)*omf),((y+215.861121388216-verschuivingy)*omf));
line.pathPoints[2].rightDirection = Array(((x+39.8638983011982+verschuivingx)*omf),((y+215.861121388216-verschuivingy)*omf));
line.pathPoints[3].leftDirection = Array(((x+167.922261870534+verschuivingx)*omf),((y+215.861121388216-verschuivingy)*omf));
line.pathPoints[3].rightDirection = Array(((x+167.922261870534+verschuivingx)*omf),((y+215.861121388216-verschuivingy)*omf));
line.closed = true;
line.stroked= false;
line.filled= true;
var newGradient = app.activeDocument.gradients.add();
newGradient.name = "NewGradient0";
newGradient.type=GradientType.LINEAR;
var itemColor1 = new CMYKColor();
itemColor1.cyan = 0;
itemColor1.magenta = 100;
itemColor1.yellow = 100;
itemColor1.black = 0;
newGradient.gradientStops[1].color = itemColor1;
newGradient.gradientStops[1].rampPoint=100;
newGradient.gradientStops[1].midPoint=50;
var itemColor0 = new CMYKColor();
itemColor0.cyan = 0;
itemColor0.magenta = 0;
itemColor0.yellow = 100;
itemColor0.black = 0;
newGradient.gradientStops[0].color = itemColor0;
newGradient.gradientStops[0].rampPoint=0;
newGradient.gradientStops[0].midPoint=50;
var colorOfGradient = new GradientColor();
colorOfGradient.gradient = newGradient;
line.fillColor = colorOfGradient;
line.fillOverprint = false;
line.rotate(130,false,false,true,false);
var grdntstop = doc.gradients.getByName("NewGradient0").gradientStops.add();
var itemColor3 = new CMYKColor();
itemColor3.cyan = 0;
itemColor3.magenta = 75;
itemColor3.yellow = 100;
itemColor3.black = 0;
grdntstop.color = itemColor3;
grdntstop.rampPoint=74.2331237792969;
grdntstop.midPoint=50;
var grdntstop = doc.gradients.getByName("NewGradient0").gradientStops.add();
var itemColor2 = new CMYKColor();
itemColor2.cyan = 30;
itemColor2.magenta = 100;
itemColor2.yellow = 0;
itemColor2.black = 0;
grdntstop.color = itemColor2;
grdntstop.rampPoint=50;
grdntstop.midPoint=50;
var grdntstop = doc.gradients.getByName("NewGradient0").gradientStops.add();
var itemColor1 = new CMYKColor();
itemColor1.cyan = 85;
itemColor1.magenta = 10;
itemColor1.yellow = 100;
itemColor1.black = 0;
grdntstop.color = itemColor1;
grdntstop.rampPoint=22.6993865966797;
grdntstop.midPoint=50;
var illustratorversion = app.version;
var illustratorversionarray = illustratorversion.split(".");
if(illustratorversionarray[0]>13){
app.activeDocument.artboards[0].artboardRect = app.activeDocument.visibleBounds;
}
zet_nulpunt();
zoomcenterpage()
function zoomcenterpage(){
var myView=app.activeDocument.views[0];
myView.centerPoint = [(app.activeDocument.width/2),(app.activeDocument.height/2)];
myView.zoom = 1
myView.screenMode.FULLSCREEN;
}
function zet_nulpunt(){
// zet nulpunt linksonder
app.activeDocument.pageOrigin = Array(0,0);
app.activeDocument.rulerOrigin = Array(0,0);
}
I found an error in your script.
We have to put ramp point from smaller points. but your script set rampPoint 75%.
var grdntstop = doc.gradients.getByName("NewGradient0").gradientStops.add();
var itemColor3 = new CMYKColor();
itemColor3.cyan = 0;
itemColor3.magenta = 75;
itemColor3.yellow = 100;
itemColor3.black = 0;
grdntstop.color = itemColor3;
grdntstop.rampPoint=22.6993865966797;
grdntstop.midPoint=50;
var grdntstop = doc.gradients.getByName("NewGradient0").gradientStops.add();
var itemColor2 = new CMY
Copy link to clipboard
Copied
Hi
I rewrite this code of apply gradient colors like below.
var itemColor = new Array();
itemColor[2] = new CMYKColor();
itemColor[2].cyan = 0;
itemColor[2].magenta = 75;
itemColor[2].yellow = 100;
itemColor[2].black = 0;
itemColor[1] = new CMYKColor();
itemColor[1].cyan = 30;
itemColor[1].magenta = 100;
itemColor[1].yellow = 0;
itemColor[1].black = 0;
itemColor[0] = new CMYKColor();
itemColor[0].cyan = 85;
itemColor[0].magenta = 10;
itemColor[0].yellow = 100;
itemColor[0].black = 0;
for (i=0;i<itemColor.length;i++){
grdntstop= doc.gradients.getByName("NewGradient0").gradientStops.add();
grdntstop.color = itemColor;
grdntstop.rampPoint = (i+1)/(itemColor.length+1)*100;
grdntstop.midPoint=50;
}
perhaps, you have to separate gradientStops object.
Ten wrote.
Copy link to clipboard
Copied
Will this solve the rampPoint problem of the script
?
Cheers Daniel
Copy link to clipboard
Copied
yes, full code is below.
var omf = 2.834645;
var x=0;
var y=0;
var verschuivingx = 0;
var verschuivingy = 0;
var size= 0;
docPreset = new DocumentPreset;
docPreset.width = 100*omf;
docPreset.colorMode = DocumentColorSpace.CMYK
docPreset.previewMode = DocumentPreviewMode.OverprintPreview;
docPreset.rasterResolution = DocumentRasterResolution.HighResolution;
docPreset.title = "testgradient";
docPreset.rulerUnits = RulerUnits.Millimeters;
docPreset.height = (100*omf);
docPreset.name = "testgradient";
var doc = app.documents.addDocument(DocumentColorSpace.CMYK,docPreset);
app.activeDocument.layers[0].name = "testgradient";
var line = doc.pathItems.add();
line.setEntirePath(Array(Array(((x+167.922261870534+verschuivingx)*omf ),((y+99.0916493732019+size - verschuivingy)*omf)),
Array(((x+39.8638983011982+verschuivingx)*omf),( (y+99.0916493732019+size - verschuivingy)*omf)),Array(((x+39.8638983011982+verschuivingx)*omf),
( (y+215.861121388216+size - verschuivingy)*omf)),Array(((x+167.922261870534+verschuivingx)*omf),( (y+215.861121388216+size - verschuivingy)*omf))));
line.pathPoints[0].leftDirection = Array(((x+167.922261870534+verschuivingx)*omf),((y+99.0916493732019-verschuivingy)*omf));
line.pathPoints[0].rightDirection = Array(((x+167.922261870534+verschuivingx)*omf),((y+99.0916493732019-verschuivingy)*omf));
line.pathPoints[1].leftDirection = Array(((x+39.8638983011982+verschuivingx)*omf),((y+99.0916493732019-verschuivingy)*omf));
line.pathPoints[1].rightDirection = Array(((x+39.8638983011982+verschuivingx)*omf),((y+99.0916493732019-verschuivingy)*omf));
line.pathPoints[2].leftDirection = Array(((x+39.8638983011982+verschuivingx)*omf),((y+215.861121388216-verschuivingy)*omf));
line.pathPoints[2].rightDirection = Array(((x+39.8638983011982+verschuivingx)*omf),((y+215.861121388216-verschuivingy)*omf));
line.pathPoints[3].leftDirection = Array(((x+167.922261870534+verschuivingx)*omf),((y+215.861121388216-verschuivingy)*omf));
line.pathPoints[3].rightDirection = Array(((x+167.922261870534+verschuivingx)*omf),((y+215.861121388216-verschuivingy)*omf));
line.closed = true;
line.stroked= false;
line.filled= true;
var newGradient = app.activeDocument.gradients.add();
newGradient.name = "NewGradient0";
newGradient.type=GradientType.LINEAR;
var itemColor1 = new CMYKColor();
itemColor1.cyan = 0;
itemColor1.magenta = 100;
itemColor1.yellow = 100;
itemColor1.black = 0;
newGradient.gradientStops[1].color = itemColor1;
newGradient.gradientStops[1].rampPoint=100;
newGradient.gradientStops[1].midPoint=50;
var itemColor0 = new CMYKColor();
itemColor0.cyan = 0;
itemColor0.magenta = 0;
itemColor0.yellow = 100;
itemColor0.black = 0;
newGradient.gradientStops[0].color = itemColor0;
newGradient.gradientStops[0].rampPoint=0;
newGradient.gradientStops[0].midPoint=50;
var colorOfGradient = new GradientColor();
colorOfGradient.gradient = newGradient;
line.fillColor = colorOfGradient;
line.fillOverprint = false;
line.rotate(130,false,false,true,false);
var itemColor = new Array();
itemColor[2] = new CMYKColor();
itemColor[2].cyan = 0;
itemColor[2].magenta = 75;
itemColor[2].yellow = 100;
itemColor[2].black = 0;
itemColor[1] = new CMYKColor();
itemColor[1].cyan = 30;
itemColor[1].magenta = 100;
itemColor[1].yellow = 0;
itemColor[1].black = 0;
itemColor[0] = new CMYKColor();
itemColor[0].cyan = 85;
itemColor[0].magenta = 10;
itemColor[0].yellow = 100;
itemColor[0].black = 0;
for (i=0;i<itemColor.length;i++){
grdntstop= doc.gradients.getByName("NewGradient0").gradientStops.add();
grdntstop.color = itemColor;
grdntstop.rampPoint = (i+1)/(itemColor.length+1)*100;
grdntstop.midPoint=50;
}
var illustratorversion = app.version;
var illustratorversionarray = illustratorversion.split(".");
if(illustratorversionarray[0]>13){
app.activeDocument.artboards[0].artboardRect = app.activeDocument.visibleBounds;
}
zet_nulpunt();
zoomcenterpage()
function zoomcenterpage(){
var myView=app.activeDocument.views[0];
myView.centerPoint = [(app.activeDocument.width/2),(app.activeDocument.height/2)];
myView.zoom = 1
myView.screenMode.FULLSCREEN;
}
function zet_nulpunt(){
// zet nulpunt linksonder
app.activeDocument.pageOrigin = Array(0,0);
app.activeDocument.rulerOrigin = Array(0,0);
}
result images...
Copy link to clipboard
Copied
My second question? has anyone experience whith these functions? (Gradient)
hiliteAngle
hiliteLength
length
matrix
origin
How can i call them in a script.
Cheers Daniel
Copy link to clipboard
Copied
I found an error in your script.
We have to put ramp point from smaller points. but your script set rampPoint 75%.
var grdntstop = doc.gradients.getByName("NewGradient0").gradientStops.add();
var itemColor3 = new CMYKColor();
itemColor3.cyan = 0;
itemColor3.magenta = 75;
itemColor3.yellow = 100;
itemColor3.black = 0;
grdntstop.color = itemColor3;
grdntstop.rampPoint=22.6993865966797;
grdntstop.midPoint=50;
var grdntstop = doc.gradients.getByName("NewGradient0").gradientStops.add();
var itemColor2 = new CMYKColor();
itemColor2.cyan = 30;
itemColor2.magenta = 100;
itemColor2.yellow = 0;
itemColor2.black = 0;
grdntstop.color = itemColor2;
grdntstop.rampPoint=50;
grdntstop.midPoint=50;
var grdntstop = doc.gradients.getByName("NewGradient0").gradientStops.add();
var itemColor1 = new CMYKColor();
itemColor1.cyan = 85;
itemColor1.magenta = 10;
itemColor1.yellow = 100;
itemColor1.black = 0;
grdntstop.color = itemColor1;
grdntstop.rampPoint=74.2331237792969;
grdntstop.midPoint=50;