# General Functions

## init

```python
def __init__(self):
```

## afterInit

This event will be called whenever the extension is added to the project and when exist while the project is loading.\
[UI-Parameter](/grid/extensions/ui-parameters.md), [Events](/grid/extensions/events.md) and [Actions](/grid/extensions/actions.md) should be defined here as well as everything which is needed to be initialized for the extension object.

```python
def afterInit(self):
```

## onParameterFeedback

This function will be called on any parameter feedback/change

<pre class="language-python"><code class="lang-python"><strong>def onParameterFeedback(self, parameter):
</strong>    if parameter == self.someParameter:
        print(self.someParameter.value)
</code></pre>

## onDisabling

This function will be called whenever the object is set to disabled

```python
def onDisabling(self):
```

## onEnabling

This function will be called whenever the object is set to disabled

```python
def onEnabling(self):
```

## shutdown/remove

This function will be called whenever the project will be closed as well as when the object will be removed from the project.

```python
def shutdown(self):
```

## Timer

```python
self.addTimer("name", 1.0, self.onTimer)

self.removeTimer("name")
```

## Set parameter as read only

```python
someParameter = self.moduleContainer.addFloatParameter("Example", 0, 0, 100)
someParameter.setParam("readonly", True)
```

## Set suffix for parameter

Add a suffix to a parameter. \
Supports float, int, point and vector.

```python
someParameter = self.moduleContainer.addFloatParameter("Example", 0, 0, 100)
someParameter.setParam("suffix", "cm")
```

## Status Arrow

```python
self.showStatusArrow(True, True) #Input, Output

self.pushStatusInput()
self.pushStatusOutput()
```

## Status

```python
self.setStatus(sp.StatusType.Undefined)
self.setStatus(sp.StatusType.Undefined, "optionalCustomName")
self.setStatus(sp.StatusType.Active, "optionalCustomName")
self.setStatus(sp.StatusType.Connected, "optionalCustomName")
self.setStatus(sp.StatusType.Disconnect, "optionalCustomName")
self.setStatus(sp.StatusType.DeviceError, "optionalCustomName")
self.setStatus(sp.StatusType.ConnectionError, "optionalCustomName")
self.setStatus(sp.StatusType.InvalidSettings, "optionalCustomName")
self.setStatus(sp.StatusType.Standby, "optionalCustomName")
self.setStatus(sp.StatusType.Disabled, "optionalCustomName")
self.setStatus(sp.StatusType.TrackedState_Live, "optionalCustomName")
self.setStatus(sp.StatusType.TrackedState_False, "optionalCustomName")
self.setStatus(sp.StatusType.TrackedState_Timeline, "optionalCustomName")
self.setStatus(sp.StatusType.Connecting, "optionalCustomName")
```

## Logging

```python
self.log("normal logs")
self.logWarning("Warning logs")
self.logError("Error logs")
```

{% hint style="warning" %}
By default, the logs with normal level are filtered out from the log window in Grid Studio.
{% endhint %}

## Validate IP parameter

```python
.isValidIP()

self.myIPparameter.isValidIP() #Return True or False
```

## Adding workflow

It is possible to also ship with your extension a default workflow.

This means when the extension object is added to Grid Studio, the workflow is automatically added with the object and all the functions that are built inside the workflow can be loaded automatically.

{% hint style="info" %}
Before adding the line of code below, it is important to build your workflow and export it. For more details, please refer to [Workflow](/grid/grid-studio-fundamentals/fundamentals/core-concepts/workflow-programming.md)
{% endhint %}

Once you have a workflow file, you need to add one line of code inside the `afterInit()` function

```python
self.cc.general.workflow.importFromFile(os.path.join(os.path.dirname(os.path.abspath(__file__)),"workflow.spasset"))
#workflow.spasset being the default workflow file that you like to load when user adds your extension
```


---

# 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/general-functions.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.
