Created
June 16, 2021 09:41
-
-
Save gentagonal/9043d3aa0b11740db9e294fa3b55f996 to your computer and use it in GitHub Desktop.
A Photoshop TPL (Tool Preset) to ABR (Adobe Brush) conversion script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// README | |
// WARNING: I wrote and tested this w/ Photoshop CS6. No idea if it works w/ newer versions. | |
// | |
// CSP (Clip Studio Paint) can import Photoshop brushes but only .abr files. It can't import .tpl files, which | |
// a lot of concept artists use to share their brushes. So I wrote a script to turn all your currently loaded | |
// tool presets in Photoshop into brushes and append them to your current brush set. If you then hit Save Brushes | |
// it will save as an .abr file that you can import into CSP. | |
// | |
// Before you run this script please make sure to save your current brushset and tool preset, then delete all | |
// of your brushes from the brush menu. The script *APPENDS* brushes, so if you want to save an .abr with ONLY | |
// the ones from the script, you'll want a clean slate. Then, load in the tool presets you want to convert. | |
// | |
// File > Scripts > Browse > Find this script and run it. | |
// Save Brushes > Save it as .abr | |
var ignoredTools = []; // Tool presets that can't be made into brushes. | |
// build action descriptor with a null class reference to the charId's corresponding typeId | |
function buildActionDescriptor(charId) { | |
var nullId = charIDToTypeID( "null" ); | |
var typeId = charIDToTypeID(charId); | |
var ref = new ActionReference(); | |
ref.putClass(typeId); | |
var desc = new ActionDescriptor(); | |
desc.putReference(nullId, ref); | |
return desc | |
} | |
// select tool preset so it's the active tool | |
function selectToolPreset(toolPresetName) { | |
var nullId = charIDToTypeID( "null" ); | |
var selectId = charIDToTypeID( "slct" ); | |
var toolPresetId = stringIDToTypeID( "toolPreset" ); | |
var ref1 = new ActionReference(); | |
// reference to the tool preset w/ the name | |
ref1.putName( toolPresetId, toolPresetName ); | |
// put it into something describing an action | |
var desc1 = new ActionDescriptor(); | |
desc1.putReference( nullId, ref1 ); | |
// select the tool preset in question | |
executeAction( selectId, desc1, DialogModes.NO ); | |
} | |
// create the brush, name it brushName, add it to your current brushset | |
function makeBrushFromCurrentSelectedTool(brushName) { | |
// make id | |
var makeId = charIDToTypeID( "Mk " ); | |
var brushDescriptor = buildActionDescriptor("Brsh"); | |
var nameId = charIDToTypeID( "Nm " ); | |
var idPrpr = charIDToTypeID( "Prpr" ); | |
var idCrnT = charIDToTypeID( "CrnT" ); | |
var ref = new ActionReference(); | |
ref.putProperty( idPrpr, idCrnT ); | |
ref.putEnumerated( | |
charIDToTypeID( "capp" ), | |
charIDToTypeID( "Ordn" ), | |
charIDToTypeID( "Trgt" ) | |
); | |
var usngId = charIDToTypeID( "Usng" ); | |
// making the brush using the current selected tool | |
brushDescriptor.putReference( usngId, ref ); | |
brushDescriptor.putString(nameId, brushName); | |
try { | |
executeAction( makeId, brushDescriptor, DialogModes.NO ); | |
} catch (err) { | |
// sure would be nice if PS had proper error classes and documented error codes :') | |
// alas... | |
if (!err.message.indexOf("The command 'Make' is not currently available")) { | |
throw err; | |
} else { | |
ignoredTools.push(brushName); | |
} | |
} | |
} | |
function iterateOverToolPresets() { | |
var ref = new ActionReference(); | |
ref.putEnumerated( | |
charIDToTypeID( "capp" ), | |
charIDToTypeID( "Ordn" ), | |
charIDToTypeID( "Trgt" ) | |
); | |
var appDesc = executeActionGet(ref); | |
// presetManager refers to the actual Preset Manager you access from the brush window | |
// the index 7 corresponds to Tool Presets in the dropdown of that window. | |
// we are getting the list of names of the tool presets | |
var pmList = appDesc.getList(stringIDToTypeID("presetManager")); | |
var nameList = pmList.getObjectValue(7).getList(charIDToTypeID('Nm ')); | |
for (var index = 0; index < nameList.count; index++){ | |
var toolPresetName = nameList.getString(index); | |
selectToolPreset(toolPresetName); | |
makeBrushFromCurrentSelectedTool(toolPresetName); | |
} | |
} | |
// ======================================================= execution start | |
iterateOverToolPresets(); | |
if (ignoredTools.length > 0) { | |
var ignoredCountToDisplay = 20; | |
var ignoredToDisplay = ignoredTools.slice(0, ignoredCountToDisplay); | |
alertMessage = "These tool presets were ignored because they're not brushes.\n" | |
alertMessage += ignoredToDisplay.join("\n") | |
var truncatedCount = Math.max(ignoredTools.length - ignoredCountToDisplay, 0); | |
if (truncatedCount > 0) { | |
alertMessage += "\n + " + truncatedCount + " more"; | |
} | |
alert(alertMessage); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment