# UI Parameters

It´s possible to create parameters within your extension which are exposed and direct available within Grid.

## General

A parameter which should be visible within the inspector needs to be defined within the [afterInit](/grid/extensions/general-functions.md#afterinit) function.

A parameter need to be "linked" to a tab/container similar like this:

```python
def afterInit(self):
    self.objectContainer.addFloatParameter("Example Float", 0, 0, 100)
```

For more details [see here.](/grid/extensions/tabs-containers-and-parameters.md)

***

## Access / Use parameter values

```python
parameterName.value
```

```python
def afterInit(self):
    self.parameter = self.objectContainer.addFloatParameter("Example", 0, 0, 100)
    
def someReadFunction(self):
    floatValue = self.parameter.value

def someSetFunction(self):
    self.parameter.value = 1.234

def onParameterFeedback(self, parameter):
    if parameter == self.parameter:
        print(self.parameter.value)
```

***

## Parameter types

### String

<figure><img src="/files/6deEChIbQusnqwafi0li" alt=""><figcaption></figcaption></figure>

Add a parameter of the type string

`.addStringParameter("ParameterLabel", "DefaultValue")`

<pre class="language-python"><code class="lang-python"><strong>self.parameter = self.yourContainer.addStringParameter("Example String", "string")
</strong></code></pre>

A parameter of the type string is also supporting multilines

```python
self.parameter.setParam("multiline", True) #Enable multiline support
```

{% hint style="success" %}
instead of using multiline you can also add:&#x20;

<pre class="language-python"><code class="lang-python"><strong>.addTextParameter("Example Text","First Line\nSecond Line")
</strong></code></pre>

{% endhint %}

```python
self.parameter.value #returns a string
```

<pre class="language-python"><code class="lang-python"><strong>self.parameter.value = "Example" #set parameter
</strong></code></pre>

***

### Text

<figure><img src="/files/2d5jF8n2lyPVRhnxIHik" alt=""><figcaption></figcaption></figure>

Add a parameter of the type text

`.addTextParameter("ParameterLabel", "DefaultValue")`

<pre class="language-python"><code class="lang-python"><strong>self.parameter = self.yourContainer.addTextParameter("Example Text", "text\ntext\n")
</strong></code></pre>

```python
self.parameter.value #returns a string
```

<pre class="language-python"><code class="lang-python"><strong>self.parameter.value = "Example" #set parameter
</strong></code></pre>

***

### Integer

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

Add a parameter of the type int

`.addIntParameter("ParameterLabel", DefaultValue, MinValue, MaxValue)`

<pre class="language-python" data-full-width="false"><code class="lang-python"><strong>self.parameter = self.yourContainer.addIntParameter("Example Int", 587, 1, 65535)
</strong></code></pre>

{% hint style="success" %}
This parameter supports suffixes.[ See here.](broken://pages/8GLeBi8YyTDip80gYtbq#set-suffix-for-parameter)
{% endhint %}

```python
self.parameter.value #returns a float
# do int(parameter.value) if you need a int
```

```python
self.parameter.value = int(123) #set parameter
```

***

### Float

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

Add a parameter of the type float

`.addFloatParameter("ParameterLabel", DefaultValue, MinValue, MaxValue)`

```python
self.parameter = self.yourContainer.addFloatParameter("Example Float", 0, 0, 100)
```

{% hint style="success" %}
This parameter supports suffixes.[ See here.](broken://pages/8GLeBi8YyTDip80gYtbq#set-suffix-for-parameter)
{% endhint %}

<pre class="language-python"><code class="lang-python"><strong>self.parameter.value #returns a float
</strong></code></pre>

```python
self.parameter.value = 123.456 #set parameter
```

***

### Bool

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

Add a parameter of the type bool

`.addBoolParameter("ParameterLabel", DefaultValue)`

```python
self.parameter = self.yourContainer.addBoolParameter("Bool", False)
```

```python
self.parameter.value #returns a bool
```

```python
self.parameter.value = True #set parameter
```

***

### Enum / Dropdown

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

Add a parameter of the type enum.<br>

Empty Enum

`.addEnumParameter("ParameterLabel", defaultIndex, "")`

```python
self.parameter = self.yourContainer.addEnumParameter("Enum", 0, "")
```

Enum with predefined entires

`.addEnumParameter("ParameterLabel", defaultIndex, "SemikolonSeparatedEntriesAsString")`

```python
self.parameter = self.yourContainer.addEnumParameter("Enum", 0, "First;Second;Third")
```

{% hint style="success" %}
An enum entry within Grid owns a name/key as well as a value/data.

If the entries are generated within the function ".addEnumParameter()" the value/date will be the index.
{% endhint %}

Additional enum functions

```python
self.parameter.value #returns the index of the actual enum entry
```

```python
self.someParameter.getData() #returns the data/value of the actual enum entry
```

```python
self.someParameter.getKey() #returns the key/name of the actual enum entry
```

```python
self.parameter.getLabel(index) #returns the key/name of the index defined entry
```

```python
self.someParameter.clearOptions() #remove all entries from the enum 
```

```python
self.someParameter.addOption("Name", Value) #add a new entry
```

{% hint style="info" %}
The value is a var and can hold different parameter types like: \
Int, Float, String, etc.

`.addOption("Enum", 1234)`

`.addOption("Enum", 12.34)`

`.addOption("Enum", "OneTwo")`
{% endhint %}

```python
self.someParameter.removeOption("Name") #remove a specific entry using the key/name
```

```python
self.parameter.value = 3 #set the enum to index 3
```

***

### Point / Vector2

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

Add a parameter of the type point / vector2

`.addPointParameter("ParameterLabel")`

```python
self.parameter = self.yourContainer.addPointParameter("Point")
```

{% hint style="success" %}
This parameter supports suffixes.[ See here.](broken://pages/8GLeBi8YyTDip80gYtbq#set-suffix-for-parameter)
{% endhint %}

```python
self.parameter.value #returns a float array with two entries [0.0, 1.1]
```

```python
self.parameter.value = [123.123, 456.456] #set parameter
```

***

### Vector

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

Add a parameter of the type  vector3

`.addVectorParameter("ParameterLabel")`

<pre class="language-python"><code class="lang-python"><strong>self.parameter = self.yourContainer.addVectorParameter("Vector")
</strong></code></pre>

{% hint style="success" %}
This parameter supports suffixes.[ See here.](broken://pages/8GLeBi8YyTDip80gYtbq#set-suffix-for-parameter)
{% endhint %}

```python
self.parameter.value #returns a float array with three entries [0.0, 1.1, 2.2]
```

```python
self.parameter.value = [123.123, 456.456, 789.789] #set parameter
```

***

### IP

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

Add a parameter formatted correctly for IP-addresses

`.addIPParameter("ParameterLabel", AvailableAdressesOnly)`

<pre class="language-python"><code class="lang-python"><strong>self.parameter = self.yourContainer.addIPParameter("IP", True)
</strong></code></pre>

{% hint style="success" %}
If True -> show all available local adapter\
If False -> IP can be defined manually and the list is "helping" only.
{% endhint %}

```python
self.parameter.value #returns a string formated like: "123.456.789.0"
```

```python
self.parameter.value = "192.168.1.123" #set parameter
```

{% hint style="info" %}
You can use  `.isValidIP()` to check the given IP address.\
Return True or False.

```python
self.parameter.isValidIP()
```

{% endhint %}

***

### Color

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

Add a color parameter

`.addColorParameter("ParameterLabel")`

```python
self.parameter = self.yourContainer.addColorParameter("Color")
```

```python
self.parameter.value #returns color as string Hex based (AARRGGBB)
# AA = Alpha 00-FF
# RR = Red 00-FF
# GG = Green 00-FF
# BB = Blue 00-FF
```

```python
self.parameter.value = "00000000" #set to Black and Alpha to 0
self.parameter.value = "FF000000" #set to Black and Alpha to 1
self.parameter.value = "FFFF0000" #set to Red and Alpha to 1
self.parameter.value = "FF00FF00" #set to Green and Alpha to 1
self.parameter.value = "FF0000FF" #set to Blue and Alpha to 1
```

***

### File

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

Add a parameter which supports a file explorer search

`.addFileParameter("ParameterLabel","preDefinedPath")`

```python
self.parameter = self.yourContainer.addFileParameter("File","")
```

```python
self.parameter.value #returns the linked file
```

***

### Trigger / Button

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

Add a trigger button parameter

`.addTrigger("ParameterLabel")`

```python
self.trigger = self.yourContainer.addTrigger("Trigger Button")
```

```python
def onParameterFeedback(self, parameter):
    if parameter == self.trigger:
        doSomething()
```

***

### Data

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

Add a data parameter to handle json formated data

`.addDataParameter("ParameterLabel")`

<pre class="language-python"><code class="lang-python"><strong>self.parameter = self.yourContainer.addDataParameter("Data")
</strong></code></pre>

Access value from child parameter:

```python
self.parameter.value["Example"]["name"].value #returns "John"
self.parameter.value.getSubPath("Example/name").value #returns "John"
```

Set / Write value of a child parameter

```python
self.parameter.value["Example"]["name"].value = "Example" #set value
self.parameter.value.getSubPath("Example/name").value = "Example" #set value
```

Append a new child

```python
newChild = sp.ValueTree("new child name")
newChild.value = 3
self.parameter.value.appendChild(newChild)
```

<div align="left"><figure><img src="/files/kUndzia5kpQ2FunRESTU" alt=""><figcaption></figcaption></figure></div>

```python
anotherChild = sp.ValueTree("example")
anotherChild.value = "example"
self.parameter.value["new child name"].appendChild(anotherChild)
```

<div align="left"><figure><img src="/files/7tCrqUkfr7AowoVlAQQe" alt=""><figcaption></figcaption></figure></div>

Set complete parameter from json

{% hint style="warning" %}
A json import is needed:

```python
import json
```

{% endhint %}

{% hint style="danger" %}
This should only be used to "fill" the tree initial. \
Please don´t use this to update a single child parameter.
{% endhint %}

```python
self.parameter.setTreeValueWithJson("Example", json.dumps(
    {
        "name":"John",
        "age":30,
        "car":""
    }))
    
# adds the given json into the data parameter 
```

***

### DataTarget

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

Adds a customizable data parameter which can be filled with json arrays.

`.addDataTargetParameter("ParameterLabel", "", "")`

```python
def afterInit(self):
    self.parameter = self.yourContainer.addDataTargetParameter("Data Target", "", "")
    self.parameter.setGetTargetFunction(self.getData)

def getData(self):
    return [
                {
                    "name": "One",
                    "extra": "1",
                    "inspectable" : self.cc
                },
                {
                    "name": "Two",
                    "extra": "2",
                    "inspectable" : self.cc
                }
            ]

```

{% hint style="danger" %}
This are the minimum json values needed for a single based json array element.

```
{
    "name": "",
    "extra": "",
    "inspectable" : self.cc
}
```

{% endhint %}

```python
self.parameter.value #returns the string value from "extra"
```

```python
self.parameter.getLabel() #returns the string value from "name"
```

***

### Object Target

<figure><img src="/files/78sPPYnfXKPhrb9bTnXy" alt=""><figcaption></figcaption></figure>

Adds a target parameter which can be linked to objects

`.addTargetParameter("ParameterLabel", True, "")`

```python
self.parameter = self.yourContainer.addTargetParameter("Target", True, "")
```

***

### Parameter Target

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

Adds a target parameter which can be linked to objects

`.addTargetParameter("ParameterLabel", False, "")`

```python
self.parameter = self.yourContainer.addTargetParameter("Target", False, "")
```

***


---

# 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/ui-parameters.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.
