Entities

Entities allow a plugin to store lots of different information in the form of a data tree which can be accessible easily with Grid Studio.

Accessing and Storing Values

There are multiple ways to store values into the entities.

Dictionary

One of the method is that you can treat the self.entities as a dictionary.

For example, you can do the following to set the value of the key some/sub/path

self.entities["some"]["sub"]["path"].value = xxxx

getSubPath

Another method is to use a function that belows to the entities which is the getSubPath. To have access to the key some/sub/path, you would do the following:

self.entities.getSubPath("some/sub/path", True)

The second parameter which is a bool , if set True will create the key for you if the key does not already exists.

So to set the value of this key, you would do the following:

self.entities.getSubPath("some/sub/path", True).value = 1.23

Set with Json

If you already have a data structured stored in the JSON format, it is possible to directly dump the entire JSON into the entities by using the setTreeValueWithJson function.

Assuming you already have the JSON formatted data, you could do something like below:

#myJsonData is variable where I have my JSON formatted data
self.entities.data.setTreeValueWithJson(myJsonData)

Enable / Disable Entities Tab in Inspector

To enable (show) the entities tab

self.cc.entities.hideInEditor = False

To disable (hide) the entities tab

self.cc.entities.hideInEditor = True

Changing the default view of the Entities Tab

How the entities tab is viewed by default in the inspector can be defined by the following parameter

self.cc.entities.valueRepresentation.value

True
False

Templates for Value Representation

From the plugin, you can define different templates. These templates are different groups of keys and values pair (entity) you want to display.

Add an entity into the template

self.addEntityRepresentation("Name of the parameter to be displayed", "Parameter type", "Path to the entity", containerName="Option to place Parameters in a container")

After adding all of the desired entity, you would need to save them into a template

self.saveEntityRepresentationTemplate("Name of the template")

And as a final step, you might want to clear the selection, so that it would not affect any further entity selection and template creation. To do so, you need to make the following function call

self.clearEntityRepresentations()

So putting it all together, you would have something like the following:

self.addEntityRepresentation("String Value", "string", "someString")
self.saveEntityRepresentationTemplate("Basic")
self.clearEntityRepresentations()

There is the additional option if you like to organize these parameters into containers.

As an example, you might have something like the following:

self.addEntityRepresentation("String Value", "string", "someString", containerName="Some Container")
self.addEntityRepresentation("Bool Value", "boolean", "someBool", containerName="Some Container")
self.addEntityRepresentation("Float Value", "float", "some/sub/path", containerName="Some Other Container")
self.saveEntityRepresentationTemplate("Expert")
self.clearEntityRepresentations()

Last updated