萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 軟體知識 >  >> 影像處理 >> Adobe Illustrator 教學

AI 腳本自動分割文本框:段落獨立化神器

處理大量文本排版時,常需將單一文本框拆分為多個獨立段落框。手動拆分極其繁瑣,一段 JS 腳本即可一鍵完成。

腳本功能

  • 支援點文字與區域文字(段落文字)。
  • 自動識別換行符(`\n`),將每個段落拆分為獨立文本框。
  • 保留原文本格式(字體、大小、顏色、段落樣式等)。
  • 相容 CS3/CS4/CS5 等版本(測試通過)。

安裝與使用

  1. 將下方程式碼複製到記事本,存為 分割文本框.jsx(或 `.js`)。
  2. 放入 Illustrator 腳本資料夾:
    Windows: `C:\Program Files\Adobe\Adobe Illustrator [版本]\Presets\Scripts\`
    Mac: `/Applications/Adobe Illustrator [版本]/Presets/Scripts/`
  3. 重啟 AI,或直接 檔案 > 腳本 > 其他腳本 選取執行。
  4. 使用前先選取目標文本框,執行腳本即自動拆分。

腳本原始碼

/////////////////////////////////////////////////////////////////
//divide textframe v.2 -- cs,cs2
//>=--------------------------------------
// divides a multiline text field into separate textframe objects.
// basically, each line in the selected text object
// becomes it's own textframe. vertical spacing of each new line is based on leading.
// 
// this is the opposite of my "join textframes" scripts which
// takes multiple lines and stitchs them back together into the same object.
//>=--------------------------------------
// js code (c) copyright: john wundes ( john@wundes.com ) www.wundes.com
//copyright full text here: https://www.wundes.com/js4ai/copyright.txt
/////////////////////////////////////////////////////////////////

if(app.documents.length > 0){
    var sel = app.activeDocument.selection;
    if(sel.length == 1 && sel[0].typename == "TextFrame"){
        var tf = sel[0];
        if(tf.contents.indexOf("\n") != -1){
            var lines = tf.contents.split("\n");
            var top = tf.top;
            var left = tf.left;
            var leading = tf.paragraphs[0].leading;
            if(typeof leading == "string") leading = parseFloat(leading);
            tf.remove();
            for(var i=0; i

腳本執行前後對比

原作者版權聲明

腳本作者 John Wundes (john@wundes.com),請尊重版權保留註釋。更多實用腳本見 wundes.com/js4ai。

善用腳本自動化重複勞動,將精力留給真正的設計決策。

copyright © 萬盛學電腦網 all rights reserved