
nearz
Explorer
nearz
Explorer
Activity
‎Aug 16, 2020
05:50 AM
Yes I have looked at this, I believe this is only for popup alerts. For example I have a script right now that currently goes through and selects different objects one at a time, makes the edit and moves on to the next object until complete. Illustrator currently renders the preview to highlight the selection, the same as when the user is manually selecting the object. My thought process is that if illustrator does not have to update the preview at the same time as running the script then it may help script performance.
... View more
‎Aug 15, 2020
05:37 PM
Hi all, Is there anyway to suspend Illustrator UI while a script executes?
... View more
‎Aug 14, 2020
03:28 PM
Hi All, I was able to get Silly-V's dynamic actions tutorial to work for some pathfinder commands that I needed access to. I have now tried it with selecting and deleting unused swatches, but it does nothing. I set app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS, thinking the alert that is given when you delete the swatches was the problem but no luck. Any help would be appreciated. function unusedSwatch(){
actionString = [
'/version 3',
'/name [ 8',
'756e757365647377',
']',
'/isOpen 1',
'/actionCount 1',
'/action-1 {',
'/name [ 8',
'737774636864656c',
']',
'/keyIndex 0',
'/colorIndex 0',
'/isOpen 0',
'/eventCount 2',
'/event-1 {',
'/useRulersIn1stQuadrant 0',
'/internalName (ai_plugin_swatches)',
'/localizedName [ 8',
'5377617463686573',
']',
'/isOpen 0',
'/isOn 1',
'/hasDialog 0',
'/parameterCount 1',
'/parameter-1 {',
'/key 1835363957',
'/showInPalette 4294967295',
'/type (enumerated)',
'/name [ 17',
' 53656c65637420416c6c20556e75736564',
']',
'/value 11',
'}',
'}',
'/event-2 {',
'/useRulersIn1stQuadrant 0',
'/internalName (ai_plugin_swatches)',
'/localizedName [ 8',
'5377617463686573',
']',
'/isOpen 0',
'/isOn 1',
'/hasDialog 1',
'/showDialog 1',
'/parameterCount 1',
'/parameter-1 {',
'/key 1835363957',
'/showInPalette 4294967295',
'/type (enumerated)',
'/name [ 13',
' 44656c65746520537761746368',
']',
'/value 3',
'}',
'}',
'}'
].join('\n')
$.writeln('hit')
doc = app.activeDocument
var aiFile = doc.fullName.fsName
var dirArray = aiFile.split('/');
dirArray[dirArray.length-1] = 'unusedsw.aia'
var newPath = dirArray.join('/')
var f = new File(newPath)
f.open('w')
f.write(actionString)
f.close()
app.loadAction(f)
app.doScript('unusedsw', 'swtchdel')
app.unloadAction('unusedsw', '');
f.remove();
}
... View more
‎Aug 14, 2020
04:31 AM
That appears to have worked. Thank you both. femkeblanco, I was moving each item one at a time as I came across them for a color check. When I had the issue deleting the layers I thought it was a timing issue, first thought was if I could move all items at once then remove layers may help with the timing. So I collected all pageItems by color into an array, grouped them, then moved them to the layer created. Code, its messy right now but it works with the backwards iteration. If you all know of a way to do this efficently please let me know. //@include "../utils/json2.jsx"
doc = app.activeDocument
drillBoxes()
function drillBoxes(){
allPageItems = filterPageItems()
seps = seprateItems(allPageItems)
moveToLayer(seps)
removeEmptyLayers(doc.layers)
}
function addToGroup(arr){
groupCollect = doc.groupItems.add()
for(i=0; i<arr.length; i++){
arr[i].move(groupCollect, ElementPlacement.PLACEATBEGINNING)
}
return groupCollect
}
function moveToLayer(sepObj, callback){
for(y=0; y < sepObj.colors; y++){
nGroup = addToGroup(seps[seps.colornames[y]])
nGroup.move(doc.layers[seps.colornames[y]], ElementPlacement.PLACEATBEGINNING)
}
}
function seprateItems(allPageItems){
//Move all items at once?
createdLayers = {}
createdLayers['colors'] = 0
createdLayers['colornames'] = []
len = allPageItems.length
for(z=0; z < len; z++){
j = allPageItems[z].length - 1
while(j >= 0){
currItem = allPageItems[z][j]
if(currItem.typename === 'CompoundPathItem'){
if(currItem.pathItems.length){
if(currItem.pathItems[0].filled){
currColor = currItem.pathItems[0].fillColor
}else{
currColor = currItem.pathItems[0].strokeColor
}
if(currColor.constructor.name === 'SpotColor'){
if(currColor.spot.name === '[Registration]'){
currItem.remove()
j--
continue
}
if(createdLayers[currColor.spot.name + 'color']){
createdLayers[currColor.spot.name].push(currItem)
}else{
addLayer(currColor.spot.name, [50, 50, 50])
doc.layers[currColor.spot.name].zOrder(ZOrderMethod.SENDTOBACK)
createdLayers[currColor.spot.name] = []
createdLayers[currColor.spot.name].push(currItem)
createdLayers['colors'] += 1
createdLayers['colornames'].push(currColor.spot.name)
createdLayers[currColor.spot.name + 'color'] = true
}
}else{
currItem.remove()
}
}else{
curItem.remove()
j--
continue
}
}else{
if(currItem.fillColor.constructor.name === 'SpotColor' || currItem.strokeColor.constructor.name === 'SpotColor'){
if(currItem.filled){
currColor = currItem.fillColor
}else{
currColor = currItem.strokeColor
}
if(currColor.spot.name === '[Registration]'){
currItem.remove()
j--
continue
}
if(createdLayers[currColor.spot.name + 'color']){
createdLayers[currColor.spot.name].push(currItem)
}else{
addLayer(currColor.spot.name, [50, 50, 50])
doc.layers[currColor.spot.name].zOrder(ZOrderMethod.SENDTOBACK)
createdLayers[currColor.spot.name] = []
createdLayers[currColor.spot.name].push(currItem)
createdLayers['colors'] += 1
createdLayers['colornames'].push(currColor.spot.name)
createdLayers[currColor.spot.name + 'color'] = true
}
}else{
currItem.remove()
}
}
j--
}
}
return createdLayers
callback()
}
function filterPageItems(){
collect = []
docLayers = doc.layers
for(i=0; i < docLayers.length; i++){
currLayer = docLayers[i]
returnArr = []
collectedPageItems = pageItemCustomRecursive(currLayer, returnArr)
collect.push(collectedPageItems)
}
// cleanCollect = twoDeArraytoOneDe(collect)
return collect
}
function pageItemCustomRecursive(parent, returnItems){
if(parent.typename == "Layer" && parent.layers.length > 0){
var layers = parent.layers
for( var i = 0; i < layers.length; i++ ) {
var subLayer = layers[i]
pageItemRecursive(subLayer, returnItems)
}
}
var items = parent.pageItems
for( var j = 0; j < items.length; j++ ){
var curItem = items[j]
if(curItem.typename == "GroupItem"){
pageItemRecursive(curItem, returnItems)
}else if(curItem.typename == "MeshItem" || "PlacedItem" || "SymbolItem" || "RasterItem" || "NonNativeItem" || "PluginItem" || "PathItem" || "CompoundPathItem"){
returnItems.push(curItem)
}
}
return returnItems
}
function removeEmptyLayers(arr){
$.writeln(arr)
app.redraw()
for(i=arr.length-1; i >= 0; i--){
$.writeln(arr[i])
if(arr[i].pageItems.length === 0){
arr[i].remove()
}else{
$.writeln(arr[i])
continue
}
}
} function addLayer(name, rgbColors){
if (rgbColors === undefined){rgbColors = [255, 0, 255]}
var cont = true;
function change() {
cont = !cont;
}
for(i = 0; i < app.activeDocument.layers.length; i++){
if(app.activeDocument.layers[i].name == name){
change();
}
}
if (cont == true) {
var newColor = new RGBColor();
newColor.red = rgbColors[0];
newColor.green = rgbColors[1];
newColor.blue = rgbColors[2];
var newLayer = app.activeDocument.layers.add();
newLayer.name = name;
newLayer.color = newColor;
}
app.activeDocument.layers[name].visibile = true
app.activeDocument.layers[name].locked = false
app.activeDocument.activeLayer = app.activeDocument.layers.getByName(name);
} Also using this function from another file
... View more
‎Aug 13, 2020
05:24 PM
I have something already written that will go through and add pageItems to an array based on the fill or stroke color being the same. At first I was moving each item to a layer named with the color that the item was either filled with or stroked with. After moving all items to a different layer in the document I would attempt to go through and delete the empty layers. I am not exactly sure what was happening but it seemed that the script started to try and delete layers before all pageItems were moved to the new layer. So there were empty layers left. I tried redraw() before trying to delete the layers this worked a little better but still did not work entirely, and seemed to be speratic and deleting 0, 1, 2, 3.... layers everytime I ran it. I cannot seem to find a solution to this. So my next attempt was to collect each item to an array and try to add that to app or document selection app.selection = [pageItems...] app.activeDocument.selection = [pageItems] The script would freeze up, and when I quit it I was left with some of the items selected. Again not exactly sure what was happening here either. I also tried to research a way to move the array of pageItems all at once after being collected. Not finding anything on this so not sure if it is possible. I am trying to avoid running through a loop again. There are over 4,000 pageItems I am testing on, production files could possibly be much more.
... View more
‎Aug 09, 2020
06:13 AM
I am trying to use to the reflection interface to get information on undocumented methods. When I follow the JS tool guide some of the properties do not return anything. obj.reflect.properties : works obj.reflect.methods : works obj.reflect.name : works obj.reflect.description & obj.reflect.help : does not work - nothing prints to console. object.reflect.methods.{{$methodname}}.arguments(or argumetns[#]) : does not work There is not much documentation on the web, any help would be appreciated.
... View more
‎Jul 21, 2020
12:37 PM
Yup, I misread part of the second response from Maple_Stirrup. I thought the goal was to modify the clipping path indivdually and masked art would be static. This is the better example to go by.
... View more
‎Jul 21, 2020
06:10 AM
2 Upvotes
I would also suggest getting the absolute value for w and h. This way if one of the y or x points is negative in the cartersian plane, you will still get a positive number. var w = Math.abs(x2 - x1);
var h = Math.abs(y1 - y2);
... View more
‎Jul 21, 2020
06:00 AM
1 Upvote
If you have a reference to the shape that is drawn for the mask, you can use that reference after it is a mask to modify as need. You can also name the pathItem that is drawn for the mask and get it later on in your script with getByName({{'name'}}). Here is an example. I have a circle in the document, a rectanlge is drawn, select all, then clip to the rectangle. The recatngle the script drew still has a variable name("rectClip") that can be referenced, with this variable name I can rotate the mask 90º. Of course this would need to be modified to fit your needs. var rectClip = app.activeDocument.pathItems.rectangle(-200, 0, 612, 200)
rectClip.filled = false
rectClip.name = 'MyClip'
app.executeMenuCommand('selectall')
app.executeMenuCommand('makeMask')
rectClip.rotate(90, undefined, undefined, undefined, undefined, Transformation.CENTER)
... View more
‎Jul 14, 2020
07:39 PM
1 Upvote
You can do an image trace in illustrator. Steps should be easy to find online. It will take your image and convert to vector. Its not perfect, but easy to accomplish what you are looking for.
... View more
‎Jul 14, 2020
02:21 PM
1 Upvote
Silly-V, This thread has already been a game changer. I did not know there was more documentation in ESTK than what the documents hold. What I did not see, is there anyway to change the property? so that I can flip between stroke and fill active states from a script. By the way, dynamic actions thread was a big help. Thank you.
... View more
‎Jul 13, 2020
05:49 PM
That did the trick, thanks. Was able to use another post by Silly-V to write the action from a string to a file, load, run, and unload. Where do you all find some of this stuff? I swear its like the documentation has a secret menu. Like the executeMenuCommand I found a couple of years ago, but still have never seen it in any of the official documentation. Unless I am not looking hard enough.
... View more
‎Jul 12, 2020
06:20 PM
See thread delete-remove-duplicate-paths I am following the steps from the second to last comment from the bottom, from Lizzzzahhh. If I use the Pathfinder palette it works. It is an outlined text that is closed shape, but it is a single line font so the paths and point are directly on top of eachother. After the steps mentioned above, the duplicates are removed. If I use the menu Effect > Pathfinder > Outline and then expand appearance it does not work. I am still left with duplicate 1-to-1 paths and points. If you draw a rectangle and then copy it in front, then select both and use the palette to do Outline does it not removed the second path? I tried this as well and I was left with one rectangle path.
... View more
‎Jul 12, 2020
03:20 PM
Hi All, I have been looking all over to see if I could find anything on jsx script to access the pathfinder tool. I have a script that is adding text in a font that is "single line", really it is a closed compoundpath after outlined. I can use the outline option from the pathfinder tool which deletes the redudant points, but have not found a way to do so from a script. Trying to avoid having the user do this step manually. I have already tried the Live Pathfinder Outline, but this is exectuing the menu command which has a different behavior than the tool. I do note understand why that is but unimportant in this context.
... View more
‎Jul 10, 2020
11:38 AM
I have always used the extension .jsxinc in the include e.g #inlcude layers.jsxinc. I am assuming based of this it is not a requirement?
... View more
‎May 13, 2020
04:48 PM
VS Code has extensions now that let you run and debug extendscript
... View more
‎May 26, 2016
09:47 AM
can you run app.executeMenuCommand('group'); on the selection and then clip the selection?
... View more
‎May 05, 2016
10:25 AM
I want to set stroke color(existing spot swatch) and other attributes like overprint and stroke width to path items on a target layer("DIE") in the active document. What I have already sets what I want to all existing path items on all layers. I have tried ways to index the target layer "DIE" but can not seem to get it to work. if(app.documents.length > 0 && app.activeDocument.pathItems.length > 0) { var doc = app.activeDocument; for (var i = 0; i < doc.pathItems.length; i++){ plotSet = doc.pathItems; plotSet.filled = false; plotSet.stroked = true; plotSet.strokeWidth = 2; plotSet.strokeOverprint = true; plotSet.strokeColor = doc.swatches["PLOT"] .color; } }
... View more
‎Feb 24, 2016
07:32 PM
I currently have a working script and am trying to refine it to be as automated as possible. Currently you have to add some info into prompt boxes to be placed into the active document. The info is all in a JDF file which I believe is similar if not the same as an XML file. The JDF info varies per job and was wondering if there is a way the script can retrieve the info per job. So that in the script will pull all the info and there will be no prompt boxes required. I want the script to just be ran and it does all the work.
... View more