Skip to content

Instantly share code, notes, and snippets.

@creold
Created August 27, 2024 10:09

Revisions

  1. creold created this gist Aug 27, 2024.
    63 changes: 63 additions & 0 deletions PartialPathDeselection.jsx
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,63 @@
    /*
    Recursively deselects partial paths within the selected group to safely use the Eyedropper tool
    with Appearance mode enabled to apply styles only to the paths and not to the group
    Author: Sergey Osokin, email: [email protected]
    Check my other scripts: https://github.com/creold
    Donate (optional):
    If you find this script helpful, you can buy me a coffee
    - via Buymeacoffee: https://www.buymeacoffee.com/aiscripts
    - via Donatty https://donatty.com/sergosokin
    - via DonatePay https://new.donatepay.ru/en/@osokin
    - via YooMoney https://yoomoney.ru/to/410011149615582
    */

    //@target illustrator
    preferences.setBooleanPreference('ShowExternalJSXWarning', false); // Fix drag and drop a .jsx file

    function main () {
    if (!/illustrator/i.test(app.name)) {
    alert('Wrong application\nRun script from Adobe Illustrator', 'Script error');
    return false;
    }

    if (!app.documents.length) {
    alert('No documents\nOpen a document and try again', 'Script error');
    return;
    }

    if (!app.selection.length || selection.typename === 'TextRange') {
    alert('Few objects are selected\nPlease select at least one group and try again', 'Script error');
    return;
    }

    var paths = getPaths(app.selection);
    if (!paths.length) return;

    for (var i = 0, len = paths.length; i < len; i++) {
    if (!paths[i].hasOwnProperty('pathPoints')) continue;
    // Deselect one path point
    paths[i].pathPoints[0].selected = PathPointSelection.NOSELECTION;
    }
    }

    // Get paths from selection
    function getPaths(coll) {
    var paths = [];
    for (var i = 0; i < coll.length; i++) {
    var item = coll[i];
    if (item.pageItems && item.pageItems.length) {
    paths = [].concat(paths, getPaths(item.pageItems));
    } else if (/compound/i.test(item.typename) && item.pathItems.length) {
    paths = [].concat(paths, getPaths(item.pathItems));
    } else if (/pathitem/i.test(item.typename)) {
    paths.push(item);
    }
    }
    return paths;
    }

    // Run script
    try {
    main();
    } catch (err) {}