<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
span.EpostStil17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="NO-BOK" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-GB">Thanks to the answer to this post <a href="https://gis.stackexchange.com/questions/447362/pyqgis-to-set-masked-symbol-layer-and-mask-source">
https://gis.stackexchange.com/questions/447362/pyqgis-to-set-masked-symbol-layer-and-mask-source</a><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">I managed to set the mask layer in QGIS version 3.28.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">The code is not working In ver. 3.30 due to a change in the QgsSymbolLayerReference class.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">However I’m not able to change the original code so it fits with the new specification<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">I just don’t understand how to set the input parameters to fulfil the requirements in
<a href="https://qgis.org/pyqgis/3.30/core/QgsSymbolLayerReference.html#qgis.core.QgsSymbolLayerReference">
https://qgis.org/pyqgis/3.30/core/QgsSymbolLayerReference.html#qgis.core.QgsSymbolLayerReference</a><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-family:"Courier New""># Set masked symbol layers :  setMaskedSymbolLayers(self, maskedLayers: Iterable[QgsSymbolLayerReference])<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-family:"Courier New"">fileName = "./gpkg/karplantehoyder.gpkg"<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-family:"Courier New"">layer = QgsVectorLayer(fileName, "hoyder", "ogr")<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-family:"Courier New"">layer.loadNamedStyle('./qml/n5hoyder.qml')      # Load qml<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-family:"Courier New"">QgsProject.instance().addMapLayer(layer, False) # Add layer False to be able
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-family:"Courier New"">root.insertLayer(4,layer)                       # to specify a custom position<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-family:"Courier New"">label_settings = layer.labeling().settings()    # Get current settings of the layer<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-family:"Courier New"">text_format = label_settings.format()           # Get text format of the settings<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-family:"Courier New""># old code (working in 3.28)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-family:"Courier New""># text_format.mask().setMaskedSymbolLayers([QgsSymbolLayerReference(layer.id(), QgsSymbolLayerId("", 0))])  # set masked symbol layers *****<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-family:"Courier New""># -- New code<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-family:"Courier New"">linesymbol = QgsLineSymbol()<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-family:"Courier New"">lyr = linesymbol.symbolLayer(0)                 # Trying to get the id of the line layer (hoyder)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-family:"Courier New"">text_format.mask().setMaskedSymbolLayers([layer.id(), lyr.id()])  # set masked symbol layers – not working<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-family:"Courier New""># --<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-family:"Courier New"">label_settings.setFormat(text_format)           # set format<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-family:"Courier New"">layer.labeling().setSettings(label_settings)    # set settings<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-family:"Courier New"">layer.saveStyleToDatabase(layer.name(),'style n5hoyder',True,'')  # Save style in gpkg<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">Anyone who knows how I should write the code marked with *****?<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">Kind regards<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB">Anne<o:p></o:p></span></p>
</div>
</body>
</html>