Example on how to use proxies

Hello, dear Paraview developers!

Could you please give me an example on how to use proxies from C++ to manipulate vtk objects?
I was not able to find a credible and simple example

Best regards,
Mike

Proxies are generally created using pqObjectBuilder::createProxy

https://kitware.github.io/paraview-docs/latest/cxx/classpqObjectBuilder.html#afb38d983a5f90ee0cb9b26656fbb77f0

Could you clarify please, what should one specify for the parameters of createProxy?

An example would help a lot

creating a sphere source proxy:

pqServer* server = pqActiveObject::instance().activeServer();
pqObjectBuilder::createProxy("sources", "SphereSource", server, "Sphere1");
  pqServer* server = pqActiveObjects::instance().activeServer();
  pqObjectBuilder builder = pqObjectBuilder(nullptr);
  vtkSMProxy * sphere_proxy = builder.createProxy("sources", "SphereSource", server, "Sphere1");
  vtkSMProperty* radius = sphere_proxy->GetProperty("Radius");
  //How to set the value?
  //How to actually create the sphere?
  sphere_proxy->UpdateVTKObjects();

Mathieu, I still don’t get how to make use of it, could you help me please

 pqServer* server = pqActiveObjects::instance().activeServer();
 const auto* builder = pqApplicationCore::instance()->getObjectBuilder();
 vtkSMProxy * sphere_proxy = builder.createProxy("sources", "SphereSource", server, "Sphere1");
 vtkSMPropertyHelper(sphere_proxy, "radius").Set(20);
 pqPVApplicationCore::applyPipeline();

Do not hesitate to look at paraview source code for that or to consider joining a ParaView advanced course.

I use an older version of paraview and I dont have applyPipeline, so I have tried

  pqServer* server = pqActiveObjects::instance().activeServer();
  pqObjectBuilder*  builder = pqApplicationCore::instance()->getObjectBuilder();
  vtkSMProxy* sphere_proxy = builder->createProxy("sources", "SphereSource", server, "Sphere1");
  vtkSMPropertyHelper(sphere_proxy, "radius").Set(20);  
  //pqPVApplicationCore::applyPipeline();
  sphere_proxy->UpdateVTKObjects();

But it has not worked, what could be wrong?

what did not work ?

In any case, here is how to “Apply” with older version of ParaView:

 pqServer* server = pqActiveObjects::instance().activeServer();
 const auto* builder = pqApplicationCore::instance()->getObjectBuilder();
 pqPipelineSource* source = builder.createSource("sources", "SphereSource", server);
 proxy = source->getProxy();
 vtkSMPropertyHelper(proxy, "radius").Set(20);
 proxy->UpdateVTKObjects();
 source->updatePipeline();
 source->setModifiedState(pqProxy::UNMODIFIED);

Mathieu, it creates a menu, with an Apply button to click

Could this be achieved without creating any menus?

Do you mean that it create a source that is visible in the pipeline ?

Yes, this is what it does. You do not want that ?

I would like to skip the user interface and have a sphere created with C++ code only, without any user interface actions

source->setModifiedState(pqProxy::UNMODIFIED); should take care of that.

With this line of code I have the picture on the screenshot above