Copy link to clipboard
Copied
Greetings, and health and happiness in the new year! 🙂
I've made solid progress with my script and overcame quite a bit of unexpected (deep down expected of course) complexity. Have a peek!
The swatch maker
Now, what I've been struggling with for a few hours, which humbly warrants my presence here I dare to hope, is that I do have a piece of code that will create the mixed ink swatch. But when I used into a function it stops working. By that I mean, when I start parametrizing the colorants using parameters passed in the function, the code breaks.
Let me show you with a video first:
The exact code, in a blank file, works.
Notice the 'Process Cyan' etc are just straight numbers hard coded in.
Here it is:
// Your settings
// -------------------------------------
var MY_MIX_INKS = {
// Valid ink names are required
// At least 2 process inks are required
'Process Cyan' : 0, // Process1 : %
'Process Magenta' : 0, // Process2 : %
'Process Yellow' : 100, // Custom1 : %
'Gold' : 100 // Custom2 : %
},
MY_MIX_NAME = 'DoubleColor';
// Ink Validator
// -------------------------------------
var validateInkData = function(o, c, ll, pp)
{
var k, t, z=0, r=1;
ll.length = pp.length = 0;
for( k in o )
{
if( !o.hasOwnProperty(k) ) continue;
if( !(t=c.itemByName(k)).isValid ){ r=0; break; }
ll[z] = t.getElements()[0];
pp[z++] = +o[k];
}
return r;
};
// Main Code
// -------------------------------------
var doc = app.activeDocument,
inkList, // will receive validated ink list (array)
inkPerc; // corresponding percentages (array)
if( !doc.mixedInks.itemByName(MY_MIX_NAME).isValid )
{
if( validateInkData(MY_MIX_INKS,
doc.inks, inkList=[], inkPerc=[]) )
{
doc.mixedInks.add(inkList, inkPerc,
{
name: MY_MIX_NAME,
model: ColorModel.MIXEDINKMODEL,
space: ColorSpace.MIXEDINK
});
alert( "The mixed ink '" + MY_MIX_NAME +
"' has been successfully created." );
}
else
{
alert( "Unable to create mixed ink. " +
"Some inner inks are missing." );
}
}
else
{
alert( "The mixed ink '" + MY_MIX_NAME +
"' already exists." );
}
The same code, called from inside a function in my code file, fails at the adding mixed in step.
The only change is that I pass the function's parameters to the 'Process Cyan' etc.
And that breaks it for some reason.
//--------------------------------------------------------------------------------------------------------------------------------------------------------ADD SWATCHES TO THE SWATCHES PANEL ONE BY ONE----------------------------------------------------------------
function addMixedInk(cyan, magenta, yellow, black, specialty, mixedInkName)
{
$.writeln(cyan + " " + magenta+ " " + yellow+ " " + black+ " " + specialty+ " " + mixedInkName);
// Your settings
// -------------------------------------
var MY_MIX_INKS = {
// Valid ink names are required
// At least 2 process inks are required
'Process Cyan' : cyan, // Process1 : %
'Process Magenta' : magenta, // Process2 : %
'Process Yellow' : yellow, // Custom1 : %
'Gold' : specialty // Custom2 : %
},
MY_MIX_NAME = 'DoubleColor';
// Ink Validator
// -------------------------------------
var validateInkData = function(o, c, ll, pp)
{
var k, t, z=0, r=1;
ll.length = pp.length = 0;
for( k in o )
{
if( !o.hasOwnProperty(k) ) continue;
if( !(t=c.itemByName(k)).isValid ){ r=0; break; }
ll[z] = t.getElements()[0];
pp[z++] = +o[k];
}
return r;
};
// Main Code
// -------------------------------------
var doc = app.activeDocument,
inkList, // will receive validated ink list (array)
inkPerc; // corresponding percentages (array)
if( !doc.mixedInks.itemByName(MY_MIX_NAME).isValid )
{
if( validateInkData(MY_MIX_INKS,
doc.inks, inkList=[], inkPerc=[]) )
{
doc.mixedInks.add(inkList, inkPerc,
{
name: MY_MIX_NAME,
model: ColorModel.MIXEDINKMODEL,
space: ColorSpace.MIXEDINK
});
alert( "The mixed ink '" + MY_MIX_NAME +
"' has been successfully created." );
}
else
{
alert( "Unable to create mixed ink. " +
"Some inner inks are missing." );
}
}
else
{
alert( "The mixed ink '" + MY_MIX_NAME +
"' already exists." );
}
switch(selectedSpecialty)
{
case "Silver":
theMixedInk = { 'Process Cyan': cyan, 'Process Magenta' : magenta, 'Process Yellow': yellow, 'Process Black': black, 'Silver' : specialty}, mixedInkName;
break;
case "Gold":
theMixedInk = { 'Process Cyan': cyan, 'Process Magenta': magenta, 'Process Yellow': yellow, 'Process Black': black, 'Gold': specialty}, mixedInkName;
break;
}
}
Any help is greatly appreciated!
I will be sharing the code of course and its been great fun to learn all this.
Thank you for your kindness, and time!!!
Antoine
Hi Antoine,
Looking into your video, I think the problem is obvious: the modal dialog box is preventing the script from continuing.
The script (as well as the user in InDesign) can't change the document while a modal dialog box is open so you have either to close it before continuing or use non-modal dialog box — use "palette" instead of "dialog" — which acts like the "find-change" dialog: the user can interact with the document when it's open.
Note the "Cannot handle the request because a modal d
Copy link to clipboard
Copied
I will be giving away this tool please contribute if you can. Thank you.
Copy link to clipboard
Copied
To be more precise, if change the hard coded numbers for cyan magenta etc. with variables received as parameters in my function, then it doesn't work.
Copy link to clipboard
Copied
Found my answer!!! 🙂
Copy link to clipboard
Copied
And that was?
Only did a quick look at your problem function. Sorry.
Thanks,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Hi Antoine,
Looking into your video, I think the problem is obvious: the modal dialog box is preventing the script from continuing.
The script (as well as the user in InDesign) can't change the document while a modal dialog box is open so you have either to close it before continuing or use non-modal dialog box — use "palette" instead of "dialog" — which acts like the "find-change" dialog: the user can interact with the document when it's open.
Note the "Cannot handle the request because a modal dialog or alert is active" error message at the bottom left corner in ESTK.
I hope it helps!
Regards,
Kasyan
Copy link to clipboard
Copied
Well, I really kicked myself on this one... Yep.
I've worked out the bugs so far thanks to all your help! 🙂
Learned to notice the ExtendScript bottom left status bar error message, learned to used JongWare's library, learned to use a for loop to writeln() all the props/methods of an object. Learned a lot! Still a babe in the woods overall. I've spread my code into distinct files for sanity now. I'm thinking of porting it to CEP once I'm done however not sure it supports docked out standalone palettes? My UI takes a lot of room. Thanks again for your assistance.!
Copy link to clipboard
Copied
If I make a document with a Spot color named Gold, and call your function like this
addMixedInk(20, 20, 0, 0, 100, "My Color")
I get a mixed ink swatch with the parameter values, but the script fails with your switch statement, because the selectedSpecialty parameter hasn‘t been defined.
You also haven’t created the theMixedInk variable anywhere.
switch(selectedSpecialty)
{
case "Silver":
theMixedInk = { 'Process Cyan': cyan, 'Process Magenta' : magenta, 'Process Yellow': yellow, 'Process Black': black, 'Silver' : specialty}, mixedInkName;
break;
case "Gold":
theMixedInk = { 'Process Cyan': cyan, 'Process Magenta': magenta, 'Process Yellow': yellow, 'Process Black': black, 'Gold': specialty}, mixedInkName;
break;
}
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more