RobOctopus
Participant
RobOctopus
Participant
Activity
‎Feb 06, 2025
08:45 AM
I think the best way to achieve what you want is via an extension. Check this tutorial out, which achieves a dockable panel for script launching. This may do what you want, but if not it may provide some insight to expand upon what you may actually want. Alternative, and I am unsure what your goal is for your script, but you could look into making it more robust such that you do not need to interact with it at any point. may need to do things in batches. https://youtu.be/1MirbjuLgSI?si=aya_FWS1ixUN_M47
... View more
‎Jan 29, 2025
07:08 AM
I do not think this is possible in a simple way from Extendscript. I do however think you can do this by making a one-time action to load via scripting, using the action to shear, then deleting it. Untested, but just my hunch
... View more
‎Jan 23, 2025
10:31 AM
a lot of the sample scripts provided via the adobe application don't do anything spectacular but rather show functionality via extendscript. Its up to you to extrapolate how the script is being demonstrated and use it in a different way. opening the file to edit it would show you via the comments and the small amount of code how the desired result is achieved and what you would need to change to benefit your needs.
... View more
‎Jan 20, 2025
06:02 PM
when editting the contents of text via scripting you need to use insertion points to add text to maintain text styling. simply altering the contents will cause all of the contents to be reformatted to the same format as the first character.
... View more
‎Dec 14, 2024
11:17 AM
2 Upvotes
What you have described sounds do-able via scripting. If you would like to learn how to do it yourself, which i definitely recommend as it is easier to troubleshoot problems and you'll learn a skill thats quite invaluable, I would start very simple with some script ideas and expand on it. Things like just making a textframe and put text in it. moving an object somewhere on the document. changing the artboard or adding new ones. Scripting for Illustrator is built off of a slightly outdated javascript framework and using adobe's own syntax to create a language called Extendscript. Files you create would be .jsx files that are "javascript extended". The general framework for illustrator scripting mirrors the layer structure. If you want to access a text frame inside layer 1. you would targeting the application, then the document, then the layer, then the textframe. app.activeDocument.layers[0].textFrames[0] Every element for scripting will have both properties and methods. a property is a readable, usually writable, value of that element. the geometric bounds are a property you can access while looking at the textFrame, the contents of the text frame are a property that can be accessed. A method is a built-in function that that element can perform. textFrame.createOutline() is a function that will convert the targeted textframe to outlined graphics. var myTextFrame = app.activeDocument.layers[0].textFrames[0]
myTextFrame.contents /*would return whatever the contents are*/
myTextFrame.createOutline() /*would convert the text frame into outline paths*/ For your script you would probably want to utilize a UI window to input some information and then have it create the desired documentation. I have a script setup that does just that for my companies packaging process. every package gets put onto a frame that outlines the specifications for printing, the inks used, the dieline used, and some other information like modification dates. it was originally a non-documented 15-30 min process, if not longer if it was your first time. It's now 30 seconds to a minute at most. some resources to get started Documentation for the illustrator framework. https://ai-scripting.docsforadobe.dev/index.html The ScriptUI panel can be a tricky thing to understand, someone built a fantastic web tool to assist with making them. https://scriptui.joonas.me/ W3schools isnt the best documentation for javscript but I think it works just fine. Some stuff is too new for the javscript engine that extendscript uses and therefore doesnt exist. https://www.w3schools.com/jsref/default.asp For Coding, I use Visual Studio Code to write the scripts. most any texteditor would work though. https://code.visualstudio.com/ I started scripting for indesign and illustrator about 4-5 years ago, knowing absolutely nothing. a lot of trial, error, and picking apart other peoples code is how I learned. I would start with some service to learn basic javascript so you can understand strings, objects, arrays, and more. Then once you have a grasp on javascript, dive into the documentation for illustrator and start fiddling around. Hope this helps! feel free to ask more questions
... View more
‎Nov 26, 2024
08:20 AM
1 Upvote
Layers do not have a hidden property, they are visible https://ai-scripting.docsforadobe.dev/jsobjref/Layer.html#layer-visible I would wager this is the problem
... View more
‎Nov 06, 2024
07:31 AM
Not really sure what youre asking in your post, but it seems like you need to use some grep searching to test if a layer name is accurate var layerName = layer.name
if(layerName.toString().search(/XX T\d+( .+)?/gi)!=-1){
/*the search will return 0 if the layername satisfies the search of having XX T any number of digits and maybe extra text after it. if it doesnt meet that criteria it will return -1 for the search*/
}
... View more
‎Oct 24, 2024
01:15 PM
2 Upvotes
There's 2 ways to go about this. 1) you create a rectangle path at your desired position and size and then turn that path into an area text frame var Rect = app.activeDocument.pathItems.rectangle(Y,X,Width,Height)
/* you will have to change the Y X width Height values to meet your needs. usually the Y value is a negative based number so from top left of artboard -Y will move the object to the bottom of the artboard. X works as regular left is 0 right is positive number.*/
var AreaText = app.activeDocument.textFrames.areaText(Rect)
AreaFrame.contents = "Test Box" 2) create your area text frame and then you alter the textpath of the frame to alter the dimensions without skewing the text var AreaFrame = app.activeDocument.textFrames[0]
/* target your area text frame and then set the values of each coordinate left/top/height/width*/
AreaFrame.textPath.left = 10 /* x coord */
AreaFrame.textPath.top = -20 /* y coord usually negative based */
AreaFrame.textPath.height = 50;
AreaFrame.textPath.width = 100;
... View more
‎Oct 15, 2024
08:26 AM
didn't read the rest of the script, but no where is the window declared a palette var myWindow = new Window(
"dialog",
"Custom Checks & Fixes - Illustrator, v1.0",
undefined,
{ resizeable: true }
);
/* change to */
var myWindow = new Window(
"palette",
"Custom Checks & Fixes - Illustrator, v1.0",
undefined,
{ resizeable: true }
);
... View more
‎Oct 09, 2024
12:16 PM
1 Upvote
I am unfamiliar with running scripts from actions, but my theory is that because the action is running the script there is a problem with illustrator updating. I tried this on a whim and it seemed to work. Add app.redraw() after the item being selected. = true. This will force illustrator to redraw and it now notices the item is selected and therefore the group command will work and the renaming will work.
... View more
‎Oct 03, 2024
09:09 AM
Text Fill Color is a property of CharacterAttributes. code should be aTextFrame.textRange.characterAttributes.fillColor = ColorObjectThing;
/*or*/
aTextFrame.textRange.characterAttributes.fillColor = app.activeDocument.swatches.getByName("SwatchName").color;
... View more
‎Sep 09, 2024
07:12 AM
there may be a better way, but this had worked for a smaller task of mine. feel free to change the text increment values to whatever text you plan on using. if youre using larger text, then .5 may be too small of an increment. /*do this to whatever textframe you want to check. but as long as the text frame is returning true for overset, the loop will keep running and each loop will reduce each character by .5 size and .5 leading.*/
while(CheckIfOverset(Selection)){
var CharLen = Selection.textRange.characters.length
for (var p = 0; p < CharLen; p++) {
Selection.textRange.characters[p].size-=0.5
Selection.textRange.characters[p].leading-=0.5
}
}
/* overset function takes area frame, converts to point text and determines if text is overset */
function CheckIfOverset(t) {
var d;
d = t.duplicate()
d.name = 'temp'
d.convertAreaObjectToPointObject()
d = t.parent.textFrames['temp']
if (d.contents.replace(/[\x03\r]/g, '') !== t.contents.replace(/[\x03\r]/g, '')) {
d.remove();
return true
} else {
d.remove();
return false
}
}
... View more
‎Jul 30, 2024
01:31 PM
1 Upvote
I am not a fan of the method outlined above for adding elements to scriptUI, someone more familiar can explain why they do or do not work. The method that the https://scriptui.joonas.me/ exports is easier to understand whats happenning. I removed the lines refering to myInputText and added this instead and it works as intended /*
Commented out code block to replace with other definition method
var myInputText = myPanel2.add ('group {orientation: "column", alignChildren: ["fill","fill"]}');
myInputText.add ('edittext', undefined, "Enter");
myInputText.characters = 50;
myInputText.active = true;
//myInputText.text = "test"
//added a line to specifically edit the text contents, it remained as "enter" but would return the text contents of the line "test"
*/
var myInputText = myPanel2.add('edittext {properties: {name: "myInputText"}}');
myInputText.text = "Enter";
... View more
‎Jul 09, 2024
01:30 PM
1 Upvote
a script could do this, but i think learning InDesign's Data Merge tool would be better. you would create an excel sheet of whatever Data you want. in this case it's just the numbers 1-300+. Then you create a file in indesign and design the text box to your liking then merge the data and it will replicate the data through the design. It would be a multi-record merge.
... View more
‎Jul 09, 2024
01:06 PM
could you provide an image of what youre looking for? is Indesign an option for you?
... View more
‎Jun 05, 2024
07:18 AM
1 Upvote
might not be ideal, but this was able to produce the results. i dont think i've ever seen someone turn off the visibility in the appearance before. var circle = app.activeDocument.selection[0]
app.executeMenuCommand('deselectall')
var rect = app.activeDocument.pathItems.rectangle(circle.top - 36, circle.left, 36, 36);
rect.selected=true
app.executeMenuCommand('Adobe New Stroke Shortcut')
app.redraw()
rect.stroked = true;
rect.strokeWidth = 3
... View more
‎May 28, 2024
10:46 AM
if you try to save it asdoc.name+suffix. it will fail to save the file since .pdf_plateno isnt a file type. You will need to do what I wrote in my previous reply about pulling the .pdf part out of the filename, so it becomes Filename+suffix+".pdf" var fileNameOnly = app.activeDocument.name.substring(0,app.activeDocument.name.lastIndexOf("."))
var newFullName = fileNameOnly+suffix+".pdf"
... View more
‎May 23, 2024
12:38 PM
No Problem @Aidan_C . Unfortunately, aligning stroke is really goofy via scripting, but doable. Add the following to the previous code. /*the original code i sent had layers being created around line 23/24 add this there*/
var BackgroundRectangle = FindLayerCreate(app.activeDocument, "WHITE RECTANGLE")
/*previous code things here*/
/*then after the circles are made add this
it will create a rectangle on the background rectangle layer we make earlier
then we make sure the stroke is white, the width is equal to the circle sizes, and that there isnt a fill. then we call the align stroke function and finally move it to the bottom of the stack as a redudancy*/
var WhiteRectangle = BackgroundRectangle.pathItems.rectangle(ATop+Bleed,ALeft-Bleed, AWidth+(Bleed*2), -(AHeight-(Bleed*2)))
WhiteRectangle.stroked = true
WhiteRectangle.strokeWidth = CircleWidthHeight
WhiteRectangle.strokeColor = new CMYKColor();
WhiteRectangle.filled = false
WhiteRectangle.fillColor = new NoColor();
AlignStroke(WhiteRectangle, 1)
BackgroundRectangle.move(app.activeDocument,ElementPlacement.PLACEATEND)
/* somewhere at the bottom of the code, copy/paste this function does some goofy things to align the stroke by creating an action to do it for us and then deleting the action */
/**
* Will change the alignment of a stroked path.
* @param {Object} FrameToAlign - PathItem to edit
* @param {String|Number} AlignNumber - 0=Center, 1=Inside, 2=Outside
*/
function AlignStroke(FrameToAlign, AlignNumber){
/*
need to grab the previous stroke join and cap as they are overwritten for some reason.
will reset them back to their previous state at the end of the function
*/
var PreviousJoin = FrameToAlign.strokeJoin
var PreviousCap = FrameToAlign.strokeCap
switch(AlignNumber){
case "0":
case 0:
var AlignInsert = [
'/name [ 6',
'43656e746572',
']',
'/value 0']
break;
case "1":
case 1:
var AlignInsert = [
'/name [ 6',
'496e73696465',
']',
'/value 1']
break;
case "2":
case 2:
var AlignInsert = [
'/name [ 7',
'4f757473696465',
']',
'/value 2']
break
}
var ActionString = [
'/version 3',
'/name [ 14',
'5374726f6b65416c69676e536574',
']',
'/isOpen 1',
'/actionCount 1',
'/action-1 {',
'/name [ 17',
'5374726f6b65416c69676e416374696f6e',
']',
'/keyIndex 0',
'/colorIndex 0',
'/isOpen 1',
'/eventCount 1',
'/event-1 {',
'/useRulersIn1stQuadrant 0',
'/internalName (ai_plugin_setStroke)',
'/localizedName [ 10',
'536574205374726f6b65',
']',
'/isOpen 1',
'/isOn 1',
'/hasDialog 0',
'/parameterCount 1',
'/parameter-1 {',
'/key 1634494318',
'/showInPalette 4294967295',
'/type (enumerated)'].concat(AlignInsert,
'}',
'}',
'}').join("\n")
var f = File(Folder.desktop+"/StrokeAlignment.aia");
f.open('w');
f.write(ActionString);
f.close();
app.executeMenuCommand("deselectall")
FrameToAlign.selected = true;
app.loadAction(f);
app.doScript('StrokeAlignAction', 'StrokeAlignSet');
app.unloadAction('StrokeAlignSet', '');
f.remove();
FrameToAlign.strokeJoin = PreviousJoin
FrameToAlign.strokeCap = PreviousCap
}
... View more
‎May 22, 2024
10:50 AM
1 Upvote
not sure I'm understanding the question, but hopefully this helps app.activeDocument.fullName /* is equal to "~/Desktop/Test.ai" or "/Users/USERNAME/Desktop/Test.ai" */
app.activeDocument.name /* is equal to "Test.ai" */ if you wish to remove the .ai, theres a few options, here is one var fileNameOnly = app.activeDocument.name.substring(0,app.activeDocument.name.lastIndexOf(".")) it will kick back as just "Test" you can then formulate your new Path location using the string var newFileLocation = New File("/Folder/Folder/Folder/"+fileNameOnly+".pdf")
var PDFopts = new PDFSaveOptions();
/* can add any save options here */
app.activeDocument.saveAs(newFileLocation, PDFopts);
... View more
‎May 22, 2024
09:19 AM
you'll have to write out the path location to save it. for instance say the current file, Test.ai, is on my desktop. the Filepath would look like /* Mac Scenario */
var myFileLocation = "/Users/USERNAME/Desktop/Test.ai" if I wanted to save the file in a new location say a cloud storage location. I just need to change where the path is drawing to. Here is an example use Box as a mounted location /* Mac Scenario */
var myOriginalFile = "/Users/USERNAME/Desktop/Test.ai"
var myNewLocation = new File("Users/USERNAME/Library/CloudStorage/Box-Box/FolderOnBox/Test.ai")
app.activeDocument.saveAs(myNewLocation);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES) I don't do Windows Pathing often, if ever, so not sure the syntax for the file path is the same, but the idea should be the same.
... View more
‎May 20, 2024
05:02 AM
1 Upvote
What you're looking for is the capitalization attribute. alert(app.activeDocument.textFrames[0].textRange.characterAttributes.capitalization)
app.activeDocument.textFrames[0].textRange.characterAttributes.capitalization = FontCapsOption.ALLCAPS
alert(app.activeDocument.textFrames[0].textRange.characterAttributes.capitalization) on a blank document, this sample code just targets the first text frame and changes the capitalization setting to all caps. All of the Font Cap options you mentioned are what are used here FontCapsOption.ALLCAPS All Caps FontCapsOption.ALLSMALLCAPS All Smallcaps FontCapsOption.NORMALCAPS Normal Caps FontCapsOption.SMALLCAPS Small Caps EDIT: Wanted to also add. The above is a display change to the text. The text may internally be set as "Lorem Ipsum" but changed to display setting as All Caps would display as "LOREM IPSUM" while maintaining the internal text as "Lorem Ipsum". To access the Change case functionality you can either do a heavier coding approach to change the text contents or use the executeMenuCommand to access those commands. https://ten-artai.com/illustrator-ccver-22-menu-commands-list/ app.executeMenuCommand("UpperCase Change Case Item")
app.executeMenuCommand("LowerCase Change Case Item")
app.executeMenuCommand("Title Case Change Case Item")
app.executeMenuCommand("Sentence case Change Case Item")
... View more
‎May 17, 2024
03:07 PM
From what i've gathered, there is not a clean and easy way to script the setting of a documents bleed. If someone else knows an easy way to implement feel free to add. below is a script that will create the 10 circles you need, 5 filled, and 5 stroked. I would suggest using a different name than "black" for your swatch. it gets messy since there is already a default black swatch. /*get the artboards dimensions for placing the circles*/
var ArtboardRect = app.activeDocument.artboards[0].artboardRect
var ALeft = ArtboardRect[0]
var ATop = ArtboardRect[1]
var ARight = ArtboardRect[2]
var ABottom = ArtboardRect[3]
var AWidth = ArtboardRect[2]-ArtboardRect[0]
var AHeight = ArtboardRect[3]-ArtboardRect[1]
/*
change the bleed value here to change where the circles need to be placed
change the CircleWidthHeight value to change how large the circles are. they are currently 6mm converted to pts.
look up the UnitValue function to edit these
*/
var Bleed = UnitValue(9,"mm").as("pt")
var CircleWidthHeight = UnitValue(6,"mm").as("pt")
/* adds the spot colors. will probably fail with the black as the name is not unique*/
AddSpot("Black", 0, 0, 0, 100, true)
AddSpot("Registration", 100, 0, 100, 0, true)
/*create new layers for your new circles*/
var FilledCircles = FindLayerCreate(app.activeDocument, "BLACK CIRCLES")
var StrokedCircles = FindLayerCreate(app.activeDocument, "OVERPRINT")
/*here we set the values for making the stroked circles*/
var StrokeValues = {
stroked: true,
sWidth: 0.25,
sColor: app.activeDocument.swatches.getByName("Registration").color,
sOverprint: true,
filled: false,
fColor: new NoColor(),
fOverprint: false,
targetLayer: StrokedCircles
}
/*make all 5 stroked circles*/
MakeCircle(ATop+Bleed,ALeft-Bleed,CircleWidthHeight,StrokeValues)
MakeCircle(ATop+Bleed,ARight+Bleed-CircleWidthHeight,CircleWidthHeight,StrokeValues)
MakeCircle(ABottom-Bleed+CircleWidthHeight,ARight+Bleed-CircleWidthHeight,CircleWidthHeight,StrokeValues)
MakeCircle(ABottom-Bleed+CircleWidthHeight,ALeft-Bleed,CircleWidthHeight,StrokeValues)
MakeCircle((ABottom/2)+(CircleWidthHeight/2),ALeft-Bleed,CircleWidthHeight,StrokeValues)
/*set the values for the filled circles*/
var FillValues = {
stroked: false,
sWidth: 0,
sColor: new NoColor(),
sOverprint: false,
filled: true,
fColor: app.activeDocument.swatches.getByName("Black").color,
fOverprint: false,
targetLayer: FilledCircles
}
/*make all 5 filled circles*/
MakeCircle(ATop+Bleed,ALeft-Bleed,CircleWidthHeight,FillValues)
MakeCircle(ATop+Bleed,ARight+Bleed-CircleWidthHeight,CircleWidthHeight,FillValues)
MakeCircle(ABottom-Bleed+CircleWidthHeight,ARight+Bleed-CircleWidthHeight,CircleWidthHeight,FillValues)
MakeCircle(ABottom-Bleed+CircleWidthHeight,ALeft-Bleed,CircleWidthHeight,FillValues)
MakeCircle((ABottom/2)+(CircleWidthHeight/2),ALeft-Bleed,CircleWidthHeight,FillValues)
function MakeCircle(Top,Left,CWH,StrokeFillValues){
var newCircle = StrokeFillValues.targetLayer.pathItems.ellipse(Top,Left,CWH,CWH,false)
newCircle.stroked = StrokeFillValues.stroked
newCircle.filled = StrokeFillValues.filled
newCircle.strokeWidth = StrokeFillValues.sWidth
newCircle.strokeColor = StrokeFillValues.sColor
newCircle.strokeOverprint = StrokeFillValues.sOverprint
newCircle.fillColor = StrokeFillValues.fColor
newCircle.fillOverprint = StrokeFillValues.fOverprint
}
/**
* Adds a spot swatch based on CMYK information
* @Param {Object|String} NewColor - if its an object of color information will convert otherwise assumes its a string
* @Param {Number} c - the value of Cyan 0-100
* @Param {Number} m - the value of Magenta 0-100
* @Param {Number} y - the value of Yellow 0-100
* @Param {Number} k - the value of Black 0-100
* @Param {Boolean} SpotProcess - true/false if the spot color is a process or not. if true will be spot
*/
function AddSpot(NewColor, c, m, y, k, SpotProcess) {
SpotProcess = (SpotProcess === 'true') /*convert to bool*/
if (typeof NewColor == "object") {
var name = NewColor[0]
var c = NewColor[1]
var m = NewColor[2]
var y = NewColor[3]
var k = NewColor[4]
} else if (typeof NewColor == "string") {
name = NewColor
} else {
alert(NewColor + " is not in a recognizable format for coding")
}
try {
swatch = app.activeDocument.swatches[name]; // if swatch exists....
//AddSpot (name+=' 1', c, m, y, k); // ...add 1 to swatch name
} catch (e) {
var newColor = new CMYKColor();
newColor.cyan = c;
newColor.magenta = m;
newColor.yellow = y;
newColor.black = k;
var newSpot = app.activeDocument.spots.add()
newSpot.colorType = SpotProcess ? ColorModel.SPOT : ColorModel.PROCESS;
newSpot.name = name;
newSpot.color = newColor;
}
}
function FindLayerCreate(ParentLayer, ChildLayer) {
try {
var NewLayer = ParentLayer.layers[ChildLayer]
} catch (e) {
var NewLayer = ParentLayer.layers.add()
NewLayer.name = ChildLayer
}
return NewLayer
}
... View more
‎Apr 12, 2024
09:53 AM
so you want to take the information from 1 file. hold it into a script and recreate on another machine. This, i'm sure makes copy paste information unusable. I would think you would have an easier time getting the path of the object and contents (size, leading, etc) and then recreating that way psuedo code
get text frames
for each text frame
get all path points along their text path (to recreate the path items, allows for irregular shapes)
get the contents of the text frame
for each character house loop through and save the size,leading and other pertinent styling options, along with font
all of the above information would be housed in some array format
new doc loop through array
create path item from coordinates
add text contents to path
loop through all character styling and apply correct styles to each
... View more
‎Apr 12, 2024
09:12 AM
to get the width of the line add a width statement of the textframe you just created and added contents to myTextFrame.contents = lineArr[i];
thisWidth = myTextFrame.width in regards to the lines not matching exactly the script is outlining text to get exact coordinates of the text objects then duplicating the text by each line to a new frame, but using the coordinates of the text outlines. text frames however include other space above the text which should be the ascender height of the point size, which can be irregular. I am unsure what your end goal is with the script, but it currently seems like it is complicating a process and getting undesired results due to the overcomplication
... View more
‎Apr 11, 2024
09:28 AM
If you zoom out, you should see the text showing up (at least if the layer structure is showing there should be text). based on my testing, you need to change your rulerOrigin for the new document. the script is getting the coordinates of the text frame based on 1 rulerOrigin, then the next document is using a different rulerOrigin, so the coordinates are not matching. I added myDocument.rulerOrigin = [0,myDocument.artboards[0].artboardRect[1]] to the code directly after line 55 when myDocument is added and the text was placing in the same fashion as the original document.
... View more
‎Apr 10, 2024
12:21 PM
3 Upvotes
does this solution not already answer your question you've asked before? https://community.adobe.com/t5/illustrator-discussions/how-to-get-textrange-each-line-start-and-end-character-cooridnates-using-extendscript/td-p/14422468
... View more
‎Apr 05, 2024
08:44 AM
1 Upvote
I see what you're trying to do with the offset calculations but they arent quite being used correctly and it might be confusing when trying to think that way. youre offsetting some values that shouldnt be offset like the X coord on a vertical line. i rewrote the drawMark values so they work now without using the offset and end vars // Top-left corner
drawMark(x1, y1 + bleedPoints, lengthPoints, true); // Vertical
drawMark(x1 - bleedPoints-lengthPoints, y1, lengthPoints, false); // Horizontal
// Top-right corner
drawMark(x2, y1 + bleedPoints, lengthPoints, true); // Vertical
drawMark(x2+bleedPoints, y1, lengthPoints, false); // Horizontal
// Bottom-left corner
drawMark(x1, y2-bleedPoints-lengthPoints, lengthPoints, true); // Vertical
drawMark(x1-bleedPoints-lengthPoints, y2, lengthPoints, false); // Horizontal
// Bottom-right corner
drawMark(x2, y2-bleedPoints-lengthPoints, lengthPoints, true); // Vertical
drawMark(x2+bleedPoints, y2, lengthPoints, false); // Horizontal
... View more
‎Apr 03, 2024
08:36 AM
Cant see the top lines, but if TopFolder is undefined or in the wrong format, then it will fail.
... View more
‎Apr 03, 2024
08:14 AM
1 Upvote
alternative approach if you dont want to keep the 2.83... constant anytime you want to use it. There is a built in function to create and convert units UnitValue(Value,Unit) This will create a value in the specified unit. so you can do UnitValue(8,"mm") and it would be an 8 mm value. the problem specifically with Illustrator is all values are point based. There's another function with UnitValue to convert UV.as(conversion) so you can do UnitValue(8,"mm").as("pt") and it will convert the 8 mm to points for use. so the above could be var newWidth = width + UnitValue(8,"mm").as("pt") more documentation here https://extendscript.docsforadobe.dev/extendscript-tools-features/specifying-measurement-values.html once I found this, I started using this method over having to keep the units I needed as a global value or put into each function. Cheers
... View more
‎Apr 02, 2024
01:42 PM
1 Upvote
This should work, its not super refined, but it will do what you need. run the file from illustrator (or indesign) select a folder containing the files you want to rename select a file containing the data of old name and new name. data must be saved as a tabbed text file with column 1 being old name and column 2 being new name assumes all of the files will be .eps I would suggest copying your files somewhere as a backup before making changes to them. couple of things you will need to open the file and change. var TopFolder = Folder("PATH TO FOLDER OF FILES")
var DataFile = File("PATH TO TABBED TEXT FILE")
/* alternatively, you can use a selection each time you run, just comment the lines above out and uncomment the ones below */
//var TopFolder = Folder.selectDialog("Pick the Folder containing the Files you want to rename")
//var DataFile = File.selectDialog("Pick the File containing the Data for renaming")
if(TopFolder!=undefined && DataFile!=undefined){
/*we open the data file and get the contents*/
DataFile.open('r');
DataFileContents = DataFile.read().split("\n"); /*split data on line returns*/
DataFile.close();
for(var a=0;a<DataFileContents.length;a++){
DataFileContents[a] = DataFileContents[a].split("\t") /*split rows on tabs*/
}
var allFiles = scanSubFolders(TopFolder); /*get all of the files in the TopFolder*/
var afL = allFiles.length;
for (var i=0;i<afL;i++){
var ThisFile = allFiles[i]
var ThisFileName = ThisFile.name.toString().substring(0,ThisFile.name.toString().lastIndexOf(".")) /*pull only the filename back and cut off the end*/
var NewName = FindDataInArray(ThisFileName,DataFileContents)+".eps" /*get the new name and add .eps to it*/
if(NewName!=false){
ThisFile.rename(NewName);
}
}
}
/*this is not the best function, but it works
this function assumes the data is set up so the old file name is array 0 and new name is array 1
*/
function FindDataInArray(DataToFind,ArrayToTest){
for(var a=0;a<ArrayToTest.length;a++){
if(ArrayToTest[a][0]==DataToFind) return ArrayToTest[a][1]
}
return false
}
function scanSubFolders(tFolder) { // folder object
var sFolders = new Array();
var allFiles = new Array();
sFolders.push(tFolder);
for (var j = 0; j < sFolders.length; j++) { // loop through folders
var procFiles = sFolders[j].getFiles();
for (var i = 0; i < procFiles.length; i++) { // loop through this folder contents
if (procFiles[i] instanceof File) {
allFiles.push(procFiles[i]);// if no search mask collect all files
} else if (procFiles[i] instanceof Folder) {
sFolders.push(procFiles[i]);// store the subfolder
scanSubFolders(procFiles[i]);// search the subfolder
}
}
}
return allFiles;
};
... View more