• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Can you modify this script for me?

Explorer ,
Nov 05, 2020 Nov 05, 2020

Copy link to clipboard

Copied

Script modification requirement / Modification requirement 1: Adding the artboard is completed and automatically deselect all objects 2: Then the option window of Illustrator's file/export/export as...

 

 

//Select objects to add artboard


var doc = app.activeDocument;
var theSelect = doc.selection;
var objGBCheck = false; //Switch between geometric boundary and visual boundary //true //false

if (theSelect.length > 0) {
for (i = theSelect.length - 1; i > -1; i--) {
var bound = NO_CLIP_BOUNDS(theSelect[i]);
doc.artboards.add(bound);//Convert to artboard
}doc.artboards.remove(0);
} else {
alert("Hello there!\nYou must select the object first!!", "Error message");
}

function NO_CLIP_BOUNDS(the_obj) {
var NO_CLIP_OBJECTS_AND_MASKS = new Array();
GET_NO_CLIP_OBJECTS_AND_MASKS(the_obj);
var v_left = new Array();
var g_left = new Array();
var v_top = new Array();
var g_top = new Array();
var v_right = new Array();
var g_right = new Array();
var v_bottom = new Array();
var g_bottom = new Array();
for (var i = 0; i < NO_CLIP_OBJECTS_AND_MASKS.length; i += 1) {
g_left[i] = NO_CLIP_OBJECTS_AND_MASKS[i].geometricBounds[0];
v_left[i] = NO_CLIP_OBJECTS_AND_MASKS[i].visibleBounds[0];
g_top[i] = NO_CLIP_OBJECTS_AND_MASKS[i].geometricBounds[1];
v_top[i] = NO_CLIP_OBJECTS_AND_MASKS[i].visibleBounds[1];
g_right[i] = NO_CLIP_OBJECTS_AND_MASKS[i].geometricBounds[2];
v_right[i] = NO_CLIP_OBJECTS_AND_MASKS[i].visibleBounds[2];
g_bottom[i] = NO_CLIP_OBJECTS_AND_MASKS[i].geometricBounds[3];
v_bottom[i] = NO_CLIP_OBJECTS_AND_MASKS[i].visibleBounds[3];
}
var GV_Bounds = objGBCheck ? "true": "false";
switch (GV_Bounds) {
case "true":
var g_L = MIN_IN_ARRAY(g_left);
var g_T = MAX_IN_ARRAY(g_top);
var g_R = MAX_IN_ARRAY(g_right);
var g_B = MIN_IN_ARRAY(g_bottom);
return [g_L, g_T, g_R, g_B];
break;

case "false":
var v_L = MIN_IN_ARRAY(v_left);
var v_T = MAX_IN_ARRAY(v_top);
var v_R = MAX_IN_ARRAY(v_right);
var v_B = MIN_IN_ARRAY(v_bottom);
return [v_L, v_T, v_R, v_B];
break;
}

function GET_NO_CLIP_OBJECTS_AND_MASKS(the_obj) {
if (IS_CLIP(the_obj)) {
NO_CLIP_OBJECTS_AND_MASKS.push(the_obj.pageItems[0]);
return;
}
if (the_obj.constructor.name == "GroupItem") {
try {
var N_sub_obj = the_obj.pageItems.length;
for (var i = 0; i < N_sub_obj; i += 1) {
GET_NO_CLIP_OBJECTS_AND_MASKS(the_obj.pageItems[i]);
}
} catch(error) {

}
return;
}
NO_CLIP_OBJECTS_AND_MASKS.push(the_obj);
return;
}
}

function IS_CLIP(the_obj) {
try {
if (the_obj.constructor.name == "GroupItem") {
if (the_obj.clipped) {
return true;
}
}
} catch(error) {

}
return false;
}

function MAX_IN_ARRAY(the_array) {
var MAX = the_array[0];
for (var i = 0; i < the_array.length; i += 1) {
if (the_array[i] > MAX) {
MAX = the_array[i]
}
}
return MAX;
}

function MIN_IN_ARRAY(the_array) {
var MIN = the_array[0];
for (var i = 0; i < the_array.length; i += 1) {
if (the_array[i] < MIN) {
MIN = the_array[i]
}
}
return MIN;
}

TOPICS
Scripting

Views

407

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 08, 2020 Nov 08, 2020

@lengxiaomo wrote: "Added function: Cancel the selection of all objects …"

That is easy. Add this at the end::

doc.selection = null;

 

@lengxiaomo wrote: "Added function: … and pop up the illustrator file/export/export as window …"

The task is not yet clear.

Do you really need the export dialog? This means that the script is always interrupted for manual input.

 

And which way do you want to export?

  • export for screens
  • export as
  • save for web (legacy)
  • or selection export as

Which settings do you

...

Votes

Translate

Translate
Adobe
Explorer ,
Nov 06, 2020 Nov 06, 2020

Copy link to clipboard

Copied

Can someone help me? Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 08, 2020 Nov 08, 2020

Copy link to clipboard

Copied

I expect the reason you haven't received any replies is because your request is not clear. I would start by describing what the script does. Then describe what parts you want modifying, in terms of "instead of it doing that, I want it to do this". And describe it in as much detail as possible.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 08, 2020 Nov 08, 2020

Copy link to clipboard

Copied

Added function: Cancel the selection of all objects and pop up the illustrator file/export/export as window. The script has finished running. I hope you can understand my requirements. Thank you for your help

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2020 Nov 08, 2020

Copy link to clipboard

Copied

@lengxiaomo wrote: "Added function: Cancel the selection of all objects …"

That is easy. Add this at the end::

doc.selection = null;

 

@lengxiaomo wrote: "Added function: … and pop up the illustrator file/export/export as window …"

The task is not yet clear.

Do you really need the export dialog? This means that the script is always interrupted for manual input.

 

And which way do you want to export?

  • export for screens
  • export as
  • save for web (legacy)
  • or selection export as

Which settings do you use?

In which file format do you want to export?

 

You can call the save-dialog or the save-as-dialog - but IMHO not (one of) the export dialog(s) directly. But maybe in combination with actions.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 08, 2020 Nov 08, 2020

Copy link to clipboard

Copied

Hello I need to export to TIF dpi to 150. The export location needs to be manually set. I don’t know if the script can be implemented. Thank you for your help

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 08, 2020 Nov 08, 2020

Copy link to clipboard

Copied

Why manually? Do you want to save to a new location every time?

Otherwise, the location can be hard-coded in the script.

 

Export as tiff (without dialog) for example, see:

Export File as TIFF... no file saved 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 08, 2020 Nov 08, 2020

Copy link to clipboard

Copied

LATEST

Because of work reasons, an AI file needs to be exported to many different TIF folders, so you need to manually select the export location

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines