Skip to content

Commit

Permalink
Added ExtractFromGroup.jsx
Browse files Browse the repository at this point in the history
Extract selected items from parent groups
  • Loading branch information
creold committed May 5, 2024
1 parent 8bd55e8 commit e968fda
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ Click the category name to learn more about the scripts in the selected category
### [Group | Mask](md/Group.md)

* [CenterClipsToArtboards](https://github.com/creold/illustrator-scripts/blob/master/md/Group.md#centerclipstoartboards)
* [ExtractFromGroup](https://github.com/creold/illustrator-scripts/blob/master/md/Group.md#extractfromgroup) `new, 05.05.2024`
* [ExtUngroup](https://github.com/creold/illustrator-scripts/blob/master/md/Group.md#extungroup)
* [MoveToGroup](https://github.com/creold/illustrator-scripts/blob/master/md/Group.md#movetogroup) `upd, 09.02.2024`
* [TrimMasks](https://github.com/creold/illustrator-scripts/blob/master/md/Group.md#trimmasks)
Expand Down
1 change: 1 addition & 0 deletions README.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
Скрипты для создания и управления группами, обтравочными масками

* [CenterClipsToArtboards](https://github.com/creold/illustrator-scripts/blob/master/md/Group.ru.md#centerclipstoartboards)
* [ExtractFromGroup](https://github.com/creold/illustrator-scripts/blob/master/md/Group.ru.md#extractfromgroup) `new, 05.05.2024`
* [ExtUngroup](https://github.com/creold/illustrator-scripts/blob/master/md/Group.ru.md#extungroup)
* [MoveToGroup](https://github.com/creold/illustrator-scripts/blob/master/md/Group.ru.md#movetogroup) `upd, 09.02.2024`
* [TrimMasks](https://github.com/creold/illustrator-scripts/blob/master/md/Group.ru.md#trimmasks)
Expand Down
92 changes: 92 additions & 0 deletions jsx/ExtractFromGroup.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
ExtractFromGroup.jsx for Adobe Illustrator
Description: Extract selected items from parent groups
If Alt key is pressed, move item before the first parent group
If Alt key is not pressed, move item before the topmost level parent group
Date: May, 2024
Author: Sergey Osokin, email: hi@sergosokin.ru
Installation: https://github.com/creold/illustrator-scripts#how-to-run-scripts
Release notes:
0.1 Initial version
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
NOTICE:
Tested with Adobe Illustrator CC 2019-2024 (Mac/Win)
This script is provided "as is" without warranty of any kind
Free to use, not for sale
Released under the MIT license
http://opensource.org/licenses/mit-license.php
Check my other scripts: https://github.com/creold
*/

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

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

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

if (!selection.length || selection.typename == 'TextRange') {
alert('No objects selected\nPlease select object(s) and try again', 'Script error');
return;
}

var isAltPressed = ScriptUI.environment.keyboardState.altKey;

for (var i = 0, len = app.selection.length; i < len; i++) {
var item = app.selection[i];
if (item.parent.typename === 'CompoundPathItem') {
item = item.parent;
}
var parent = getParentGroup(item, isAltPressed);

if (parent.typename === 'GroupItem') {
item.move(parent, ElementPlacement.PLACEBEFORE);
}
}
}

/**
* Find the parent GroupItem of the specified item based on the Alt key status
* @param {Object} item - The item for which to find the parent GroupItem
* @param {boolean} isAltKey - A boolean flag indicating whether the Alt key is pressed or not
* @returns {Object} - The parent GroupItem if found
*/
function getParentGroup(item, isAltKey) {
if (isAltKey) {
if (item.parent.typename === 'GroupItem') {
return item.parent;
} else {
return getParentGroup(item.parent, isAltKey);
}
} else {
var topParent = item;
while (topParent.parent.typename === 'GroupItem') {
topParent = topParent.parent;
}
return topParent;
}
}

// Run script
try {
main();
} catch (err) {}
8 changes: 8 additions & 0 deletions md/Group.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

## Scripts
* [CenterClipsToArtboards](https://github.com/creold/illustrator-scripts/blob/master/md/Group.md#centerclipstoartboards)
* [ExtractFromGroup](https://github.com/creold/illustrator-scripts/blob/master/md/Group.md#extractfromgroup) `new, 05.05.2024`
* [ExtUngroup](https://github.com/creold/illustrator-scripts/blob/master/md/Group.md#extungroup)
* [MoveToGroup](https://github.com/creold/illustrator-scripts/blob/master/md/Group.md#movetogroup) `upd, 09.02.2024`
* [TrimMasks](https://github.com/creold/illustrator-scripts/blob/master/md/Group.md#trimmasks)
Expand All @@ -24,6 +25,13 @@ Aligns selected clip groups and their contents to the center of the parent artbo

![CenterClipsToArtboards](https://i.ibb.co/ykHy3rM/Center-Clips-To-Artboards.gif)

## ExtractFromGroup
[![Direct](https://img.shields.io/badge/Direct%20Link-ExtractFromGroup.jsx-FF6900.svg)](https://rebrand.ly/extrgrp) [![Download](https://img.shields.io/badge/Download%20All-Zip%20archive-0088CC.svg)](https://bit.ly/2M0j95N)

Extracts the selected items from parent groups. By default, each item is moved before the top parent group. If <kbd>Alt / Option (⌥)</kbd> key is pressed, move item before the first parent group.

![ExtractFromGroup](https://i.ibb.co/pK5yzqS/Extract-From-Group.gif)

## ExtUngroup
[![Direct](https://img.shields.io/badge/Direct%20Link-ExtUngroup.jsx-FF6900.svg)](https://rebrand.ly/extungrp) [![Download](https://img.shields.io/badge/Download%20All-Zip%20archive-0088CC.svg)](https://bit.ly/2M0j95N)

Expand Down
8 changes: 8 additions & 0 deletions md/Group.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

## Scripts
* [CenterClipsToArtboards](https://github.com/creold/illustrator-scripts/blob/master/md/Group.ru.md#centerclipstoartboards)
* [ExtractFromGroup](https://github.com/creold/illustrator-scripts/blob/master/md/Group.ru.md#extractfromgroup) `new, 05.05.2024`
* [ExtUngroup](https://github.com/creold/illustrator-scripts/blob/master/md/Group.ru.md#extungroup)
* [MoveToGroup](https://github.com/creold/illustrator-scripts/blob/master/md/Group.ru.md#movetogroup) `upd, 09.02.2024`
* [TrimMasks](https://github.com/creold/illustrator-scripts/blob/master/md/Group.ru.md#trimmasks)
Expand All @@ -24,6 +25,13 @@

![CenterClipsToArtboards](https://i.ibb.co/ykHy3rM/Center-Clips-To-Artboards.gif)

## ExtractFromGroup
[![Direct](https://img.shields.io/badge/Прямая%20ссылка-ExtractFromGroup.jsx-FF6900.svg)](https://rebrand.ly/extrgrp) [![Download](https://img.shields.io/badge/Скачать%20все-Zip--архив-0088CC.svg)](https://bit.ly/2M0j95N)

Извлекает выбранные элементы из групп. По умолчанию каждый элемент извлечётся перед самой верхней группой. Если зажата клавиша <kbd>Alt / Option (⌥)</kbd>, то элемент переместится перед первой родительской группой.

![ExtractFromGroup](https://i.ibb.co/pK5yzqS/Extract-From-Group.gif)

## ExtUngroup
[![Direct](https://img.shields.io/badge/Прямая%20ссылка-ExtUngroup.jsx-FF6900.svg)](https://rebrand.ly/extungrp) [![Download](https://img.shields.io/badge/Скачать%20все-Zip--архив-0088CC.svg)](https://bit.ly/2M0j95N)

Expand Down

0 comments on commit e968fda

Please sign in to comment.