<div dir="ltr"><div>Hi all</div><div><br></div><div>I am implementing a custom plugin for QGIS Server that uses a QgsServerFilter subclass.</div><div><br></div><div>The purpose of this plugin is to use QGIS Server to respond to `GetPrint` requests. However, I need to pass some runtime parameters to my map layout before handing it over to `GetPrint`.</div><div><br></div><div>I think the place where I should do these preparatory steps, which ultimately include loading some layers and setting some layout variables, is in my `onRequestReady()` method.</div><div><br></div><div>The problem: I need to be able to set properties on the relevant QgsPrintLayout instance, but in order to do that I would need to retrieve it from the current QgsProject instance, and I can't figure out how to get a hold of it.</div><div><br></div><div>Is it possible to get the current instance of QgsProject in the context of QGIS server?</div><div><br></div><div>At first I tried to do it as I would on a plugin for the desktop:</div><div><br></div><div>```</div><div>qgis_project = QgsProject.instance()</div><div>layout_manager = qgis_project.layoutManager()</div><div>my_layout = layout_manager.getLayoutByName("the_name")</div><div># this fails, my_layout is None</div><div>```</div><div><br></div><div>This approach does not work, as the resulting qgis_project is not the one I am using in my request.</div><div><br></div><div>Then I searched through the properties of `QgsServerInterface`, hoping to find some sort of `getCurrentProject()` method - but this does not seem to exist.</div><div><br></div><div>I also tried loading the project from disk in my plugin with</div><div><br></div><div>```</div><div>current_project = QgsProject.instance()</div><div>current_project.read(server_iface..configFilePath())</div><div>```</div><div><br></div><div>This second approach does allow me to load up the project, but any changes I set at runtime are not propagated to subsequent handlers in the QGIS Server workflow, meaning that the `GetPrint` handler does not see my changes to the project.</div><div><br></div><div>I don't want to save the changes, just set them at runtime and use them. This is because other (potentially parallel) requests will also need to modify the aforementioned layout in order to customize their printing needs.</div><div><br></div><div>Is it at all possible to do what I am trying to do? Or is there maybe a more proper way?</div><div><br></div><div>Thanks in advance</div><br><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">___________________________ ___ __<br>Ricardo Garcia Silva</div></div>