Thanks for that. I also found a tutorial by Nathan Woodrow which explains how to do custom functions.

https://woostuff.wordpress.com/2015/05/21/accessing-composer-item-properties-via-custom-expressions-in-qgis/

On 5/08/21 12:51 am, Stefan Giese (WhereGroup) wrote:

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:

/from qgis.core import *//
//from qgis.gui import *//
//
//@qgsfunction(args='auto', group='Custom')//
//def get_layout_textitem(layoutTitle, itemId, feature, parent)://
//    """//
//    Gets the text from a labelitem in the layout with the name layoutTitle.//
//    <h2>Example usage:</h2>//
//    <ul>//
//      <li>get_layout_textitem('Layout 1', 'text1') -> 'lorem ipsum</li>//
//    </ul>//
//    """//
//
//    project = QgsProject.instance()//
//    projectLayoutManager = project.layoutManager()//
//    layout = projectLayoutManager.layoutByName(layoutTitle)//
//
//    fileNameLabel = layout.itemById(itemId)//
//    fileNameText = fileNameLabel.text() //
//    return fileNameText/

//

Am 04.08.2021 um 14:06 schrieb Patrick Dunford:
layoutTitle = "Landscape 16:9 Header Nav Copyright Filename 2021"

project = QgsProject.instance()
projectLayoutManager = project.layoutManager()
layout = projectLayoutManager.layoutByName(layoutTitle)

fileNameLabel = layout.itemById('Filename')
fileNameText = fileNameLabel.text()
--
Mit freundlichen Grüßen
Stefan Giese
Projektleiter/Consultant
************************************************************
Aufbau von Geodateninfrastrukturen mit Open-Source-Software
FOSS Academy 5 Tage-Kompaktkurs „Sommerschule 2021“
Jetzt anmelden:https://foss-academy.com/kompaktkurse/ *************************************************************
WhereGroup GmbH
Schwimmbadstr. 2
79100 Freiburg
Germany

Fon: +49 (0)761 / 519 102 - 61
Fax: +49 (0)761 / 519 102 - 11

[email protected]
www.wheregroup.com
Geschäftsführer:
Olaf Knopp, Peter Stamm
Amtsgericht Bonn, HRB 9885
_______________________________________________
Qgis-user mailing list
[email protected]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

Reply via email to