> For the complete documentation index, see [llms.txt](https://www.opal-rt.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.opal-rt.com/docs/rt-lab/automation-api-and-scripting/rt-lab-api/c-rt-lab-api-reference/functions-reference/opalsetnotificationcallbackformodel.md).

# OpalSetNotificationCallbackForModel

<table data-header-hidden><thead><tr><th width="180.2222900390625"></th><th></th></tr></thead><tbody><tr><td><strong>Group</strong></td><td>Utilities</td></tr><tr><td><strong>Description</strong></td><td><p>Registers a callback function that will be called when a specific event happens in the simulator. The callback function will be called when an event from the registered events list happens and is related to the specified model. To register events for all models in a project use <strong>OpalSetNotificationCallback</strong>, or set model ID to 0 (zero).</p><p>If an event is registered for both model and project.</p><p>Each time this function is called with the same model ID, the event list and the callback function passed in argument will replace the previously registered list and callback function. However, you can register a specific event list and callback function for each model.</p><p>Pass an empty event list to unregister all events. Use special event OP_ALL_EVENTS to register all possible events.</p><p>You can also define your own events, see OP_EVENTS.</p><p>The callback function can be defined as following:</p><p>void <strong>pfnCallback</strong>(OP_NOTIFICATION notification, void * pUserData) { /*Some code...*/ }</p></td></tr><tr><td><strong>Required Control</strong></td><td>None</td></tr><tr><td><strong>Usage</strong></td><td>int <strong>OpalSetNotificationCallbackForModel</strong>(unsigned short numEvents,OP_EVENTS eventsList[], OPALCALLBACK pfnCallback, void *pUserData, OP_REF_ID modelId);</td></tr><tr><td><strong>Input</strong></td><td><ul><li><strong>numEvents:</strong> number of the registered event in eventsList arguments</li><li><strong>eventsList:</strong> list of events (see OP_EVENTS) that will generate a call to the registered callback function</li><li><strong>pfnCallback:</strong> callback function</li><li><strong>pUserData:</strong> second argument of the callback function</li><li><strong>modelId:</strong> ID of the model whose events will be detected</li></ul></td></tr><tr><td><strong>Output</strong></td><td>None</td></tr><tr><td><strong>Return value</strong></td><td><ul><li><strong>EOK:</strong> Success.</li><li><strong>EINVAL:</strong> Invalid number of events or callback function is NULL or event list is NULL or modelId is invalid.</li><li><strong>EBADF:</strong> invalid event found in events List</li></ul></td></tr><tr><td><strong>Examples</strong></td><td>None</td></tr><tr><td><strong>Related items</strong></td><td>OP_EVENTS, OP_NOTIFICATION, OpalSetNotificationCallback, OpalNotificationGetPathName, OpalNotificationGetID, OpalNotificationGetValue</td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.opal-rt.com/docs/rt-lab/automation-api-and-scripting/rt-lab-api/c-rt-lab-api-reference/functions-reference/opalsetnotificationcallbackformodel.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
