Skip to main content
Simon Henke
Known Participant
June 14, 2019
Question

Photoshop Scripting way slower than native Photoshop functionality

  • June 14, 2019
  • 1 reply
  • 1254 views

Hi everyone,

I'm currently working on a photoshop extension for more customizable grid layouts.

I noticed, that small operations like adding a guide line take quite long to execute.
However, when you use photoshops "create new guide layout"-function, all the guides (even if you add like 100+ columns) are displayed immediately, without any delay.

My code looks something like that:

function createGrid() {

  resetGuides()

  var guidePos = 0

  for(var i = 1; i<= columns; i++) {

     guidePos += columnStep*i

     createGuideLine('Vrtc', guidePos)

  }

}

function resetGuides() {

  var idclearAllGuides = stringIDToTypeID( "clearAllGuides" )

  executeAction( idclearAllGuides, undefined, DialogModes.NO )

}

function createGuideLine(orientation, pixelposition) {

  var idMk = charIDToTypeID( "Mk  " )

  var desc37 = new ActionDescriptor()

  var idNw = charIDToTypeID( "Nw  " )

  var desc38 = new ActionDescriptor()

  var idPstn = charIDToTypeID( "Pstn" )

  var idPxl = charIDToTypeID( "#Pxl" )

  desc38.putUnitDouble( idPstn, idPxl, pixelposition )

  var idOrnt = charIDToTypeID( "Ornt" )

  var idOrnt = charIDToTypeID( "Ornt" )

  var idOr = charIDToTypeID( orientation )

  desc38.putEnumerated( idOrnt, idOrnt, idOr )

  var idGd = charIDToTypeID( "Gd  " )

  desc37.putObject( idNw, idGd, desc38 )

  executeAction( idMk, desc37, DialogModes.NO )

}

I've read that ActionDescriptor Code is faster than DOM operations (which would be app.guides.add(...)), but I'm already using those where possible and it's still increasingly slow the more guides are being added.

Also, I'm already using the SuspendHistory function.

Do you have any idea how to get a more instant rendering of the guides? Maybe clearing all guides and drawing them in a loop isn't the right way. Should I always keep track of the existing guides and just move them around? I don't feel like this would improve it, since photoshops "guide layout" feature can display many new guides in a milisecond..

This topic has been closed for replies.

1 reply

JJMack
Community Expert
Community Expert
June 14, 2019

There are always more than one may to do thing in Photoshop you using the slow way to create guide layout one guide at a time and comparing it to it to Photoshop feature new guide layout.  The time to walk to town compared to the time to ride to town. You Comparing two methods.

newGuideLayout(true, 20, 10, 20, 20, 20, 20);

function newGuideLayout(replace, colCount, colGutter, marginTop, marginLeft, marginBottom, marginRight) {

var descriptor = new ActionDescriptor();

var descriptor2 = new ActionDescriptor();

descriptor.putBoolean( stringIDToTypeID( "replace" ), replace );

descriptor.putEnumerated( stringIDToTypeID( "presetKind" ), stringIDToTypeID( "presetKindType" ), stringIDToTypeID( "presetKindCustom" ));

descriptor2.putInteger( stringIDToTypeID( "colCount" ), colCount );

descriptor2.putUnitDouble( stringIDToTypeID( "colGutter" ), stringIDToTypeID( "pixelsUnit" ), colGutter );

descriptor2.putUnitDouble( stringIDToTypeID( "marginTop" ), stringIDToTypeID( "pixelsUnit" ), marginTop );

descriptor2.putUnitDouble( stringIDToTypeID( "marginLeft" ), stringIDToTypeID( "pixelsUnit" ), marginLeft );

descriptor2.putUnitDouble( stringIDToTypeID( "marginBottom" ), stringIDToTypeID( "pixelsUnit" ), marginBottom );

descriptor2.putUnitDouble( stringIDToTypeID( "marginRight" ), stringIDToTypeID( "pixelsUnit" ), marginRight );

descriptor.putObject( stringIDToTypeID( "guideLayout" ), stringIDToTypeID( "guideLayout" ), descriptor2 );

descriptor.putEnumerated( stringIDToTypeID( "guideTarget" ), stringIDToTypeID( "guideTarget" ), stringIDToTypeID( "guideTargetCanvas" ));

executeAction( stringIDToTypeID( "newGuideLayout" ), descriptor, DialogModes.NO );

}

JJMack
Simon Henke
Known Participant
June 14, 2019

Thanks for your quick reply JJMack.

The problem is that I want to make a more customizable grid creator. Currently I can also specify the weight of a column,

for example 4x 2x 1x 1x in a 4 column layout, which would look like this:

|--------|----|--|--|

Photoshop's guide layout creator always creates equal size columns, so I guess I can't use that function..

edit:

Here's an example of the current state of the extension:

The fact that photoshop doesn't have these customization features is the reason I'm developing this extension after all..

So I was wondering HOW photoshop places the guides internally when using the guide layout feature.

Maybe they have some function like placeGuidesAt(positions: Array, orientation: Direction) or something similar to place many guides at once.

JJMack
Community Expert
Community Expert
June 14, 2019

Yes I understand that. You are still trying to compare two different methods the one guide at a time method to a Plug-in all guides at once method for creating for a custom layout. That Plugin will likely never be written for creating a usable UI for it may not be possible.  Layouts that can be calculated with simple Math can be with new Guide layout.

You would need to write the Plugin to that would create the layout in one shot from your UI.

JJMack