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

How to debug properly?

Community Beginner ,
Nov 11, 2017 Nov 11, 2017

Copy link to clipboard

Copied

I have just started with photoshop scripting in CC 2015 and it's really bothering me that I cannot properly debug my scripts. For example photoshop returns an array/object and I want to look what's inside this array/object - how am I supposed to do that?! In photoshop itself I just have the alert command that isn't showing contents of arrays/objects. The extrendedScript Toolkit CS6 is the same. When I select photoshop at the target software dropdown the script runs in photoshop, so no debug infos in the toolkit. When I select the toolkit it throws errors because it doesn't know any photoshop functions.
Am I missing something or doing something wrong?

TOPICS
Actions and scripting

Views

5.5K

Translate

Translate

Report

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

Community Expert , Nov 12, 2017 Nov 12, 2017

Davide had some neat ideas on looking into object. I learned something. So taking what he said and looking up the info in the Javascript tool Kit. I used their example for reflect. Neat feature! By the way, sometimes it's easier and less typing to assign variables to things like app.activeDocument, activeLayers, and the actual textItems, I changed your script a bit. Try it now.

#target photoshop

var doc = app.documents.add(500, 500, 72, "foobar", NewDocumentMode.RGB); 

 

var days = doc.artLayers.a

...

Votes

Translate

Translate
Adobe
Community Expert ,
Nov 11, 2017 Nov 11, 2017

Copy link to clipboard

Copied

I'm not up on all the debugging capabilities of ESTK, but it should normally show what's in an array. with either alert() or $.writeln(). Have you tried adding .toString() when you want to look at the array?

Votes

Translate

Translate

Report

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
Engaged ,
Nov 11, 2017 Nov 11, 2017

Copy link to clipboard

Copied

ESTK has the standard set of debugging utils – you can set breakpoints, step in/over/out, you have a Data Browser panel, etc. More info in the Javascript Tools Guide pdf.

You can always log stuff on the console with $.writeln(), if you want; also ExtendScript has a peculiar .toSource() method that you may want to use:

var obj = {

   a: 1,

   b: false,

   c: [9, 19,29]

}

$.writeln(obj)

// [object Object]

$.writeln(obj.toSource())

// ({a:1, b:false, c:[9, 19, 29]})

Also, the Reflection interface is quite useful – see the above-mentioned pdf on page 211.

Davide

Davide Barranca - PS developer and author
www.ps-scripting.com

Votes

Translate

Translate

Report

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
Community Beginner ,
Nov 12, 2017 Nov 12, 2017

Copy link to clipboard

Copied

Hm, maybe I have to be a bit more specific because of my current issue.

I have this code

doc = app.documents.add(500, 500, 72, "foobar", NewDocumentMode.RGB);

days = doc.artLayers.add()

days.kind = LayerKind.TEXT;

days.name = "test";

days.textItem.size = 14;

days.textItem.position = new Array(0, 0);

days.textItem.contents = '01';

activeDocument.activeLayer = activeDocument.artLayers.getByName("test");

$.writeIn(activeDocument.activeLayer.textItem);

alert(activeDocument.activeLayer.textItem);

When I select Photoshop CC 2015 I get a runtime error at line 13 because photoshop doesn't seem to know $.writeIn().
When I select the Toolkit CS6 I get multiple errors starting at line 1 because it doesn't know any of those photoshop specific commands (that is what I mentioned in my post before).

As you can see I am trying to see what's inside "activeDocument.activeLayer.textItem". I could also take "activeDocument.activeLayer", it doesn't matter. Usually when I log an object/array to the console I get children of it listed but not in this case. I just get the object/array itself like [activeDocument.activeLayer.textItem] when I alert it.
alert() is the only "working" function (because of the behaviour I mentioned in the paragraph before) in terms of outputting something. But it's not what I wanted.
Maybe I am expecting something wrong. Is the only way to see what's inside "activeDocument.activeLayer" to search the guideline/doc for this method?

Votes

Translate

Translate

Report

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
Engaged ,
Nov 12, 2017 Nov 12, 2017

Copy link to clipboard

Copied

You've written writeIn with a capital "i" instead of writeln() with lowercase "L"...

Davide Barranca - PS developer and author
www.ps-scripting.com

Votes

Translate

Translate

Report

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
Community Expert ,
Nov 12, 2017 Nov 12, 2017

Copy link to clipboard

Copied

Davide had some neat ideas on looking into object. I learned something. So taking what he said and looking up the info in the Javascript tool Kit. I used their example for reflect. Neat feature! By the way, sometimes it's easier and less typing to assign variables to things like app.activeDocument, activeLayers, and the actual textItems, I changed your script a bit. Try it now.

#target photoshop

var doc = app.documents.add(500, 500, 72, "foobar", NewDocumentMode.RGB); 

 

var days = doc.artLayers.add() 

days.kind = LayerKind.TEXT; 

days.name = "test"; 

var dTxtItem = days.textItem

dTxtItem.size = 24; 

dTxtItem.position = new Array(50, 50); 

dTxtItem.contents = '01'; 

 

//Since you just created the text layer, it is the active layer 

doc.activeLayer = doc.artLayers.getByName("test"); 

var props = dTxtItem.reflect.properties;

for (var i = 0; i < props.length; i++) {

    try{

        $.writeln('this property ' + props.name + ' is ' + dTxtItem[props.name]);

        }

    catch(e){$.writeln(props.name + '---'+e)}

}

This is what I get in the console when I run the script:

this property antiAliasMethod is AntiAlias.CRISP

this property autoKerning is AutoKernType.METRICS

this property color is [SolidColor]

this property useAutoLeading is true

this property tracking is 0

this property verticalScale is 100

this property horizontalScale is 100

this property baselineShift is 0 pt

this property contents is 01

this property font is MyriadPro-Regular

leading---Error: The text is set to auto-leading and has no special leading value.

this property ligatures is true

this property alternateLigatures is false

oldStyle---Error: The requested property does not exist.

this property position is 50 px,50 px

this property direction is Direction.HORIZONTAL

this property size is 24 pt

this property fauxBold is false

this property fauxItalic is false

this property capitalization is TextCase.NORMAL

this property strikeThru is StrikeThruType.STRIKEOFF

this property underline is UnderlineType.UNDERLINEOFF

this property language is Language.ENGLISHUSA

this property noBreak is false

this property kind is TextType.POINTTEXT

this property justification is Justification.LEFT

this property leftIndent is 0 pt

this property firstLineIndent is 0 pt

this property rightIndent is 0 pt

this property spaceBefore is 0 pt

this property spaceAfter is 0 pt

this property hangingPuntuation is false

this property hangingPunctuation is false

this property textComposer is TextComposer.ADOBESINGLELINE

this property hyphenation is false

this property minimumGlyphScaling is 100

this property desiredGlyphScaling is 100

this property maximumGlyphScaling is 100

this property minimumLetterScaling is 0

this property desiredLetterScaling is 0

this property maximumLetterScaling is 0

this property minimumWordScaling is 80.0000011920929

this property desiredWordScaling is 100

this property maximumWordScaling is 133.000004291534

this property autoLeadingAmount is 120.000004768372

hyphenateWordsLongerThan---Error: General Photoshop error occurred. This functionality may not be available in this version of Photoshop.

- <no additional information available>

hyphenateAfterFirst---Error: General Photoshop error occurred. This functionality may not be available in this version of Photoshop.

- <no additional information available>

hyphenateBeforeLast---Error: General Photoshop error occurred. This functionality may not be available in this version of Photoshop.

- <no additional information available>

hyphenLimit---Error: General Photoshop error occurred. This functionality may not be available in this version of Photoshop.

- <no additional information available>

hyphenationZone---Error: General Photoshop error occurred. This functionality may not be available in this version of Photoshop.

- <no additional information available>

hyphenateCapitalWords---Error: The requested property does not exist.

width---Error: The requested operation is only applicable for paragraph text.

height---Error: The requested operation is only applicable for paragraph text.

this property warpStyle is WarpStyle.NONE

this property warpDirection is Direction.HORIZONTAL

this property warpBend is 0

this property warpHorizontalDistortion is 0

this property warpVerticalDistortion is 0

this property typename is TextItem

this property parent is [ArtLayer test]

this property __proto__ is [object Object]

Result: undefined

Votes

Translate

Translate

Report

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
Community Beginner ,
Nov 13, 2017 Nov 13, 2017

Copy link to clipboard

Copied

Interesting. I am still kinda disappointed that I have to use "reflect" to get the properties. Thought it would be more intuitive (because native javascript offers this behaviour). Thank your for the answers. I have just one question. Why did you use "var" in front of the variables? I mean it's not needed in this example, the scope is the same. Just curious if there is a special reason why.

Votes

Translate

Translate

Report

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
Community Expert ,
Nov 13, 2017 Nov 13, 2017

Copy link to clipboard

Copied

LATEST

Habit, I guess. Just a better visual for me to see where the variables are declared.

Votes

Translate

Translate

Report

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