<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Thanks for that. I also found a tutorial by Nathan Woodrow which
explains how to do custom functions.</p>
<p><a class="moz-txt-link-freetext" href="https://woostuff.wordpress.com/2015/05/21/accessing-composer-item-properties-via-custom-expressions-in-qgis/">https://woostuff.wordpress.com/2015/05/21/accessing-composer-item-properties-via-custom-expressions-in-qgis/</a><br>
</p>
<div class="moz-cite-prefix">On 5/08/21 12:51 am, Stefan Giese
(WhereGroup) wrote:<br>
</div>
<blockquote type="cite"
cite="mid:e6eba827-832b-0c60-72cd-b4c2857c8f6d@wheregroup.com">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<p>here is a function which does the job. It's a bit more generic,
you have to pass the layoutname and the itemID to get the text:</p>
<p><i>from qgis.core import *</i><i><br>
</i><i>from qgis.gui import *</i><i><br>
</i><i><br>
</i><i>@qgsfunction(args='auto', group='Custom')</i><i><br>
</i><i>def get_layout_textitem(layoutTitle, itemId, feature,
parent):</i><i><br>
</i><i> """</i><i><br>
</i><i> Gets the text from a labelitem in the layout with the
name layoutTitle.</i><i><br>
</i><i> <h2>Example usage:</h2></i><i><br>
</i><i> <ul></i><i><br>
</i><i> <li>get_layout_textitem('Layout 1', 'text1')
-> 'lorem ipsum</li></i><i><br>
</i><i> </ul></i><i><br>
</i><i> """</i><i><br>
</i><i><br>
</i><i> project = QgsProject.instance()</i><i><br>
</i><i> projectLayoutManager = project.layoutManager()</i><i><br>
</i><i> layout =
projectLayoutManager.layoutByName(layoutTitle)</i><i><br>
</i><i><br>
</i><i> fileNameLabel = layout.itemById(itemId)</i><i><br>
</i><i> fileNameText = fileNameLabel.text() </i><i><br>
</i><i> return fileNameText</i></p>
<p><i><img src="cid:part1.3912BC80.8989B42F@gmail.com" alt=""
class=""></i></p>
<div class="moz-cite-prefix">Am 04.08.2021 um 14:06 schrieb
Patrick Dunford:<br>
</div>
<blockquote type="cite"
cite="mid:f138d57d-0537-64c6-4bee-18071a88489a@gmail.com">layoutTitle
= "Landscape 16:9 Header Nav Copyright Filename 2021" <br>
<br>
project = QgsProject.instance() <br>
projectLayoutManager = project.layoutManager() <br>
layout = projectLayoutManager.layoutByName(layoutTitle) <br>
<br>
fileNameLabel = layout.itemById('Filename') <br>
fileNameText = fileNameLabel.text() </blockquote>
<pre class="moz-signature" cols="72">--
Mit freundlichen Grüßen
Stefan Giese
Projektleiter/Consultant
************************************************************
Aufbau von Geodateninfrastrukturen mit Open-Source-Software
FOSS Academy 5 Tage-Kompaktkurs „Sommerschule 2021“
Jetzt anmelden: <a class="moz-txt-link-freetext" href="https://foss-academy.com/kompaktkurse/" moz-do-not-send="true">https://foss-academy.com/kompaktkurse/</a>
*************************************************************
WhereGroup GmbH
Schwimmbadstr. 2
79100 Freiburg
Germany
Fon: +49 (0)761 / 519 102 - 61
Fax: +49 (0)761 / 519 102 - 11
<a class="moz-txt-link-abbreviated" href="mailto:stefan.giese@wheregroup.com" moz-do-not-send="true">stefan.giese@wheregroup.com</a>
<a class="moz-txt-link-abbreviated" href="http://www.wheregroup.com" moz-do-not-send="true">www.wheregroup.com</a>
Geschäftsführer:
Olaf Knopp, Peter Stamm
Amtsgericht Bonn, HRB 9885</pre>
</blockquote>
</body>
</html>