Ah, sorry. I misunderstood what it does - I was thinking I could specify an arbitrary groupName which it would create and load the layers in projectFilePath into. groupName is actually meant to be an existing group in projectFilePath, and it loads that.
Thanks. > > Date: Mon, 19 Sep 2022 09:08:02 +0200 > From: Johannes Kr?ger (WhereGroup) <johannes.kroe...@wheregroup.com> > To: qgis-developer@lists.osgeo.org > Subject: Re: [QGIS-Developer] Does > QgsProject.instance().createEmbeddedGroup() work? > Message-ID: <e2363bee-8f04-e078-4991-d704de838...@wheregroup.com> > Content-Type: text/plain; charset="utf-8"; Format="flowed" > > Hi Alister, > > > https://qgis.org/pyqgis/master/core/QgsProject.html#qgis.core.QgsProject.createEmbeddedGroup > and > > https://api.qgis.org/api/classQgsProject.html#ad2e059da29ebfc32096367abb78da46c > say it should return a QgsLayerTreeGroup so I guess it is broken, at > least documentation-wise. > > https://api.qgis.org/api/qgsproject_8cpp_source.html#l03274 on the other > hand hints at several "return nullptr" so it returning None is by > design. The code seems fairly readable and even has useful comments so > maybe check if one of the cases might be true in your testcase. > > Cheers, Hannes > > Am 19.09.22 um 05:40 schrieb Alister Hood via QGIS-Developer: > > Hi, I want to programmatically embed a project, like I can in the gui > > with "Layer>embed layers and groups." > > > > I thought QgsProject.instance().createEmbeddedGroup() was what I > > needed, but it doesn't seem to work - see below.? Am I completely off > > track, or is it broken? > > > > Thanks. > > > > path='/home/alister/testtoembed.qgs' > > project = QgsProject.instance() > > project.read(path) > > True > > project.clear() > > newGroup = QgsLayerTreeGroup() > > type(newGroup) > > <class 'qgis._core.QgsLayerTreeGroup'> > > newGroup = QgsProject.instance().createEmbeddedGroup('test', path, []) > > type(newGroup) > > <class 'NoneType'> > > > > _______________________________________________ > > QGIS-Developer mailing list > > QGIS-Developer@lists.osgeo.org > > List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer > > Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer > > -- > Johannes Kr?ger / GIS-Entwickler/-Berater >
_______________________________________________ QGIS-Developer mailing list QGIS-Developer@lists.osgeo.org List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer