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

Error 21: undefined is not an object when reading pathpoints of path with javascript

Participant ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

I'm trying to write a javascript that extracts all pathpoints from a path named "Frame" and saves the info in a text file for later use. I use this code to loop through SubPathItems and Pathpoints of the given path:

 

function extractSubPathInfo(pathObj){
    var pl = pathObj.subPathItems.length;
    for(var s = 0; s < pathObj.subPathItems.length; s++){
        
          for( var i = 0; i < pathObj.subPathItems.pathPoints.length; i++){
            // Save Pathpoint to file
          };
          
    };
};

var myPathInfo = extractSubPathInfo(app.activeDocument.pathItems.getByName('Frame'));

 

However, PS throws this error "Error 21: undefined is not an object" for the line "for( var i = 0; i < pathObj.subPathItems.pathPoints.length; i++){".

 

It's as is the SubPathItem doesn't contain any information. What am I not hetting here?

 

TOPICS
Actions and scripting

Views

295

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 , Aug 12, 2022 Aug 12, 2022

You don’t seem to declare which subPathItem, you don’t actually use the variable s in the line 

          for( var i = 0; i < pathObj.subPathItems.pathPoints.length; i++){

 

Votes

Translate

Translate
Adobe
Community Expert ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

You don’t seem to declare which subPathItem, you don’t actually use the variable s in the line 

          for( var i = 0; i < pathObj.subPathItems.pathPoints.length; i++){

 

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
Participant ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

Serves me right for borrowing a script i didn't quite understand! This is the working version I ended up with:

 

#target photoshop

// Functions

function writeToFile(output) {
    ExportFile.write(output);  
}


// Open file for append to file "poserframes-path.txt" on desktop
var ExportFile = new File(Folder.desktop + "/poserframes-path.txt");
ExportFile.open("a", "TEXT");


// Get paths in document
var pathObj = app.activeDocument.pathItems.getByName('Frame');

for (var s = 0; s < pathObj.subPathItems.length; s++) { // Loopa genom alla SubPathItems
    
    for (var i = 0; i < pathObj.subPathItems[s].pathPoints.length; i++) { // Loopa genom akka pathPoints i SubPathitem

        var thisPathPoint = "'" + pathObj.subPathItems[s].pathPoints[i].kind + "', '" + pathObj.subPathItems[s].pathPoints[i].anchor +  "', '" + pathObj.subPathItems[s].pathPoints[i].leftDirection + "', '" + pathObj.subPathItems[s].pathPoints[i].rightDirection + "', '" + pathObj.subPathItems[s].pathPoints[i].typename + "'\n";
        
        writeToFile(thisPathPoint);
    }
    
}

// Close file
ExportFile.close();

 

Thanks again!

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 ,
Aug 12, 2022 Aug 12, 2022

Copy link to clipboard

Copied

LATEST

You’re welcome. 

 

With only four PathPoints it will likely not make much difference but if working with Paths in Scripts is a frequent task for you using Action Manager-code might increase the speed of the Script a little. 

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