How can i get assembly-tree attribute?

Hello,Tino:

i add some attributes to assembly-tree through the function AddAttribute or AddFaceAttribute or AddEdgeAttribute, how can i get these attribute?

bool AddFaceAttribute(NodeId bodyNodeID, uint32_t faceIndex, const char *attributeName, AssemblyTree::AtrributeType attributeType, const char *attributeValue)

Thanks!
Best

Jenson

You can call the corresponding Web Viewer functions:

Hello, tino:

Firstly, i’m so soory for my title! I have modified!
When i upload a SCS Files which i generated by Sc API from “D:\Projects\HOOPS_Communicator_2025.6.1\authoring\libsc\examples\sc_store_cube_sample.cpp”, then I find the nodeId is negative!Why?

I find the attributes type is a array,so how should i get the attribute?attributes[0]? It’s error!

Thanks a bunch!
Best

js code:

if(selectType.value === “face”)

{

    var config = new Communicator.PickConfig(Communicator.SelectionMask.Face);

    this._hwv.selectionManager.clear();

    this._hwv.view.pickFromPoint(event.getPosition(), config).then((selection) => {

            if (selection.getNodeId() != null) {

                    this._hwv.selectionManager.set(selection);                                        

                    const nodeId = selection.getNodeId();

                    console.log("nodeId:",nodeId);

                    const faceId = selection.getFaceEntity().getCadFaceIndex();

                    console.log("faceId:",faceId);

                    this._hwv.model.getFaceAttributes(nodeId,faceId).attributes.forEach(attr => {

                            console.log("femapId:", attr.getValue());

                    });                        

            }

    });

}

The function getFaceAttributes returns a promise so you can do a .then or await:

const faceAttributes = await this._hwv.model.getFaceAttributes(nodeId,faceId);

faceAttributes.attributes.forEach(attr => {
    console.log("femapId:", attr.getValue());
});

Also, when I run the sample, the node id for the cube is positive, not negative. A quick recommendation is that for each time you run the example, please delete the old version in HOOPS_Communicator_2025.6.1\quick_start\converted_models\authoring_samples_data.

Hello,tino:

Thanks you very much! Thanks again!

Best!

Jenson

attributes.zip (23.2 KB)
Hello,tino:
Sorry for my question!
I deleted the old version, then i get the positive nodeId,but i don’t get the faceattributes, and i test all faces, the results are null. God, why? Help me!
Respectfully yours!
Jenson

In your original code from an earlier post, you hard-coded the body id as 1 in the first argument:

assembly_tree.AddFaceAttribute(1, 1, "femap_id", SC::Store::AssemblyTree::AttributeType::AttributeTypeInt, "90");

Instead of doing that, pass the body id variable to the function:

assembly_tree.AddFaceAttribute(body_id, 1, "femap_id", SC::Store::AssemblyTree::AttributeType::AttributeTypeInt, "90");

Hello,tino:

Sorry, I may not have described my question clearly. Actually, the SCS files in the compressed file have already been generated using the parameter body_id not the parameter “1”. But the results are null.
Best wishes!
Jenson

Hello,

Please send me your .cpp file by clicking my profile and then “Message”.

Thanks,
Tino