Simulate Click with Brush

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

Grrr1337
Posts: 8
Joined: Fri Nov 01, 2019 3:40 pm

Re: Simulate Click with Brush

Post by Grrr1337 »

Kukurykus wrote: Sun Jan 03, 2021 12:55 pm That has nothing to do with Smart Object, you simply have not unchecked 'Always Create Smart Objects When Placing' in General Preferences.

You can keep Smart Objects though if later you want to relink them to other .pngs, or simply replace embedded content.

All smart objects will refresh at once only when first they all were linked to same file, so are duplicates of each other.
Yes, that was the case and this is the behaviour what I'm after (I just didn't knew how to do it).
I've incorporated these functions to your code, so now all the imported/generated layers are smart objects linked to the corresponding image.

Code: Select all

// Edit->Preferences->General->[?] Always create smart objects when placing
// Use [Ctrl+K] to get to the preferences menu
function placeRasterSmartObjectPreference(bool)
{
  cTID = function(s) { return app.charIDToTypeID(s); };
  sTID = function(s) { return app.stringIDToTypeID(s); };
  var desc1 = new ActionDescriptor();
  var ref1 = new ActionReference();
  ref1.putProperty(cTID('Prpr'), cTID('GnrP'));
  ref1.putEnumerated(cTID('capp'), cTID('Ordn'), cTID('Trgt'));
  desc1.putReference(cTID('null'), ref1);
  var desc2 = new ActionDescriptor();
  desc2.putBoolean(sTID("placeRasterSmartObject"), bool);
  desc1.putObject(cTID('T   '), cTID('GnrP'), desc2);
  executeAction(cTID('setd'), desc1, DialogModes.NO);
}; // function placeRasterSmartObjectPreference



// Relink to File
// run with: placeRasterSmartObjectPreference(true);
function AcLyrRelinkToFile(fpath)
{
  if (app.activeDocument.activeLayer.kind != LayerKind.SMARTOBJECT) return;
  cTID = function(s) { return app.charIDToTypeID(s); };
  sTID = function(s) { return app.stringIDToTypeID(s); };
  var des = new ActionDescriptor();
  des.putPath(cTID('null'), new File(fpath));
  executeAction(sTID('placedLayerRelinkToFile'), des, DialogModes.NO);
}; // function AcLyrRelinkToFile
Kukurykus wrote: Sun Jan 03, 2021 12:55 pm There is event for brush clicking, but it's hidden as it generates too many lines of code.

There is workaround for it though, but better use placing method ;)
Was just curious about it, looks like theres a workaround for everything. :)

By 'placing method' I understand the technique you used in your code?
How is that done manually and how would look with using DOM?
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Simulate Click with Brush

Post by Kukurykus »

Placing you find in File menu, by DOM you won't do it like many other commands avialable only from AM, the simpler, but slower DOM comes from.
Grrr1337
Posts: 8
Joined: Fri Nov 01, 2019 3:40 pm

Re: Simulate Click with Brush

Post by Grrr1337 »

I see that I have alot to explore,
Thanks Kukurykus your help means alot to me! :D
AnilTejwani
Posts: 20
Joined: Wed Feb 22, 2017 5:37 pm
Location: Paraguay

Re: Simulate Click with Brush

Post by AnilTejwani »

Hi,
This post has been really helpful but i was wondering if it would be possible to create real brush clicks, instead of using external images as smartobjects.

My case is I have a custom brush-shape and I want to use it as a single click at a specific position on the image.
// clickBrush(100,200); //100 px right from topleft, 200 px down from topleft

I have been looking over the net and as rightly said there is no code for 'brush click', its not possible to record it in 'actions panel' and even 'scriptlistner' doesnt record it.

If anyone can help or point in the right direction, that would be great.

Thanks in advance.
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Simulate Click with Brush

Post by Kukurykus »

You answered your own question and the solution to this topic shows there's only tricky workaround, like one presented.

According to my free time and complexity of the problem I would solve what you want but that would cost you money ;)