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

Defining & Deleting Colors using VBscript

New Here ,
Mar 05, 2008 Mar 05, 2008
I would like to set several colors and if the color is already defined I want to delete it and re-define it. Below is how I'm defining a color.
Thanks,
Archie

Set Color = Document.Colors.Add
Color.Name = "Green"
Color.Model = idColorModel.idSpot
Color.ColorValue = Array(100,0,100,0)
TOPICS
Scripting
752
Translate
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 ,
Mar 05, 2008 Mar 05, 2008
Hi Archie,

Here's what I do:

On Error Resume Next
Set myColor = myDocument.Colors.Item("Green")
If Err.Number <> 0 Then
Set myColor = myDocument.Colors.Add
Color.Name = "Green"
Color.Model = idColorModel.idSpot
Color.ColorValue = Array(100,0,100,0)
Err.Clear
End If
On Error Goto 0

Thanks,

Ole
Translate
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
New Here ,
Mar 05, 2008 Mar 05, 2008
Hi Ole,
I had already found a piece of code like your example, but I need to delete the color if it's already there and then create it using my values. The deleting part is my problem.
Thanks,
Archie
Translate
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 ,
Mar 05, 2008 Mar 05, 2008
Hi Archie,

Okay, how about this?

On Error Resume Next
Set myColor = myDocument.Colors.Item("Green")
If Err.Number = 0 Then
myColor.Delete
End If
On Error Goto 0

...and then define your new color.

Thanks,

Ole
Translate
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
New Here ,
Mar 05, 2008 Mar 05, 2008
That worked! But it has lead to another question. After the script is used to open a template, created the colors, create a dialog to enter a batch number (also file name), place the text, Save the document I then open it back up, but two of the colors that I defined are not there (LBlue & LGreen) all of the rest are there (Green, Purple, Orange, Red, Blue & Brown). Below is the complete script.
Thanks,
Archie

Rem N12 Script

Rem SCRIPT INFO
Rem -----------

Rem Copyright Mindware Corporation Of America
Rem Author: Archie O Tucker
Rem Created: 03/03/08
Rem Revised:

Dim InDesign
Set InDesign = CreateObject("InDesign.Application.CS3")
Set Dialog = InDesign.Dialogs.Add

Set FileSys = CreateObject("Scripting.FileSystemObject")

Rem SET VALUES
Rem ----------
Dim MountSize
Dim TemplateFolder

MountLetter = "N"
MountSize = "12"
TextFolder = "E:\sxs\pm65\CA\"
TemplateFolder = "E:\SXS\ID\"
BatchFolder = "E:\SXS\ID\"

Rem OPEN TEMPLATE
Rem -------------

Document = InDesign.Open(TemplateFolder+MountLetter+MountSize+".indt", True)
Set Document =InDesign.ActiveDocument

Rem DISPLAY DIALOG
Rem --------------
Dialog.Name = MountLetter + MountSize + " Autobatch "

Set DialogColumn = Dialog.DialogColumns.Add
set BorderPanel = DialogColumn.BorderPanels.Add
set SubDialogColumn = BorderPanel.DialogColumns.Add
Set BatchNumberLabel = SubDialogColumn.StaticTexts.Add
BatchNumberLabel.StaticLabel = "Batch Number: "
Set SubDialogColumn = BorderPanel.DialogColumns.Add
Set BatchNumberField = SubDialogColumn.TextEditboxes.Add
BatchNumberField.EditContents = "65926C"
BatchNumberField.MinWidth = 100
REM LINE:41
Result = Dialog.Show

If Result = True Then
BatchNumber = BatchNumberField.EditContents
DefineColor
PlaceText
SaveBatch
CloseTemplate
Dialog.Destroy
Else
Dialog.Destroy
CloseTemplate
End If

Rem PLACE TEXT FUNCTION
Rem -------------------
Function PlaceText
Set TextFrames = Document.TextFrames
Set FirstFrame = TextFrames.Item(1)
FirstFrame.Place (TextFolder + MountSize + "_" + BatchNumber + ".TXT")

MsgBox "Ok:"

End Function

Rem SAVE BATCH FUNCTION
Rem -------------------
Function SaveBatch

InDesign.ActiveDocument.Save BatchFolder + BatchNumber + ".indd"

End Function

Rem CLOSE TEMPLATE FUNCTION
Rem -----------------------
Function CloseTemplate

InDesign.ActiveDocument.Close

End Function

Rem DEFINE COLOR
Rem ------------
Function DefineColor

On Error Resume Next

Set Color = Document.Colors.Item("Green")
If Error.Number = 0 Then
Color.Delete
End If
Error.Clear
Set Color = Document.Colors.Add
Color.Name = "Green"
Color.Model = idColorModel.idSpot
Color.ColorValue = Array(100,0,100,0)

Set Color = Document.Colors.Item("Purple")
If Error.Number = 0 Then
Set Color = Document.Colors.Delete
End If
Error.Clear
Set Color = Document.Colors.Add
Color.Name = "Purple"
Color.Model = idColorModel.idSpot
Color.ColorValue = Array(60,100,0,0)

Set Color = Document.Colors.Item("Orange")
If Error.Number = 0 Then
Color.Delete
End If
Error.Clear
Set Color = Document.Colors.Add
Color.Name = "Orange"
Color.Model = idColorModel.idSpot
Color.ColorValue = Array(0,50,100,0)

Set Color = Document.Colors.Item("Red")
If Error.Number = 0 Then
Color.Delete
End If
Error.Clear
Set Color = Document.Colors.Add
Color.Name = "Red"
Color.Model = idColorModel.idSpot
Color.ColorValue = Array(0,100,100,0)


Set Color = Document.Colors.Item("Blue")
If Error.Number = 0 Then
Color.Delete
End If
Error.Clear
Set Color = Document.Colors.Add
Color.Name = "Blue"
Color.Model = idColorModel.idSpot
Color.ColorValue = Array(100,100,0,0)

Set Color = Document.Colors.Item("LBlue")
If Error.Number = 0 Then
Color.Delete
End If
Error.Clear
Set Color = Document.Colors.Add
Color.Name = "LBlue"
Color.Model = idColorModel.idSpot
Color.ColorValue = Array(76,9,0,0)

Set Color = Document.Colors.Item("LGreen")
If Error.Number = 0 Then
Color.Delete
End If
Error.Clear
Set Color = Document.Colors.Add
Color.Name = "LGreen"
Color.Model = idColorModel.idSpot
Color.ColorValue = Array(60,0,79,0)

Set Color = Document.Colors.Item("Brown")
If Error.Number = 0 Then
Color.Delete
End If
Error.Clear
Set Color = Document.Colors.Add
Color.Name = "Brown"
Color.Model = idColorModel.idSpot
Color.ColorValue = Array(68,70,88,0)

End Function
Translate
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 ,
Mar 05, 2008 Mar 05, 2008
Hi Archie,

A couple of things:

You need to pass object references in to the functions to get them to work reliably.

You might want to name your variables something other than the class names--just to avoid confusion.

Try something like this:

Rem N12 Script

Rem SCRIPT INFO
Rem -----------

Rem Copyright Mindware Corporation Of America
Rem Author: Archie O Tucker
Rem Created: 03/03/08
Rem Revised:

Dim myInDesign
Set myInDesign = CreateObject("InDesign.Application.CS3")
Set myDialog = myInDesign.Dialogs.Add

Set FileSys = CreateObject("Scripting.FileSystemObject")

Rem SET VALUES
Rem ----------

MountLetter = "N"
MountSize = "12"
TextFolder = "E:\sxs\pm65\CA\"
TemplateFolder = "E:\SXS\ID\"
BatchFolder = "E:\SXS\ID\"

Rem OPEN TEMPLATE
Rem -------------

Set myDocument = myInDesign.Open(TemplateFolder+MountLetter+MountSize+".indt", True)

Rem DISPLAY DIALOG
Rem --------------
myDialog.Name = MountLetter + MountSize + " Autobatch "

Set myDialogColumn = myDialog.DialogColumns.Add
Set myBorderPanel = myDialogColumn.BorderPanels.Add
Set mySubDialogColumn = myBorderPanel.DialogColumns.Add
Set myBatchNumberLabel = mySubDialogColumn.StaticTexts.Add
myBatchNumberLabel.StaticLabel = "Batch Number: "
Set mySubDialogColumn = myBorderPanel.DialogColumns.Add
Set myBatchNumberField = mySubDialogColumn.TextEditboxes.Add
myBatchNumberField.EditContents = "65926C"
myBatchNumberField.MinWidth = 100
Rem LINE:41
myResult = myDialog.Show

If myResult = True Then
myBatchNumber = myBatchNumberField.EditContents
myDefineColor myDocument
myPlaceText myDocument, myTextFolder, myMountSize, myBatchNumber
mySaveBatch myInDesign, myBatchFolder, myBatchNumber
myCloseTemplate myInDesign
myDialog.Destroy
Else
myDialog.Destroy
myCloseTemplate myInDesign
End If

Rem PLACE TEXT FUNCTION
Rem -------------------
Function myPlaceText(myDocument, myTextFolder, myMountSize, myBatchNumber)
Set myTextFrames = myDocument.TextFrames
Set myFirstFrame = myTextFrames.Item(1)
myFirstFrame.Place (TextFolder + MountSize + "_" + BatchNumber + ".TXT")
MsgBox "Ok:"
End Function
Rem SAVE BATCH FUNCTION
Rem -------------------
Function mySaveBatch(myInDesign, myBatchFolder, myBatchNumber)
myInDesign.ActiveDocument.Save BatchFolder + BatchNumber + ".indd"
End Function
Rem CLOSE TEMPLATE FUNCTION
Rem -----------------------
Function myCloseTemplate(myInDesign)
myInDesign.ActiveDocument.Close
End Function
Rem DEFINE COLORS
Rem ------------
Function myDefineColors(myDocument)
myDefineColor myDocument, "Green", idColorModel.idSpot, Array(100, 0, 100, 0)
myDefineColor myDocument, "Purple", idColorModel.idSpot, Array(60, 100, 0, 0)
myDefineColor myDocument, "Orange", idColorModel.idSpot, Array(0, 50, 100, 0)
myDefineColor myDocument, "Red", idColorModel.idSpot, Array(0, 100, 100, 0)
myDefineColor myDocument, "Blue", idColorModel.idSpot, Array(100, 100, 0, 0)
myDefineColor myDocument, "LBlue", idColorModel.idSpot, Array(76, 9, 0, 0)
myDefineColor myDocument, "LGreen", idColorModel.idSpot, Array(60, 0, 79, 0)
myDefineColor myDocument, "Brown", idColorModel.idSpot, Array(68, 70, 88, 0)
End Function
Rem DEFINE COLOR
Rem ------------
Function myDefineColor(myDocument, myColorName, myColorModel, myColorValue)
On Error Resume Next
Set myColor = myDocument.Colors.Item(myColorName)
If Error.Number > 0 Then
Set myColor = myDocument.Colors.Add
myColor.Name = myColorName
Error.Clear
End If
On Error GoTo 0
myColor.Model = myColorModel
myColor.ColorValue = myColorValue
End Function

Thanks,

Ole
Translate
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
New Here ,
Mar 05, 2008 Mar 05, 2008
LATEST
Hi Ole,

Thank you for your help, I now have that part working. I think I recognize your name from a seminar I went to a very long time ago concerning Aldus PageMaker. I think it was in Seattle. I have been using PageMaker's tagged text and scripting for awhile and now I'm working on moving customers to InDesign.

Thanks,
Archie
Translate
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