Clone strokes detection

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

getInteger

Clone strokes detection

Post by getInteger »

Hi.

I'm a CS4 user.
I have some problem with events.

After every clone tool stroke, i would like to automatically define a new source point for my clone tool.
Is there a way to do this ?

Thanks.

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

Mike Hale

Clone strokes detection

Post by Mike Hale »

I think the problem you are having is there is not an event ID for a clone stroke/click or any other brush based strokes/clicks for that matter.

Without an event ID you can't add an event notifer.

I can't think of any work-around to change the clone source after a stroke.
getInteger

Clone strokes detection

Post by getInteger »



And is it possible to launch a script manually that would set a clone tool point randomly on a named layer from an other document ?
For example i'm working on "doc1" and i want the clone tool point from "layer 2" from "doc2" with random direction and random angle.
If yes, how to have the script works very quickly ?
Mike Hale

Clone strokes detection

Post by Mike Hale »

I think you can only set the clone source to a point in the active document. So the script would need to switch documents back and forth to set the source.

I assume that when you say "random direction and random angle" you mean random brush roundness and random brush angle. If so those can only be set with a script if the brush is a computed brush. That is to say the brush needs to be one of the round brushes. You can't set brush options of a sample brush like one of the splatter brushes.

Here is an example of how to set the clone source to a random point of the activeLayer of the previous document. I will leave it up to you to decide if it's quick enough.
Code: Select allfunction selectDocumentByOffset(offset){
   var desc = new ActionDescriptor();
   var ref = new ActionReference();
   ref.putOffset(charIDToTypeID('Dcmn'), offset);
   desc.putReference(charIDToTypeID('null'), ref);
   executeAction(charIDToTypeID('slct'), desc, DialogModes.NO);
   return app.activeDocument;
};
function setCloneSource(x, y, sourceLayer){// source point in pixel as Intergers, layerName as String(optional)
   var setDesc = new ActionDescriptor();
   var targetRef = new ActionReference();
   targetRef.putProperty(charIDToTypeID('Prpr'), charIDToTypeID('ClnS'));
   targetRef.putEnumerated(charIDToTypeID('capp'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));
   setDesc.putReference(charIDToTypeID('null'), targetRef);
   var imagePointDesc = new ActionDescriptor();
   var imagePointRef = new ActionReference();
   if(undefined == sourceLayer){
      if(app.activeDocument.activeLayer.isBackgroundLayer ){
         imagePointRef.putProperty(charIDToTypeID('Lyr '), charIDToTypeID('Bckg'));
      }else{
         imagePointRef.putName(cTID('Lyr '), app.activeDocument.activeLayer.name );
      }
   }else{
      if(localize('$$$/LayerName/Background=Background') == sourceLayer ){
      imagePointRef.putProperty(charIDToTypeID('Lyr '), charIDToTypeID('Bckg'));
      }else{
         imagePointRef.putName(cTID('Lyr '), sourceLayer );
      }
   }
   imagePointDesc.putReference(charIDToTypeID('Srce'), imagePointRef);
   var pointDesc = new ActionDescriptor();
   pointDesc.putUnitDouble(charIDToTypeID('Hrzn'), charIDToTypeID('#Pxl'), x);
   pointDesc.putUnitDouble(charIDToTypeID('Vrtc'), charIDToTypeID('#Pxl'), y);
   imagePointDesc.putObject(charIDToTypeID('Pstn'), charIDToTypeID('Pnt '), pointDesc);
   setDesc.putObject(charIDToTypeID('T   '), charIDToTypeID('ImgP'), imagePointDesc);
   executeAction(charIDToTypeID('setd'), setDesc, DialogModes.NO);
};
var sourceDoc = selectDocumentByOffset(-1);
var sourceDocWidth = sourceDoc.width.as('px');
var sourceDocHeight = sourceDoc.height.as('px');
var randonXPosition = Math.floor((sourceDocWidth)*Math.random()) + 1;
var randonYPosition = Math.floor((sourceDocHeight )*Math.random()) + 1;
setCloneSource(randonXPosition, randonYPosition);
selectDocumentByOffset(1);
getInteger

Clone strokes detection

Post by getInteger »

The script is faster than i thought
By "random direction and random angle" i mean the clone tool options, the way things are cloned, i'm no more sure about what "invert" checkbox do but i would like the rotate clone source value to be random.
Mike Hale

Clone strokes detection

Post by Mike Hale »

Sorry, I have never been able to set tool options with a script without using presets.
getInteger

Clone strokes detection

Post by getInteger »

So there is no way in your opinion to set the Pattern Stamp Tool texture with a script ?
Mike Hale

Clone strokes detection

Post by Mike Hale »

Not without using a preset which would set all the tool options. With the Pattern Stamp Tool you can't change just the pattern with a preset.
getInteger

Clone strokes detection

Post by getInteger »

Hmmm, that's very annoying

So i have an idea to solve my problem but is it possible to get the current foreground color, and change hue of the document to clone to the picked color, then set a clone tool point from that edited document, then go back to first document with the clone tool ready to paint.

I hope i'm making any sense.
Mike Hale

Clone strokes detection

Post by Mike Hale »

The code I posted already shows it is possible to switch documents, set the clone source, then switch back so that is possible.

You can get the current foreground color with app.foregroundColor, so that is also possible.

I can't say if it's possible to change the hue of a document to match the foreground color as I am not sure how you want to do that. If you want to add a solid fill adjustment layer to the top of the layer stack and set it's color to the foreground color and blend mode to hue, then yes that can be scripted. If you have a different way to change the hue outline the method used and I can give a better answer as to if it can be scripted.