Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Getting All Parents of field/folder/project

clwi
Enthusiast

Getting All Parents of field/folder/project

clwi
Enthusiast
Enthusiast

Hi,

 

I'm trying to create a breadcrumb bar for my project and was wondering if there's an easier way to get all the parents(hubs/projects/folders) from a project/folder/file ? Currently we're doing it by calling this function:

 

function getFolderParentRecursive(projectid, folder, arrayin, topfolders, credentials) {
   if (!credentials)
   {
        console.error("getFolderParentRecursive:Credentials null");
        return null;
   }

    return new Promise(function (fulfill, reject) {
        // do a thing, possibly async, then…
        if (folder.id != undefined && projectid != undefined) {
            arrayin.splice(0, 0, folder);

            //Check if current folder is top folder....
            for (var i = 0; i < topfolders.length; i++) {
                if (folder.id == topfolders[i].id) {
                    //Det är en topfolder
                    fulfill(arrayin);
                }
                else {
                    FoldersApi.getFolderParent(projectid, folder.id, oAuth2ThreeLegged, credentials).then(function (folderparent) {
                        //arrayin.splice(0, 0, folderparent.body.data.id);
                        if(folderparent != null)
                        {
                            getFolderParentRecursive(projectid, folderparent.body.data, arrayin, topfolders, credentials).then(function (parentarray) {
                               arrayin = parentarray;
                               fulfill(arrayin);
                            }
                            , function (err) {
                                console.error(err);
                                reject(err); //getFolderParentRecursive
                            });
                        }
                    }
                        , function (err) {
                            console.error(err);
                            reject(err); //Folder Parent
                        });
                    
                }
            }

        }
    });
}

But this way is very sluggish or slow even. Would have been nice to see the API returning all parents right from the json response for current location.

 

(Have a screenshot on what ours looks like right now... )

 

Thank you in advance for a quick reply.

 

/Claes

Reply
547 Views
3 Replies
Replies (3)

mikako_harada
Community Manager
Community Manager

Hi clwi, 

 

What API are you using?  BIM 360 Field classic  >>  /api/library/ ?  


Mikako Harada
Developer Technical Services
0 Likes

clwi
Enthusiast
Enthusiast

We're writing an node.js app and using the forge api

 

var ForgeSDK = require('forge-apis'); //Autodesk ForgeSDK api
var HubsApi = new ForgeSDK.HubsApi(); //Autodesk Hubs Client
var PorjectsApi = new ForgeSDK.ProjectsApi(); //Autodesk ProjectsAPI
var FoldersApi = new ForgeSDK.FoldersApi(); //Autodesk FoldersAPI
var BucketsApi = new ForgeSDK.BucketsApi(); //Autodesk BucketsAPI
var ObjectsApi = new ForgeSDK.ObjectsApi(); //Autodesk objectApi
var VersionsApi = new ForgeSDK.VersionsApi(); //Autodesk VersionsApi
var ItemsApi = new ForgeSDK.ItemsApi();
var DerivativesApi = new ForgeSDK.DerivativesApi();
 
Specificly the FoldersApi at it is now...
 
From package.json: 
"forge-apis": "^0.4.1",
 
 
Not saying that i'm opposed to modify/change what we're using or calling the forge api directly if that's needed
0 Likes

mikako_harada
Community Manager
Community Manager

Hi clwi,

 

Thank you for the clarification. I should have been familiarize myself with SDK, too. But I tend to stick with RESTSharp as I usually need to test new APIs before it is incorporated in the SDK.

 

Anyway, I thought that by the time you reach to a certain file or folder, you have gone through hubs >> projects >> top folders >> sub holders^n

and you keep track of those.

But I guess, if you click on a certain node in a tree in UI, for example, that node does not keep cascading ancestor list by default. You will need to find out.

 

To my best of knowledge, going backward following parents, which you are using, seem to be the way.

 

That said, one thing that made me think worth logging a wish is that,

when I was looking at the response example on the documentation carefully, the example includes name "path", but it is not when actually look at through my test.

https://developer.autodesk.com/en/docs/data/v2/reference/http/projects-project_id-folders-folder_id-...

 

it isn't in schema, either.


If you want to ask this as an enhancement request, you may try stackoverflow:

 

https://fieldofviewblog.wordpress.com/2016/10/27/where-to-get-help-about-forge/


Mikako Harada
Developer Technical Services
0 Likes

Type a product name