Article View: adobe.scripting.indesign
Article #17670Re: Make a new spot color (VB)
From: Olav Kvern
Date: Thu, 22 May 2003 06:44
Date: Thu, 22 May 2003 06:44
63 lines
3914 bytes
3914 bytes
maxdunn--
Ah, I see. Well, we can't open the color libraries via scripting, nor can we import colors. That said, there are two approaches you can take:
1. Make a spot color as shown above. Give it the CMYK values and color name of the PANTONE spot you want to use, and set its Model to idSpotColor. There's nothing magical about the spot color definitions in the library--all that's required is that your commercial printer knows that a specific plate gets smeared with the correct ink formulation.
2. The color libraries are Illustrator files, and are, therefore, plain text. You can have your script open and read the text files directly, extract the color values you want, and add the color to your document.
Here's an example of the second approach. This example uses the FileSystemObject, so you'll need to add the Microsoft Scripting Runtime library to your VB project.
Rem Get a color from a color library
Dim myInDesign As InDesign.Application
Dim myFileSystemObject As FileSystemObject
Dim myColorLibraryFile As TextStream
Dim myColor As InDesign.Color
Dim myColorLibraryFileName As String
Dim myColorName As String
Dim myColorList As String
Dim myColorDefinition As String
Dim myLineStart As Long
Dim myLineEnd As Long
Dim myColorArray() As String
Rem Enter the file path for the color library you want to open.
myColorLibraryFileName = "C:\Program Files\Adobe\InDesign 2.0\Swatch Libraries\PANTONE Solid Coated.ai"
Rem Enter the name of the color you're looking for.
myColorName = "PANTONE 274 C"
Set myFileSystemObject = CreateObject("Scripting.FileSystemObject")
Set myColorLibraryFile = myFileSystemObject.OpenTextFile(myColorLibraryFileName)
myColorList = myColorLibraryFile.ReadAll
Rem Various string manipulations to extract the color
Rem definition from the (very large) string.
myColorLocation = InStr(1, myColorList, myColorName)
myLineEnd = InStr(myColorLocation, myColorList, vbCr)
myLineStart = InStrRev(myColorList, "%%", myLineEnd)
myColorDefinition = Mid(myColorList, myLineStart, myLineEnd - myLineStart)
myColorList = ""
Rem At this point, we have a string that looks like this:
Rem %%+1.00 1.00 0.00 0.28 (PANTONE 274 C)
Rem More string manipulations follow.
myColorDefinition = Replace(myColorDefinition, "%%+", "")
myColorDefinition = Replace(myColorDefinition, " (" & myColorName & ")", "")
myColorArray = Split(myColorDefinition, " ")
Rem Our work here is done--we've got the color values we want.
Set myInDesign = CreateObject("InDesign.Application.2.0")
Set myDocument = myInDesign.ActiveDocument
Set myColor = myDocument.Colors.Add
myColor.Name = myColorName
Rem Model determines process/spot
myColor.Model = idSpotColor
Rem Color model can be cmyk, rgb, or lab
myColor.Space = idCMYKcolor
myColor.ColorValue = Array(CDbl(myColorArray(0)) * 100, CDbl(myColorArray(1)) * 100, CDbl(myColorArray(2)) * 100, CDbl(myColorArray(3)) * 100)
Note that you could get multiple colors using similar techniques. I really hate loading that large a string into a buffer, but it works reasonably quickly.
Thanks,
Ole
Technical Details
Message-ID:
<1de93764.2@WebX.la2eafNXanI>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebXReferences:
<1de93764.-1@WebX.la2eafNXanI>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f939a,2f07cdb4df521c03 X-Google-Attributes: gidf939a,public X-Google-ArrivalTime: 2003-05-22 00:08:07 PST From: "Olav Kvern" <okvern@adobe.com> Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!eusc.inter.net!newsfeed01.sul.t-online.de!t-online.de!WebX Newsgroups: adobe.scripting.indesign Subject: Re: Make a new spot color (VB) Message-ID: <1de93764.2@WebX.la2eafNXanI> Date: Wed, 21 May 2003 23:44:39 -0700 References: <1de93764.-1@WebX.la2eafNXanI> Lines: 75 MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit