<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Hi list -</p>
<p>I have a small "startup.py" project - The goal is to register
every time a user opens af layer in QGIS in a organization with
lots of QGIS users. The end goal is to find data sources that are
maintained but actually not used.</p>
<p>To that purpose I created the following script as a "proof of
concept":</p>
<p><b><font face="monospace">from qgis.core import QgsProject,
QgsMessageLog, Qgis, QgsLayerTreeLayer<br>
from datetime import datetime<br>
import os<br>
<br>
<br>
def onAddedChildren(node, indexFrom, indexTo):<br>
<br>
for i in range(indexFrom, indexTo+1):<br>
child = node.children()[i]<br>
if isinstance(child, QgsLayerTreeLayer): <br>
layer = child.layer()<br>
name = ''<br>
uri = ''<br>
if (layer):<br>
name = layer.name()<br>
datap = layer.dataProvider()<br>
if datap: <br>
uri = datap.dataSourceUri()<br>
strx =
'"{}";"{}";"{}";"{}";"{}"'.format(datetime.today().strftime('%Y-%m-%d
%H:%M:%S'),os.getlogin(),child.name(),name,uri)<br>
with open("d:/tmp/loglag.csv", "a") as g:<br>
g.write(strx+'\n')<br>
<br>
root = QgsProject.instance().layerTreeRoot()<br>
root.addedChildren.connect(onAddedChildren)<br>
</font></b></p>
<p>(I know - I might into trouble with users appending data to the
same file at the same time, but that is solveable) <br>
</p>
<p>The above script works like a charm, when a user add a single
layer using the data source manager. But it partially fails when
opening a project. The layers are registred, but it doesn't
register the uri for the individual layers. I assume the event "<font
face="monospace">addedChildren</font>" is fired before the
layers is fully loaded.</p>
<p>So is there some other event I can use to get my full layer info
? <br>
</p>
<p>-- </p>
<pre class="moz-signature" cols="72">Med venlig hilsen / Kind regards
Bo Victor Thomsen</pre>
</body>
</html>