QQ登录

只需一步,快速开始

查看: 18674|回复: 13
收起左侧

学习AI JS脚本的学习笔记

[复制链接]
累计签到:188 天
连续签到:1 天
发表于 2016-6-2 13:14:33 | 显示全部楼层 |阅读模式
你的第一个脚本:

[mw_shl_code=javascript,true]
var myDocument = app.documents.add(); //新建一个文档
var myTextFrame = myDocument.textFrames.add();  //新建一个文本框
myTextFrame.position = [200,200];  //定义文本框的位置
myTextFrame.contents = "Hello World!"  //文本框输入的内容
你的第二个脚本
var docRef = app.activeDocument;  //获取当前文档
var docWidth = docRef.width   //定义当前文件宽度
var frameRef = docRef.textFrames[0] //获取文档文本
frameRef.width = docWidth  //让文本宽度改为文档宽度
你的第三个脚本
myObject.rotate(30, undefined, undefined, true);

引用对象
var frontMostDocument = activeDocument;
var frontMostDocument = app.activeDocument;
访问对象
var myStyles = app.activeDocument.graphicStyles;
var firstStyle = app.activeDocument.graphicStyles[0];

var styleName = myStyles[0].name
var styleName = firstStyle.name
var styleName = app.activeDocument.graphicStyles[0].name

alert ( myStyles.length );

var lastStyle = myStyles[ myStyles.length - 1 ];

创建对象
var myDoc = app.documents.add()
var myLayer = myDoc.layers.add()

var myColor = new CMYKColor()

使用选择
var seIectedObjects = app.activeDocument.seIection;

var topObject = app.activeDocument.seIection[0];
alert(topObject.typename)

使用文本框
var rectRef = docRef.pathItems.rectangle(700, 50, 100, 100);
var areaTextRef = docRef.textFrames.areaText(rectRef);

var myDoc = documents.add();
var myPathItem1 = myDoc.pathItems.rectangle(244, 64, 82, 76);
var myTextFrame1 = myDoc.textFrames.areaText(myPathItem1);
var myPathItem2 = myDoc.pathItems.rectangle(144, 144, 42, 116);
var myTextFrame2 = myDoc.textFrames.areaText(myPathItem2);
// use the nextFrame property to thread the text frames
myTextFrame1.nextFrame = myTextFrame2;
var sText = "This is two text frames linked together as one story, with text
flowing from the first to the last. This is two text frames linked together as one
story, with text flowing from the first to the last. This is two text frames linked
together as one story. ";
myTextFrame1.contents = sText;
redraw();

路径
指定一系列的XY座标
var myDoc = app.activeDocument;
var myLine = myDoc.pathItems.add();
//set stroked to true so we can see the path
myLine.stroked = true;
myLine.setEntirePath([[220, 475], [375, 300], [200, 300]]);

var myDoc = app.activeDocument;
var myLine = myDoc.pathItems.add();
//set stroked to true so we can see the path
myLine.stroked = true;
var newPoint = myLine.pathPoints.add();
newPoint.anchor = [220, 475];
//giving the direction points the same value as the
//anchor point creates a strAIght line segment
newPoint.leftDirection = newPoint.anchor;
newPoint.rightDirection = newPoint.anchor;
newPoint.pointType = PointType.CORNER;
var newPoint1 = myLine.pathPoints.add();
newPoint1.anchor = [375, 300];
newPoint1.leftDirection = newPoint1.anchor;
newPoint1.rightDirection = newPoint1.anchor;
newPoint1.pointType = PointType.CORNER;
var newPoint2 = myLine.pathPoints.add();
newPoint2.anchor = [220, 300];
//giving the direction points different values
//than the anchor point creates a curve
newPoint2.leftDirection =[180, 260];
newPoint2.rightDirection = [240, 320];
newPoint2.pointType = PointType.CORNER;

var myDoc = app.activeDocument;
var myLine = myDoc.pathItems.add();
myLine.stroked = true;
myLine.setEntirePath( [[220, 475], [375, 300]]);

var newPoint = myDoc.myLine.pathPoints.add();
newPoint.anchor = [220, 300];
newPoint.leftDirection = newPoint.anchor;
newPoint.rightDirection = newPoint.anchor;
newPoint.pointType = PointType.CORNER;

创建一个矩形
var myDocument = app.documents.add()
var artLayer = myDocument.layers.add()
var rect = artLayer.pathItems.rectangle( 144, 144, 72, 216 );

创建一个多边形
var myDocument = app.documents.add()
var artLayer = myDocument.layers.add()
var poly = artLayer.pathItems.polygon( 144, 288, 72.0, 7 );

使用透视网格

从一个文档复制选定项目到新的文档
var newItem;
var docseIected = app.activeDocument.seIection;
if ( docseIected.length > 0 ) {
// Create a new document and move the seIected items to it.
var newDoc = app.documents.add();
if ( docseIected.length > 0 ) {
for ( i = 0; i < docseIected.length; i++ ) {
docseIected.seIected = false;
newItem = docseIected.duplicate( newDoc,
ElementPlacement.PLACEATEND );
}
}
else {
docseIected.seIected = false;
newItem = docseIected.parent.duplicate( newDoc,
ElementPlacement.PLACEATEND );
}
}
else {
alert( "Please seIect one 0r more art objects" );
}

复制描边群组
if ( app.documents.length > 0 ) {
docseIection = app.activeDocument.seIection;
if ( docseIection.length > 0 ) {
newGroup = app.activeDocument.groupItems.add();
for ( i = 0; i < docseIection.length; i++ ) {
newItem = docseIection.duplicate();
newItem.moveToBeginning( newGroup );
}
brush4 = app.activeDocument.brushes[1];
brush4.applyTo( newGroup );
}
}

填充颜色
if ( app.documents.length > 0 && app.activeDocument.pathItems.length > 0) {
frontPath = app.activeDocument.pathItems[0];
// Set color values for the CMYK object
newCMYKColor = new CMYKColor();
newCMYKColor.black = 0;
newCMYKColor.cyan = 30.4;
newCMYKColor.magenta = 32;
newCMYKColor.yellow = 0;
// Use the color object in the path item
frontPath.filled = true;
frontPath.fillColor = newCMYKColor;
}

关闭文档
if ( app.documents.length > 0 ) {
aiDocument = app.activeDocument;
aiDocument.close( SaveOptions.DONOTSAVECHANGES );
aiDocument = null;
}

默认填充和描边
if ( app.documents.length == 0 ) {
doc = app.documents.add();
}
else {
doc = app.activeDocument;
}
doc.defaultFilled = true;
doc.defaultStroked = true;

创建一个新文件
app.documents.add( DocumentColorSpace.RGB );

导出EPS 这是一个导出EPS的函数,如何让选中的文档导出EPS呢?
function exportFileAsEPS (destFile) {
var newFile = new File(destFile);
var saveDoc;
if ( app.documents.length == 0 )
saveDoc = app.documents.add();
else
saveDoc = app.activeDocument;
var saveOpts = new EPSSaveOptions();
saveOpts.cmykPostScript = true;
saveOpts.embedAllFonts = true;
saveDoc.saveAs( newFile, saveOpts );
}

导出JPG 这是一个导出JPG的函数,如何让选中的文档导出JPG呢?
function exportFileToJPEG (dest) {
if ( app.documents.length > 0 ) {
var exportOptions = new ExportOptionsJPEG();
var type = ExportType.JPEG;
var fileSpec = new File(dest);
exportOptions.antiAliasing = false;
exportOptions.qualitySetting = 70;
app.activeDocument.exportFile( fileSpec, type, exportOptions );
}
}

导出PSD 这是一个导出PSD的函数,如何让选中的文档导出PSD呢?
function exportFileToPSD (dest) {
if ( app.documents.length > 0 ) {
var exportOptions = new ExportOptionsPhotoshop();
var type = ExportType.PHOTOSHOP;
var fileSpec = new File(dest);
exportOptions.writeLayers = true;
exportOptions.resolution = 150;
app.activeDocument.exportFile( fileSpec, type, exportOptions );
}
}

导出TIF 这是一个导出TIF的函数,如何让选中的文档导出TIF呢?
function exportFileToPSD (dest) {
if ( app.documents.length > 0 ) {
var exportOptions = new ExportOptionsTIFF();
var type = ExportType.TIFF;
var fileSpec = new File(dest);
exportOptions.resolution = 150;
exportOptions.byteOrder = TIFFByteOrder.IBMPC;
exportOptions.IZWCompression = false;
app.activeDocument.exportFile( fileSpec, type, exportOptions );

将底层设置为最高层
if (documents.length > 0) {
countOfLayers = activeDocument.layers.length;
if (countOfLayers > 1) {
bottomLayer = activeDocument.layers[countOfLayers-1];
bottomLayer.zOrder(ZOrderMethod.BRINGTOFRONT);
}
else {
alert("The active document only has only 1 layer")
}
}

全屏
if ( app.documents.length > 0 ) {
app.documents[0].views[0].screenMode = ScreenMode.FULLSCREEN;
}

if ( app.documents.length > 0 ) {//至少开启一个档案
docseIection = app.activeDocument.seIection;//选取对象的变数
if ( docseIection.length > 0 ) {//如果选取变数大于0
newGroup = app.activeDocument.groupItems.add();//则增加新群组
for ( i = 0; i < docseIection.length; i++ ) {//for循环将
选取对象一一复制至群组中
newItem = docseIection.duplicate();//复制语法
newItem.moveToBeginning( newGroup );//移动语法
}
brush4 = app.activeDocument.brushes[1];//档案上笔刷面板排序第2的笔刷(脚本的排序要从0算起,也就是[0]就是第一个)
brush4.applyTo( newGroup );//将上述指定的剐刷套用到群组里面
}
}

画两条直线
var myDoc = app.activeDocument;
var myLine1 = myDoc.pathItems.add();
var myLine2 = myDoc.pathItems.add();
myLine1.stroked = true;
myLine2.stroked = true;
myLine1.setEntirePath([[220, 300], [375, 300]]);
myLine2.setEntirePath([[220, 350], [220, 400]]);

画一条直线,并加上注册色
doc = app.activeDocument;
theseIect = doc.seIection;
x=theseIect[0].left;
y=theseIect[0].top;
w=theseIect[0].width;
h=theseIect[0].height;
s=50;//标尺距离物体边沿宽度
tsize=40; //标尺字体大小
redColor = new CMYKColor();//标尺用红色
redColor.black = 00;
redColor.cyan = 0;
redColor.magenta =100;
redColor.yellow = 100;
var defaultStrokeColor=doc.swatches[1].color;
var g1 = doc.groupItems.add();//将标尺群组
var line1=g1.pathItems.add(); //画高度标尺
line1.setEntirePath( new Array(
new Array(x-s, y),
new Array(x-s, y-h),
)
) ;
line1.strokeColor= defaultStrokeColor;

画两条线并加上注册色
var myDoc = app.activeDocument;
var myLine1 = myDoc.pathItems.add();
var myLine2 = myDoc.pathItems.add();
myLine1.stroked = true;
myLine2.stroked = true;
myLine1.setEntirePath([[220, 300], [375, 300]]);
myLine2.setEntirePath([[220, 350], [220, 400]]);
var defaultStrokeColor=myDoc.swatches[1].color;
myLine1.strokeColor= defaultStrokeColor;
myLine2.strokeColor= defaultStrokeColor;

画两条线并加上注册色,并设长度为2mm,并将它们群组 ,并把描边粗细为0.1mm
var myDoc = app.activeDocument;
var g1 = myDoc.groupItems.add();//将两条直线群组
var myLine1=g1.pathItems.add(); //建立群组中的一条直线
var myLine2=g1.pathItems.add(); //建立群组中的另一条直线
var pointTomm=2.834645 ; //设定单位为mm
myLine1.stroked = true;
myLine2.stroked = true;
myLine1.setEntirePath([[0*pointTomm, 0*pointTomm], [0*pointTomm, -2*pointTomm]]);
myLine2.setEntirePath([[0*pointTomm,0*pointTomm], [2*pointTomm, 0*pointTomm]]);
var defaultStrokeColor=myDoc.swatches[1].color;
myLine1.strokeColor= defaultStrokeColor;
myLine2.strokeColor= defaultStrokeColor;
var defaultStrokeWidth=0.1*pointTomm
myLine1.strokeWidth= defaultStrokeWidth;
myLine2.strokeWidth= defaultStrokeWidth;

导出JPG

exporFiletToJPEG ('E:\我的.jpg');


function exportFileToJPEG (dest) {
if ( app.documents.length > 0 ) {
var exportOptions = new ExportOptionsJPEG();
var type = ExportType.JPEG;
var fileSpec = new File(dest);
exportOptions.antiAliasing = true;//抗锯齿
exportOptions.artBoardClipping = true;//画板
exportOptions.qualitySetting = 100;//品质
app.activeDocument.exportFile( fileSpec, type, exportOptions );
}
}[/mw_shl_code]

评分

参与人数 1印币 +30 收起 理由
给心加点温 + 30 很给力!

查看全部评分

华印网相关搜索

累计签到:205 天
连续签到:1 天
发表于 2016-6-2 14:21:08 | 显示全部楼层
楼主笔记还未整理好上传?还是已经上传忘记插入附件了?
累计签到:110 天
连续签到:1 天
发表于 2016-6-3 19:48:11 | 显示全部楼层
好教材,赞一个。
累计签到:79 天
连续签到:1 天
发表于 2016-6-9 12:21:49 | 显示全部楼层
楼主还是要慢慢的来教,例如第一讲是直线。那就说直线的属性,画法。这样就系统全面了~
累计签到:992 天
连续签到:2 天
发表于 2016-6-13 17:27:11 | 显示全部楼层
很好的教程,没有中文说明不然看不明白
累计签到:586 天
连续签到:1 天
发表于 2016-6-18 20:30:15 | 显示全部楼层
很受用!!!
回复 送花

使用道具 举报

累计签到:209 天
连续签到:1 天
发表于 2016-6-25 19:43:50 | 显示全部楼层
本帖最后由 sunwen 于 2016-6-25 19:51 编辑

友情支持...
{:1_134:}对没有基础而又想学的人从哪开始搞起?
累计签到:351 天
连续签到:0 天
发表于 2016-6-30 12:40:56 | 显示全部楼层
{:1_124:}有点点明白了   {:1_162:}
累计签到:7 天
连续签到:0 天
发表于 2016-7-7 15:34:00 | 显示全部楼层
嗯,挺好的,能看懂一点,不错
累计签到:891 天
连续签到:3 天
发表于 2017-7-27 08:22:16 | 显示全部楼层
发一个这方面的教程。
回复 支持 反对 送花

使用道具 举报

您需要登录后才可以回帖 登录 | 注册帐号

本版积分规则

关闭

注意注意注意:必看上一条 /1 下一条

华印网 - 华印社区
Share More 周一至周日:09:00 - 21:00
华印网旗下的设计印刷制作类专业技术站点
请勿发布违反国家法律法规的内容,会员观点不代表本站立场
企鹅群号:119572101

华印网汇集印前印后技术、PDF拼版、防伪包装、数码印刷、合版印刷、图文设计、平面设计、数码印刷及CTP等最新印刷技术,提供软件汉化、插件汉化、cdr插件、ai插件、ps插件、pdf插件、印刷流程、ctp输出、印刷软件、印能捷、esko、CorelDRAW、InDesign、Illustrator、CTP、CDR以及PDF软件下载的综合性印刷论坛社区!

Powered by Discuz! X3.4 © 2001-2021,Tencent Cloud.

站点地图|小黑屋|手机版|Archiver|华印 ( 粤ICP备19020152号-1 )

GMT+8, 2024-12-20 20:35 , Processed in 0.023318 second(s), 34 queries , Gzip On, Yac On.

快速回复 返回顶部 返回列表