Best way to list objects in a stream

What’s the best way to list object ids currently in a stream? Or, more specifically, the object ids expected by the speckle viewer’s loadObject() method?

From a dotnet server, I’ve managed to create an object with some displayValue geometry, commit it to a stream, and then view it on my locally running server’s frontend. In C#, the class is defined as:

public class TestModel : Base
{
        [DetachProperty]
        public List<Polyline> displayValue { get; private set; }
        public Box bbox { get; private set; }
        public int random { get; private set; }
}

After a commit with Helpers.Send(), if I use the Helpers.Receive("{streamDomain}/streams/{streamId}/branches/main") method, I get the following:

{
    "totalChildrenCount": 0,
    "applicationId": null,
    "speckle_type": "Base",
    "displayValue": [
        {
            "value": [
                0.0,
                0.0,
                0.0,
                1.0,
                2.0,
                3.0
            ],
            "closed": false,
            "domain": null,
            "bbox": null,
            "area": 0.0,
            "length": 0.0,
            "units": "m",
            "totalChildrenCount": 0,
            "applicationId": null,
            "speckle_type": "Objects.Geometry.Polyline",
            "id": "cff3f3652f1b01c06a600974b84ed354"
        }
    ],
    "bbox": null,
    "random": 1450717906,
    "id": "8352492e5ae6083d3d33453d9de336da"
}

These results are more or less expected. Please do not judge my line quality. He’s doing his best.

The problem I’m facing is, if I use either one of those listed ids (the top-level object or its displayValue) with the javascript viewer.loadObject(${streamDomain}/streams/${streamId}/objects/${objectId}) method, it says it can’t find an object with that id. The id changes if the object changes, which is understandable, but I can’t get any ids from Helpers.Receive() to work.

If I visit the server frontend, the data view will present me with almost the same values as Helpers.Receive():

Importantly, the id from this latest commit is different from the value in Helpers.Receive(). If I use this id in viewer.loadObject(), everything works as expected.

What I’d like to do is commit a change and then have a way to (re)load that model after the change has completed. Is there a way to programmatically find the same id being presented to me in the viewer?

Away from keyboard atm, so just a sort reply. I’d suggest looking at the object loader library:

@speckle/objectloader - npm.

And how it’s used in the frontend, excel connector etc…

UPDATE: realized you asked about C#, so scrap the above! :sweat_smile:

Still useful! Hadn’t yet encountered that, will take a look. If the answer right now is “ask from javascript” that’s totally fine too.

Stepping through how the frontend does it now. Seems to be something about asking for a commit directly. I think I just might have the wrong mental model of what’s “in” a stream vs “in” a commit.

1 Like

Object loader was the perfect reference, pointed me to the right part of the viewer code.

In order to get the id shown in the frontend and expected by viewer.loadObject(), I can use the following snippet:

var client = new Client(account);
var branch = client.BranchGet(streamId, branchName, 1).Result;
var objectId = branch.commits.items[0].referencedObject;

Also popped up in the docs here under “Advanced Receiving”.

The objectId there is still different from the id fields in the result of Helpers.Receive(). But it looks like I just got a bit twisted over which-object-and-when. Helpers and viewer.loadObject() use this “root” id and I understand now it’s the one I should be after. It looks like the object loader would help with anything I want to do once I have that information (or I could use the viewer APIs, since the id is enough to load it there).

Thanks for the help @teocomi !

2 Likes