# How to add a property to a proxy upon its registration

**URL:** https://discourse.paraview.org/t/how-to-add-a-property-to-a-proxy-upon-its-registration/432
**Category:** Development
**Created:** [August 14, 2018, 7:56pm UTC](https://discourse.paraview.org/t/how-to-add-a-property-to-a-proxy-upon-its-registration/432 "2018-08-14T19:56:07Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![gregory.zaccaro](https://discourse.paraview.org/user_avatar/discourse.paraview.org/gregory.zaccaro/32/2655_2.png) [@gregory.zaccaro](https://discourse.paraview.org/u/gregory.zaccaro)
#### Post date: [August 14, 2018, 7:56pm UTC](https://discourse.paraview.org/t/how-to-add-a-property-to-a-proxy-upon-its-registration/432/1 "2018-08-14T19:56:07Z")

</div>

I added to the vtkAlgorithm class an attribute “bool MyAttribute” with its getters and setters.

Basically, I need this attribute to be saved in the state files. I could add the property manually to every sources/filters xml definition but it’s not an option here because of having a large number of xml definitions.

I tried multiple things (e.g.: proxy SetAnnotation) and… I finally think that the best way to achieve this would be to add for each filter/source proxy a new property “MyAttribute” when the proxy has just been registered.

So I connect to the signal pqServerManagerObserver::proxyRegistered to a custom callback.  
Within the callback I didn’t find a way to extend the proxy definition. Any suggestion?

I found the class vtkSMSelfGeneratingSourceProxy which allows to extend a proxy definition but couldn’t find a way to make it work with ParaView.  
Here is how I implemented it:

```
void aProxyRegistrationReaction::onProxyRegistered(const QString& group, const QString& name, vtkSMProxy* proxy)
{
    if(std::strcmp(proxy->GetXMLGroup(), "sources") == 0 || std::strcmp(proxy->GetXMLGroup(), "filters") == 0)
    {
        std::string extension =
            " <Proxy> "
            " <Property"
            " command='SetMyAttribute'"
            " default_values='0'"
            " name='MyAttribute'"
            " number_of_elements='1'"
            " panel_visibility='never'>"
            " </Property>"
            " </Proxy> ";
        
        vtkSmartPointer<vtkSMSelfGeneratingSourceProxy> sgProxy =
            vtkSmartPointer<vtkSMSelfGeneratingSourceProxy>::New();
        sgProxy->InitializeAndCopyFromProxy(proxy);
        
        if (!sgProxy->ExtendDefinition(extension.c_str()))
        {
            std::cerr << "Failed to extend proxy definition!" << endl;
        }
        
        sgProxy->UpdateVTKObjects();
    }
}

```

And at run time, I got the errors like:

```
 ERROR: In c:\git\paraview\paraviewcore\servermanager\core\vtksmproxy.cxx, line 2297
 vtkSMSelfGeneratingSourceProxy (000002E41553C500): Proxies on different sessions.

```

Thanks in advance.

---

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [August 28, 2018, 11:41am UTC](https://discourse.paraview.org/t/how-to-add-a-property-to-a-proxy-upon-its-registration/432/2 "2018-08-28T11:41:47Z")

</div>

`vtkSMSelfGeneratingSourceProxy` is not intended to be used to clone and extend any arbitrary proxy. It is intended for cases as [this](https://gitlab.kitware.com/paraview/paraview/blob/master/ParaViewCore/CinemaReader/cinemareader.xml#L21-63) i.e. proxies that can be extended are defined as so in the XML itself.

In short, there’s no easy way that I can think of to extend the definition of all source and filter proxies. One potential (and convoluted) way is by using `vtkSIProxyDefinitionManager::AddElement`. If you look at the implementation, it provides a way to extend specific XML definitions. You can iterate over all source/filter definitions known, create a new XML config for extending each and the load that XML config using `bool vtkSIProxyDefinitionManager::LoadConfigurationXML`.
