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

Looking for guidence on JavaScript to add spot colours to a new colour group in InDesign

Explorer ,
Jan 07, 2020 Jan 07, 2020

Copy link to clipboard

Copied

Hi, its as it says in the subject.

I can create the colours, and i can create the colour groups, but I can't move the new colours into the colour groups.

 

I'm still new to this, so I might be going about it the wrong way.

 

Here is my code.

 

//Add Zund Spot Colours to swatch document
myDoc.colors.add({colorValue: [94,76,5,0], name: "Thru-cut", model:ColorModel.SPOT, id:947650, parentColorGroup: "Zund Spot Colours"});
myDoc.colors.add({colorValue: [97,6,93,0], name: "Crease", model:ColorModel.SPOT, id:976930, parentColorGroup: "Zund Spot Colours"});
myDoc.colors.add({colorValue: [2,89,82,0], name: "Kiss-cut", model:ColorModel.SPOT, id:289820, parentColorGroup: "Zund Spot Colours"});
myDoc.colors.add({colorValue: [73,67,64,74], name: "Register", model:ColorModel.SPOT, id:73676474, parentColorGroup: "Zund Spot Colours"});
myDoc.colors.add({colorValue: [60,26,0,0], name: "Punch", model:ColorModel.SPOT, id:602600, parentColorGroup: "Zund Spot Colours"});
myDoc.colors.add({colorValue: [24,91,81,16], name: "Score", model:ColorModel.SPOT, id:24918116, parentColorGroup: "Zund Spot Colours"});
myDoc.colors.add({colorValue: [56,40,86,21], name: "V-cut", model:ColorModel.SPOT, id:56408621, parentColorGroup: "Zund Spot Colours"});

//Add these colours to the "Zund Spot Colours" colorGroup
myDoc.colorGroups.add("Zund Spot Colours",["Thru-cut", "Crease", "Kiss-cut", "Register", "Punch", "Score", "V-cut"]);

//Add Litho Specialty Spots to document
myDoc.colors.add({colorValue: [0,100,100,0], name: "NUMBERING", model:ColorModel.SPOT, id:01001000, parentColorGroup: "Litho Specialty Spot Colours"});
myDoc.colors.add({colorValue: [100,0,0,0], name: "SPOTVARNISH", model:ColorModel.SPOT, id:100000, parentColorGroup: "Litho Specialty Spot Colours"});
myDoc.colors.add({colorValue: [100,0,100,0], name: "FOILING", model:ColorModel.SPOT, id:10001000, parentColorGroup: "Litho Specialty Spot Colours"});
myDoc.colors.add({colorValue: [0,28,100,0], name: "SPOTLATEX", model:ColorModel.SPOT, id:0281000, parentColorGroup: "Litho Specialty Spot Colours"});
myDoc.colors.add({colorValue: [97,0,41,0], name: "SPECIALVARNISH", model:ColorModel.SPOT, id:970410, parentColorGroup: "Litho Specialty Spot Colours"});
myDoc.colors.add({colorValue: [0,64,100,0], name: "SCORING", model:ColorModel.SPOT, id:0641000, parentColorGroup: "Litho Specialty Spot Colours"});
myDoc.colors.add({colorValue: [40,0,100,0], name: "EMBOSSDEBOSS", model:ColorModel.SPOT, id:4001000, parentColorGroup: "Litho Specialty Spot Colours"});
myDoc.colors.add({colorValue: [34,65,100,19], name: "FOLDING", model:ColorModel.SPOT, id:346510019, parentColorGroup: "Litho Specialty Spot Colours"});
myDoc.colors.add({colorValue: [100,66,0,0], name: "DIECUT", model:ColorModel.SPOT, id:1006600, parentColorGroup: "Litho Specialty Spot Colours"});

//Add these colours to the "Litho Specialty Colours" colorGroup
myDoc.colorGroups.add("Litho Specialty Spot Colours",["NUMBERING", "SPOTVARNISH", "FOILING", "SPOTLATEX", "SPECIALVARNISH", "SCORING", "EMBOSSDEBOSS", "FOLDING", "DIECUT"]);

TOPICS
Publish online , Scripting , SDK

Views

480

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

Contributor , Feb 05, 2024 Feb 05, 2024

Thanks for this, I was able to modify your code for my simpler case to run without problems

graphicTemplate.colorGroups.add
(
"Cut Contour Colors",
     [
graphicTemplate.colors.add
	({
colorValue: [0,100,0,0], 
name: "CutContourMagenta", 
model:ColorModel.SPOT, 
id:01001000, 
parentColorGroup: "Cut Contour Colors"
	})
     ]
);

this was the result in InDesign

1.jpg

Votes

Translate

Translate
Community Expert ,
Jan 07, 2020 Jan 07, 2020

Copy link to clipboard

Copied

Hi,

the following should work ( tested with InDesign 2020 on Windows )

 

 

var doc = app.documents[0];

var spotColor = doc.colors.itemByName("MySpotColorName");
var colorGroup = doc.colorGroups.itemByName("MyColorGroupName");

colorGroup.colorGroupSwatches.add( spotColor );

 

 

Did not try to add colors while adding a new color group.

Best first add the group, then add the colors with method add() of colorGroup.colorGroupSwatches.

 

Regards,
Uwe Laubender

( ACP )

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 ,
Jan 07, 2020 Jan 07, 2020

Copy link to clipboard

Copied

Also see DOM documentationc ompiled by Gregor Fellenz:

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#about.html

 

colorGroupSwatches.add() method:

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#ColorGroupSwatches.html#d1e71466__d1e7151...

 

Regards,
Uwe Laubender

( ACP )

 

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 ,
Jan 07, 2020 Jan 07, 2020

Copy link to clipboard

Copied

Hi Uwe,

"colorGroupSwatches.add()" didn't work for me for some reason, InDesign kept saying it was undefined.

 

Eventually what worked for me was this.

myDoc.colorGroups.add("Litho Specialty Spot Colours",[myDoc.colors.add({colorValue: [0,100,100,0], name: "NUMBERING", model:ColorModel.SPOT, id:01001000, parentColorGroup: "Litho Specialty Spot Colours"}), myDoc.colors.add({colorValue: [100,0,0,0], name: "SPOTVARNISH", model:ColorModel.SPOT, id:100000, parentColorGroup: "Litho Specialty Spot Colours"}), myDoc.colors.add({colorValue: [100,0,100,0], name: "FOILING", model:ColorModel.SPOT, id:10001000, parentColorGroup: "Litho Specialty Spot Colours"}), myDoc.colors.add({colorValue: [0,28,100,0], name: "SPOTLATEX", model:ColorModel.SPOT, id:0281000, parentColorGroup: "Litho Specialty Spot Colours"}), myDoc.colors.add({colorValue: [97,0,41,0], name: "SPECIALVARNISH", model:ColorModel.SPOT, id:970410, parentColorGroup: "Litho Specialty Spot Colours"}), myDoc.colors.add({colorValue: [0,64,100,0], name: "SCORING", model:ColorModel.SPOT, id:0641000, parentColorGroup: "Litho Specialty Spot Colours"}), myDoc.colors.add({colorValue: [40,0,100,0], name: "EMBOSSDEBOSS", model:ColorModel.SPOT, id:4001000, parentColorGroup: "Litho Specialty Spot Colours"}), myDoc.colors.add({colorValue: [34,65,100,19], name: "FOLDING", model:ColorModel.SPOT, id:346510019, parentColorGroup: "Litho Specialty Spot Colours"}), myDoc.colors.add({colorValue: [100,66,0,0], name: "DIECUT", model:ColorModel.SPOT, id:1006600, parentColorGroup: "Litho Specialty Spot Colours"})]);

 

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
Contributor ,
Feb 05, 2024 Feb 05, 2024

Copy link to clipboard

Copied

LATEST

Thanks for this, I was able to modify your code for my simpler case to run without problems

graphicTemplate.colorGroups.add
(
"Cut Contour Colors",
     [
graphicTemplate.colors.add
	({
colorValue: [0,100,0,0], 
name: "CutContourMagenta", 
model:ColorModel.SPOT, 
id:01001000, 
parentColorGroup: "Cut Contour Colors"
	})
     ]
);

this was the result in InDesign

1.jpg

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