How to get the node attribute or userdata?

I can get the face attribute,but how can i get the node attribute or userdata?

The front-end code:

                    const nodeSelectionItem = this.\_hwv.selectionManager.getFirst();

                    console.log("getSelectionType:",nodeSelectionItem.getSelectionType());

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

                    const nodeId = nodeSelectionItem.getNodeId();

                    const indices =  await this.\_hwv.model.getNodeUserDataIndices(nodeId);

                    console.log("User data array:",indices);

                    for (const index of indices) {

                            const data =  await this.\_hwv.model.getNodeUserData(nodeId, index); 

                            const intArray = new Int32Array(data.buffer);

                            console.log("User data array:", intArray);

                    }

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

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

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

                    faceAttributes.attributes.forEach(attr => {

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

                    });

The code of scs generator :

// Author measurement data
uint32_t part_id = _assembly_tree.CreatePart();
_assembly_tree.SetPart(child_node, part_id);
uint32_t body_id = 0;
_assembly_tree.CreateAndAddBody(part_id, body_id, SC::Store::Tessellation);

        // Add SolidEdge ID to sc
        auto FaceType = SolidEdgeGeometry::FeatureTopologyQueryTypeConstants::igQueryAll;
        SolidEdgeGeometry::BodyPtr pBody = (SolidEdgeGeometry::BodyPtr)pSEModel->Body;
        SolidEdgeGeometry::FacesPtr faces = (SolidEdgeGeometry::FacesPtr)pBody->Faces[FaceType];
        //bool bb = _assembly_tree.AddAttribute(child_node, "body_name",
        //    SC::Store::AssemblyTree::AttributeType::AttributeTypeString, pSEModel->GetBodyName());
        std::string userData = "Hello, this is user data";
        const uint8_t* dataBegin = reinterpret_cast<const uint8_t*>(userData.data());
        const uint8_t* dataEnd = dataBegin + userData.size();
        bool bb = false;
        bb = _assembly_tree.AddUserData(child_node, 1, dataBegin, dataEnd);
        for (int i = 1; i <= faces->Count; i++) {
            int faceId = ((SolidEdgeGeometry::FacePtr)faces->Item(i))->ID;
            std::string str = std::to_string(faceId);
            _assembly_tree.AddFaceAttribute(body_id, i - 1, "femap_id", 
                SC::Store::AssemblyTree::AttributeType::AttributeTypeInt, str.c_str());
        }

In your Authoring (server) code, you have this:

std::string userData = "Hello, this is user data";
        const uint8_t* dataBegin = reinterpret_cast<const uint8_t*>(userData.data());
        const uint8_t* dataEnd = dataBegin + userData.size();

        bool bb = false;
        bb = assembly_tree.AddUserData(child_node, 1, dataBegin, dataEnd);

So you are adding user data to child_node which is different from the body instance. With this is mind, you need to get the parent of the body instance when a selection is made:

hwv.setCallbacks({
    selectionArray: async function (selections) {
        if (selections.length > 0) {
            for (const selectionEvent of selections) {
                let selection = selectionEvent.getSelection();
                let nodeId = selection.getNodeId();
				console.log("Selected Node: " + nodeId);
				let nodeParent;
				if (Communicator.NodeType[hwv.model.getNodeType(nodeId)] == Communicator.NodeType[3]) {
					nodeParent = hwv.model.getNodeParent(nodeId);
					console.log("Selected Node Parent: " + nodeParent);
					
					let userDataIndices = hwv.model.getNodeUserDataIndices(nodeParent);
					
					for (const value of userDataIndices) {
						console.log("user data indices: " + value);
						console.log(JSON.stringify(hwv.model.getNodeUserData(nodeParent, value)));
					}
					
				}
                
            }
        }
    },
});

The result is:

Note that the character codes are the same as “Hello, this is user data”:

{
  "0":72,   // 'H'
  "1":101,  // 'e'
  "2":108,  // 'l'
  "3":108,  // 'l'
  "4":111,  // 'o'
  "5":44,   // ','
  "6":32,   // ' '
  "7":116,  // 't'
  "8":104,  // 'h'
  "9":105,  // 'i'
  "10":115, // 's'
  "11":32,  // ' '
  "12":105, // 'i'
  "13":115, // 's'
  "14":32,  // ' '
  "15":117, // 'u'
  "16":115, // 's'
  "17":101, // 'e'
  "18":114, // 'r'
  "19":32,  // ' '
  "20":100, // 'd'
  "21":97,  // 'a'
  "22":116, // 't'
  "23":97   // 'a'
}

Hello,Tino:

Thank you very much for your guidance!

You’re truly truly a sage!

Best wishes!

Jenson