我目前正在编写一个脚本,该脚本在插图画家中获取具有多个文本字段的图稿,并使用填充了FileMaker XML文件中的数据的文本字段复制artitem。注意:即使这是一个Illustrator扩展脚本,我也很确定它与javascript更相关。
这是XML文件中第一个给你一个想法的记录:
<FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
<ERRORCODE>0</ERRORCODE>
<PRODUCT BUILD="01-07-2009" NAME="FileMaker" VERSION="ProAdvanced 10.0v1"/>
<DATABASE DATEFORMAT="" LAYOUT="" NAME="" RECORDS="123" TIMEFORMAT=""/>
<METADATA></METADATA>
<RESULTSET FOUND="123">
<ROW MODID="11" RECORDID="11116">
<COL>
<DATA>BB-1</DATA>
</COL>
<COL>
<DATA>ELEVATOR</DATA>
</COL>
<COL>
<DATA>MACHINE</DATA>
</COL>
<COL>
<DATA>ROOM</DATA>
</COL>
<COL>
<DATA>107</DATA>
</COL>
<COL>
<DATA></DATA>
</COL>
<COL>
<DATA></DATA>
</COL>
<COL>
<DATA></DATA>
</COL>
</ROW>
以下是给我提出问题的块:
//counts the amount of records in the XML = 123
var recordsLength = contents.elements().child(4).elements().length();
//counts the amount of data elements in each record = 8
var dataLength = contents.elements().child(4).elements().child(0).elements().length();
function drawArt() {
//this loop iterates through each record; matches the groupitem name in illustrator to the first data element in the record; and duplicates the groupitem and positions it in the document.
for (var i = 0; i < recordsLength; i++) {
signType = contents.elements().child(4).elements().child(i).elements().child(0).child(0).text();
gpTarget = docRef.groupItems.getByName(signType);
newArt = gpTarget.duplicate();
newArt.top = y;
newArt.left = x;
x+=(gpTarget.width + 20);
redraw();
//counts the amount of text fields in each newArt (i added - 1 to the end because there is always a text field at the end that should not be filled in)
var txtFrmLength = newArt.textFrames.length - 1;
//this loop iterates through each data element and gets the length of it
for (var t = 1; t < dataLength; t++) {
nodeLength = contents.elements().child(4).elements().child(i).elements().child(t).child(0).text().length();
//this if statement looks to see if a data element contains data or is empty; if its not empty move to next loop; if it is, go back to first loop
if(nodeLength > 0) {
//this loop iterates through the text fields and fills in the data from the XML
for (var u = 0; u < txtFrmLength; u++)
newSign.textFrames[u].contents = contents.elements().child(4).elements().child(i).elements().child(t).child(0).text();
} else {
break;
}
}
}
}
drawArt();
}
main();
基本上,脚本应该复制和定位一个组项,将XML中的数据放入其文本字段,然后转到下一个artitem。
我将测试设置为i&lt; 2在第一个循环中,看看我是否可以缩小问题的位置。我得到的结果是每个artitem都被复制了,它的所有文本字段都填充了第5个数据节点。
任何人都可以帮我弄清楚我做错了什么吗?感谢。