코드로 참조 Illustrator 파일에서 다른 파일로 심볼 라이브러리를로드하려고합니다. UI에서 '기타 라이브러리'를 클릭 할 때와 동일한로드를하고 싶습니다. 그러면 모든 심볼을 가져 오기 위해 Ai 파일을 선택해야합니다.
누구든지 그것을하는 방법을 알고 있습니까? 쉬운 방법이 있습니까, 아니면 기호를 하나씩 복사해야합니까?
다른 문서를로드 한 다음 각 기호를 첫 번째 문서에 복사하려고했습니다.
var loadSymbolLibrary = function(fromAiFile) {
var thisDocument = activeDocument;
app.open(fromAiFile);
var fromAiDocument = activeDocument;
var symbols = fromAiDocument.symbols;
for(var i = 0; i < symbols.length; i++) {
var symbol = symbols[i];
thisDocument.symbols.add(symbol);
}
fromAiDocument.close();
activeDocument = thisDocument;
}
그러나 첫 번째 문서에 기호를 추가 할 때 오류가 발생합니다. Adobe 문서에 따르면 함수 로 심볼을 만들려면 PageItem
및 a SymbolRegistrationPoint
가 필요 add()
합니다.
[편집하다]
I also tried to load the document containing symbols in this way:
var openOptions = new OpenOptions();
openOptions.openAs = LibraryType.SYMBOLS;
var symbolDocument = app.open(symbolAiFile, null, openOptions);
This opens a symbol window in Illustrator, but I don't know how to deal with it by code as calling symbolDocument.symbols
produce a 'The document is no longer open' error.
First off, it will be useful to know for clarity that a SymbolItem is a placed instance of a Symbol and a Document has both of those.
Illustrator will not allow a call to Document.symbolItems.add()
if the symbol being passed is not in that document's symbols list. Personally, I consider that a bug. Here is a wrapper class that opens the symbol library as a new document (note the exclusion of relevant openAs property), places the symbol into that document, then copies the symbol item to the other document.
#target illustrator-18
//class
function SymbolLibrary(){
this.symbolsDoc = null;
this.len = 0;
this.begin = function(symbolFileName){
var file1 = File(symbolFileName);
//open the symbol library
var optRef = new OpenOptions();
//optRef.openAs = LibraryType.SYMBOLS; //broken. just open as regular doc
this.symbolsDoc = app.open( file1 , null , optRef);
this.len = this.symbolsDoc.symbols.length;
return this.symbolsDoc;
}
this.list = function(){
for(var i=0;i<symbolsDoc.symbols.length;i++){
$.writeln( symbolsDoc.symbols[i] );
}
return symbolsDoc.symbols;
}
this.place = function(targetDoc,index){
var symbolItem = this.symbolsDoc.symbolItems.add(this.symbolsDoc.symbols[index]);
finalItem = symbolItem.duplicate( targetDoc,ElementPlacement.PLACEATEND );
symbolItem.remove();
return finalItem;
}
this.end = function(){
this.symbolsDoc.close(SaveOptions.DONOTSAVECHANGES);
}
}
var filename = "/Applications/Adobe\ Illustrator\ CC\ 2014/"+
"Presets.localized/en_US/Symbols/Nature.ai";
//create new document
var mydoc = app.documents.addDocument('',new DocumentPreset());
//instantiate the symbol library handler class
var lib1 = new SymbolLibrary();
lib1.begin(filename);
for(var i=0;i<lib1.len;i++){
lib1.place(mydoc,i).position = [((i%10)*100),i*10];
}
lib1.end();
$.writeln('#########');
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다