Hide/Show objects

Hi,

is it possible to hide or show different objects in the model only using shapediver api?

Hi @bodibodileg, since version 2.8.0 of the API you can hide and show objects. You can find the function in the documentation here. Basically, you need to give an array with scenePaths of objects you want to show and another array with scenePaths of objects you want to hide.

The function will look like:
api.scene.toggleGeometry([SHOW OBJECT PATHS],[HIDE OBJECTS PATHS])

For example:
api.scene.toggleGeometry([],["CommPlugin_1.2b9804160ff9264ee6a031eaccedcbc8","CommPlugin_1.8d861a71a5925ea27d3c63e3f097b398"])
This example shows no objects and hide two objects.

Hope this helps.

Hi Edwin,

thank you for response. This is clear, but I dont know how can I get my objects that are located on the scene. Is there a function that can retrive all the objects? Because some of my object gets generated after inputs in the model.

To get the objects in your scene you can use the function described here.

You can either use a filter and your function will look like api.scene.get({name:"NAME YOU GAVE TO YOUR COMPONENT IN GH"}, "CommPlugin_1") or you can get the complete list of assets by using api.scene.get(null, "CommPlugin_1").

In your case you need to get the scene path of the geometry you want to hide/show so to do so you will use:

var assets = api.scene.get({name:"2D_Outline"}, "CommPlugin_1").data

This will give you a list of assets which are named 2D_Outline, one is the geometry and the other one is the material of this geometry. Then you need to filter out the asset that contains the material description to get just the geometry scene path:

var assetScenePath;

for (i = 0; i < assets.length; i++) {
if (assets[i].material){
assetScenePath = assets[i].scenePath;
}
};

assetScenePath is what you will use to hide/show your geometry.

Hope this helps.