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

Change line tool Width programatically?

Contributor ,
Jul 27, 2025 Jul 27, 2025

Hello,
The line width tool can be decreased/increased with [ and ], but unlike the brush size, its value increases just by 1 pixel regardless of the current value. 
I wanted to write a function to decrease/increase depending on the current value just like the brush tool. Although I was able to read the current value, I found no way to change it programmatically.

TOPICS
Actions and scripting
204
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

correct answers 1 Correct answer

Mentor , Jul 27, 2025 Jul 27, 2025
#target photoshop
s2t = stringIDToTypeID;
c2t = charIDToTypeID;

if (currentTool == 'lineTool') {
    //get current tool property from application
    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
    r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));

    // get and save currentToolOptions object from tool property
    var cto = executeActionGet(r).getObjectValue(s2t('currentToolOptions'));

    // get and save LnWd integer from currentToolOptio
...
Translate
Adobe
Mentor ,
Jul 27, 2025 Jul 27, 2025
#target photoshop
s2t = stringIDToTypeID;
c2t = charIDToTypeID;

if (currentTool == 'lineTool') {
    //get current tool property from application
    (r = new ActionReference()).putProperty(s2t('property'), p = s2t('tool'));
    r.putEnumerated(s2t('application'), s2t('ordinal'), s2t('targetEnum'));

    // get and save currentToolOptions object from tool property
    var cto = executeActionGet(r).getObjectValue(s2t('currentToolOptions'));

    // get and save LnWd integer from currentToolOptions
    var lineWidth = cto.getInteger(c2t('LnWd'));

    // put new size to saved currentToolOptions
    cto.putInteger(c2t('LnWd'), lineWidth + 5);

    // describe 'path' to the object with which we will perform actions
    (r = new ActionReference()).putClass(s2t(currentTool));
    (d1 = new ActionDescriptor()).putReference(s2t('target'), r);

    // put  object that we pass along this 'path'
    d1.putObject(s2t('to'), s2t('target'), cto);

    // perform the set command 
    executeAction(s2t('set'), d1, DialogModes.NO);
}

try to understand how it works to achieve better results in the future

** you can read a little about how to explore built-in objects here Action Manager Scripting 

 

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
Contributor ,
Jul 28, 2025 Jul 28, 2025
LATEST

Great! thank you very much. I'm relying mostly on recording actions and exporting their code via xtools or on scriptlistener, but these alone do not provide all the control I'm looking for. I definitely need to read more about built-in objects. thank you for the links

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