I just recently got into Photoshop scripting with JavaScript and I would like to know if there's a way I could use the variables of an active document across other scripts.
It's my first time asking a question of that nature, I hope I'll make myself understandable

I wrote a script to create a template file and use another script to apply to the active document.
I plan on writing more scripts that will affect that same active document, and although I could just paste the value over all scripts I would like to let people change the template's variable without breaking the other scripts.
Is it possible to create a .jsx file that stores the variables and load it in each script ?
Before showing the full code to run, here's an example of my issue :
I would like to apply the Camera Layer script to the Storyboard template, so the stroke selection just takes the top white space and not the black bar at the bottom.
It does work if I set the selection by manually entering the value in the array of the code snippets below :
Code: Select all
var shapeRef = [
[0,0], [0,h - 284], [w,h - 284], [w,0]
]
docRef.selection.select(shapeRef)
Code: Select all
var shapeRef = [
[0,0], [0,h - bar], [w,h - bar], [w,0]
]
docRef.selection.select(shapeRef)
Somehow it isn't recognized.
This is the template.
Code: Select all
//Storyboard Template
//Unit settings
var originalUnit = preferences.rulerUnits
preferences.rulerUnits = Units.PIXELS
//Setting up global values
width = 1920
heigth = 1364
res = 150
barHeigth = 284 // <-- THIS IS THE GLOBAL VARIABLE I REFER TO IN THE CAMERA SCRIPT
FontSize = 60
//Set canvas size and resolution,
var docRef = app.documents.add(width, heigth, res)
//Folder and Layers creation for the dialog group
var layerSet = docRef.layerSets.add()
layerSet.name = "SQ_00_SH_000_000"
var artLayerDraw = layerSet.artLayers.add()
artLayerDraw.name = "drawing"
var layerSetB = layerSet.layerSets.add()
layerSetB.name = "dialog"
var artLayerBar = layerSetB.artLayers.add()
artLayerBar.name = "dialog_mask"
docRef.activeLayer = artLayerBar
barHeigth = 284
//Set Selection
shapeRef = [
[0, 0],
[0, heigth - barHeigth],
[width, heigth - barHeigth],
[width, 0]
]
docRef.selection.select(shapeRef)
docRef.selection.invert(shapeRef)
//Set Stroke Color
fillColor = new SolidColor()
fillColor.rgb.red = 0
fillColor.rgb.green = 0
fillColor.rgb.blue = 0
app.activeDocument.selection.fill(fillColor, ColorBlendMode.NORMAL, 100, false)
docRef.selection.deselect()
//Create Text layer for dialog
var artLayerRef = layerSetB.artLayers.add()
artLayerRef.kind = LayerKind.TEXT
var textItemRef = artLayerRef.textItem
textItemRef .contents = '""'
textItemRef.size = FontSize
textColor = new SolidColor()
textColor.rgb.red = 255
textColor.rgb.green = 255
textColor.rgb.blue = 255
textItemRef.color = textColor
textItemRef.justification = Justification.CENTER
artLayerRef.textItem.position = Array(width/2, heigth - barHeigth/2)
artLayerRef.positionLocked = true
// Release references
docRef = null
artLayerRef = null
textItemRef = null
// Restore original ruler unit setting
app.preferences.rulerUnits = originalUnit
Here's the script that applies a layer with a stroke selection :
Code: Select all
//Camera Layer
//Set Document
var docRef = activeDocument
var w = app.activeDocument.width
var h = app.activeDocument.height
var bar = app.activeDocument.barHeigth // <-- THIS IS THE VARIABLE FROM THE TEMPLATE I HOPED I COULD USE
//Create Camera layer
var newCamLayer = docRef.artLayers.add()
newCamLayer.name = "CAM"
newCamLayer.move(docRef.layerSets[0], ElementPlacement.INSIDE)
docRef.activeLayer = newCamLayer
//Set Selection
var shapeRef = [
[0,0],
[0,h - bar],
[w,h - bar],
[w,0]
]
docRef.selection.select(shapeRef)
//Set Stroke Color
strokeColor = new SolidColor
strokeColor.rgb.red = 0
strokeColor.rgb.green = 165
strokeColor.rgb.blue = 63
activeDocument.selection.stroke (strokeColor, 10, StrokeLocation.INSIDE, ColorBlendMode.NORMAL, 100, false)
docRef.selection.deselect()
The Caveman.