Script to rotate Items according to a name
Hey guys,
I got two docs with the same items. The only difference is, that some of the items in file B got a different ending of their names. File A File B

Left: File A, Right: File B
If an Item in File B got a number after underscore, the item in File A (that shares the same name before the underscore) should rotate for that exact amount.
E.g. piece "02_" in File A should rotate for 96 degrees , piece "05_" for 180 degrees.
My solution looks like this, but it´s not working.
function main()
{
var ADoc= app.activeDocument;
var BDoc = app.activeDocument[1];
for(var i=0; i<ADoc.pageItems.length; i++);
{
var AItems = ADoc.pageItems[i];
var AItems_name = AItems.name.split('_')[0];
// Part of the PageItems name before the underscore
for (var k=0; k<BDoc.pageItems.length; k++)
{
var BItems = BDoc.pageItems[k];
if(BItems.name.IndexOf(AItems_name) != -1);
// Checks if a pageItem from BDoc got the name of a pageItem from ADoc inside its name
{
var angle = BItems.name.split('_')[1];
AItems.rotate(angle);
}
}
}
}
main();If anybody got a solution and could explain me why my code doesn´t work I would really really appreciate it 🙂 🙂
Furthermore I tried to "import" a swatch from File B to File A. I used a script I found in another thread but it´s not working.
#target Illustrator
var docRef = app.activeDocument[0];
var docRef1 = app.activeDocument[1];
// Get specific swatch
var Designcolor = docRef1.swatches.getByName('Fading Sky');
// Add Swatch to Original Document
var AddColor = docRef.swatches.add();
AddColor.name = Designcolor.name;
AddColor.color = Designcolor.colorWhile debugging it says for line var Designcolor = docRef1.swatches.getByName('Fading Sky') "undefined is not an object". Again an explanation why the code is not working would come in very helpful!
Thanks in advance for any help guys!!! 🙂
