# 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.

<figure><img src="/files/vXrGMJs0TbsMkZcIoOW7" alt=""><figcaption></figcaption></figure>

### 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.&#x20;

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:

```python
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:

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

***

### Accessing Entity changes

It is possible to register for entity changes.&#x20;

For this the entity just needs to be defined within the `afterInit` and can cached within the `onValueFeedback` function.

#### Defining&#x20;

```python
def onValueFeedback(self, valueTree):
```

### 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                                |
| :-----------------------------------------------------------------: | :-----------------------------------------------------------------: |
| <img src="/files/dROZ8vwpXTdQHnHa997S" alt="" data-size="original"> | <img src="/files/z6WNfq64lbuurwHzAJnE" alt="" data-size="original"> |

### 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.

<figure><img src="/files/j9mEBJuymfdqsaouowsa" alt=""><figcaption></figcaption></figure>

#### 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:

```python
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:

```python
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()
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://stage-precision.gitbook.io/grid/extensions/entities.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
