This code is not displaying any feature in QGIS , so I want to save the temporary layer so that the features can be visible.
extract1 = processing.run("native:extractbylocation", { 'INPUT': layer1, 'PREDICATE': [0],
'INTERSECT': QgsProcessingFeatureSourceDefinition(ribbon.id(), selectedFeaturesOnly=True, featureLimit=-1, geometryCheck=QgsFeatureRequest.GeometryAbortOnInvalid),
'OUTPUT': QgsProcessing.TEMPORARY_OUTPUT})['OUTPUT']
group.addLayer(extract1)
QgsProject.instance().mapLayersByName("extract1") extract1.setName('My Layer')
Best Answer
I'm not sure what you mean by "save the temporary layer", because if you want to save the result, don't use a temporary output! But I guess what you actually want is to add the resulting temporary layer to the project, rename it and add it to a group in the layer tree. To do that you can use the code below:
The code example in the question is incomplete so here is a complete, reproducible example which should be self explanatory to any future readers. You can see in the screenshot how my layer tree is set up. To run this example you would need to only change the layer names.
This example adds the temporary output layer to a group in the layer tree:
The result of this example can be seen below.
This example saves the result to a file location, then loads it into the project and adds it to a group in the layer tree. To run this example you must change both the layer names and the file path to the save location.
The result of this example is below.