api.scene.EVENTTYPE.SELECT_ON does not work

Adding api.scene.EVENTTYPE.SELECT_ON does nothing to me when clicking on the model, it does not execute the function. How could I click on a part of the model and do a function.

You need to make objects selectable first, see details in this code example:


This is what I have following the steps, but it doesn’t do anything for me, it doesn’t make it selectable for me and it doesn’t work for me either.
I leave you how are my variables.

I will be unable to help from looking at the screenshot above. Please share a minimal code example that I can use for debugging.

let arrPivot = api.scene.getData({
name: “frente”
}).data[0].data;
leftPivot = {
x: arrPivot[0],
y: arrPivot[1],
z: arrPivot[2]
};
leftTrans.scenePaths = [
api.scene.get(
{
name: “frente”
},
“CommPlugin_1”
).data[0].scenePath
];
leftTrans.transformations[0].pivot = leftPivot;
api.scene.updateInteractionGroups(selectableGroup);
var assets = api.scene.get(null, “CommPlugin_1”).data;
var updateObjects = ;
let updateObject = {
id: assets[19].id,
duration: 0,
interactionGroup: selectableGroup.id,
interactionMode: “global”
};
updateObjects.push(updateObject);
api.scene.updatePersistentAsync(updateObjects, “CommPlugin_1”);
api.scene.addEventListener(api.scene.EVENTTYPE.SELECT_ON, selectCallback);

this is the code i use.

This is just partial code, I don’t know at what point it is called in the viewer life cycle and also I don’t know the ShapeDiver model that is used in the background, which could also cause issues. Is there any way you can deploy a version of this code running where I can reproduce the issue?


I have created a codepen so you can test it.

In this part of your code:


You need to give the scene path of the piece of geometry you want to transform. Right now, you are referencing a piece of data (the pivot). The problem of your model is that you did not name the geometry assets in Grasshopper, therefore it is hard to find which piece of geometry you want to transform. They all have the same default name of the display component (SDDisplayGeometry):

You should give names to all the ShapeDiver Display components so that you can then find which object you want to use for the transformation.

I have changed the name of the geometry to what I need to use. But it still doesn’t work. The link is already changed to see if something fails.

I forked your pen with fixes: https://codepen.io/ShapeDiver/pen/abBPLNr

There were multiple issues but the two main ones:

  • Your line $("#sdv-container-canvas").attr("onmouseup", "saberdondeestapuesto()"); fails and then the rest of the code did not execute. I didn’t look into why and I don’t know what the goal is so I just commented it.
  • These lines will never work:

    The assets are not necessarily returned in the same order every time, you cannot hard code an index. You need to retrieve assets using their name or other filters:

Also note that you can’t just filter by name and take the first asset in the response. There are usually two assets sharing the same name: a piece of geometry and its assigned material. You need to filter by type as well.

The part where you try to generate parameter controls in HTML does not work and I did not look into it, I think it is not complete yet.