Copy link to clipboard
Copied
I am writing a script that checks the designer's work for unexpanded graphics. Since further work with Enveloped objects, Applied appearance (or Applied Live Effects) is dangerous for transferring and printing.
I can't find a method or function that would help me check if the current object in the sorting algorithm has unexpanded graphics or effects.
At the moment, the only thing I can think of is that such objects cannot be expanded via ExecuteMenuCommand( 'Expand3') and should be expanded via ('expandstyle'). The script is quite functional for objects and groups containing up to 100 PathItems. After that, a super lag occurs, which can hang Illustrator in "not responding" mode for 5-10 minutes. And I understand that this happens because of the forced constant attempt to do 'expandstyle'.
Actually, I have a question: is there any other way to check if an object has an applied style that can be expanded?
function createProgressBar(totalItems) {
var dlg = new Window('palette', 'Progress', undefined, {closeButton: false});
dlg.text = 'Processing...';
dlg.progressBar = dlg.add('progressbar', undefined, 0, totalItems);
dlg.progressBar.preferredSize = [300, 20];
dlg.progressText = dlg.add('statictext', undefined, '0%');
dlg.show();
return dlg;
}
function updateProgressBar(dlg, currentItem, totalItems) {
if (currentItem % 10 === 0 || currentItem === totalItems) {
dlg.progressBar.value = currentItem;
dlg.progressText.text = Math.round((currentItem / totalItems) * 100) + '%';
dlg.update();
}
}
function processItemsIteratively(selectedItems) {
var totalItems = selectedItems.length;
var unexpandedPatterns = [];
var dlg = createProgressBar(totalItems);
var stack = selectedItems.slice();
var currentItem = 0;
var batch = [];
var batchSize = 10;
while (stack.length > 0) {
var item = stack.pop();
currentItem++;
batch.push(item);
if (batch.length >= batchSize || stack.length === 0) {
processBatch(batch, unexpandedPatterns);
batch = [];
}
if (currentItem % 10 === 0 || currentItem === totalItems) {
updateProgressBar(dlg, currentItem, totalItems);
}
if ((item.typename === 'GroupItem' || item.typename === 'CompoundPathItem') && item.pageItems) {
for (var i = 0; i < item.pageItems.length; i++) {
stack.push(item.pageItems[i]);
}
}
}
dlg.close();
if (unexpandedPatterns.length > 0) {
alert('Expansion complete! Unexpanded patterns remain on the artboard.');
} else {
alert('Expansion complete!');
}
}
function processBatch(batch, unexpandedPatterns) {
for (var i = 0; i < batch.length; i++) {
var item = batch[i];
try {
if (item.typename === 'TextFrame') {
continue;
}
if (item.typename === 'GroupItem' || item.typename === 'PathItem') {
try {
var originalInteractionLevel = app.userInteractionLevel;
app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
app.executeMenuCommand('expandStyle');
app.userInteractionLevel = originalInteractionLevel;
} catch (e) {
}
}
if (item.typename === 'PluginItem') {
try {
var originalInteractionLevel = app.userInteractionLevel;
app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
app.executeMenuCommand('Expand3');
app.userInteractionLevel = originalInteractionLevel;
} catch (e) {
}
}
if (item.typename === 'PathItem' && item.filled) {
var fillColor = item.fillColor;
if (fillColor.typename === 'PatternColor') {
unexpandedPatterns.push(item);
}
}
} catch (e) {
alert("Error processing item: " + e.message);
}
}
}
var selectedItems = app.activeDocument.selection;
if (selectedItems.length > 0) {
processItemsIteratively(selectedItems);
} else {
alert('No items selected. Please select objects to expand.');
}
I attached a file to check the script below. If You choose only one object, the script will take about 3 min to execute, which is quite long. Two objects could hang a PC with i5 12600 for 7 min straight.
Thanks in advance
Copy link to clipboard
Copied
Find more inspiration, events, and resources on the new Adobe Community
Explore Now