<div dir="ltr"><div><div><div>Hi,<br></div>I don't know exactly what happened, but it works now. I can launch my own model from the plugin.<br><br></div>This is the final code :<br><br>model = ModelerAlgorithm.ModelerAlgorithm.fromFile(file_path)<br>model.provider = Processing.modeler<br>Processing.modeler.algs.append(model)<br>command_line = model.commandLineName()<br>Processing.algs['model'][command_line] = model<br>return command_line<br><br></div><div>runalg shows by default the QgsMessageBar. We will see if we need it or if we need to change processing.<br></div>Thanks again Victor.<br><div class="gmail_extra"><br><div class="gmail_quote">2015-06-22 17:28 GMT+02:00 Etienne Trimaille <span dir="ltr"><<a href="mailto:etienne.trimaille@gmail.com" target="_blank">etienne.trimaille@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>Hi Victor,<br><br>Thanks for the answer. I maybe the first one, but I need to launch a model in the InaSAFE plugin and I don't want to write by hand the equivalent in python :)<br>I tried your code above :<span><br><br><span>model</span> = ModelerAlgorithm.fromFile("Path/to/your/<span>model</span>/file")<br>
<span>model</span>.provider = <span>Processing</span>.modeler<br>
<span>Processing</span>.modeler.algs.append(<span>model</span>)<br><br></span>But I can't launch it with runalg, I got 'Algorithm not found', so I add this :<br>Processing.algs['model'][model.commandLineName()] = model<br><br></div><div>I can see it with processing.alglist now.<br><br></div><div>But I can't launch it with processing.runalg :<br><br>

<p style="margin:0px;text-indent:0px"><span style="font-family:"Courier New,courier"">Traceback (most recent call last):<br>  File "/home/etienne/.qgis2/python/plugins/inasafe/safe/routing/gui/routing_dialog.py", line 210, in accept<br>    None)<br>  File "/home/etienne/.qgis2/python/plugins/processing/tools/general.py", line 71, in runalg<br>    alg = Processing.runAlgorithm(algOrName, None, *args)<br>  File "/home/etienne/.qgis2/python/plugins/processing/core/Processing.py", line 277, in runAlgorithm<br>    alg = alg.getCopy()<br>  File "/home/etienne/.qgis2/python/plugins/processing/modeler/ModelerAlgorithm.py", line 169, in getCopy<br>    newone.defineCharacteristics()<br>  File "/home/etienne/.qgis2/python/plugins/processing/modeler/ModelerAlgorithm.py", line 208, in defineCharacteristics<br>    modelOutput = copy.deepcopy(alg.algorithm.getOutputFromName(out))<br>  File "/home/etienne/.qgis2/python/plugins/processing/modeler/ModelerAlgorithm.py", line 110, in algorithm<br>    self._algInstance = ModelerUtils.getAlgorithm(self.consoleName).getCopy()<br>AttributeError: 'NoneType' object has no attribute 'getCopy'</span></p><br>Do you have an idea ?<br><br></div><div>Regards,<br></div><div>Etienne<br></div><div><p style="margin:0px;text-indent:0px"><br></p><p style="margin:0px;text-indent:0px"><span style="font-family:"Courier New,courier""></span></p></div><div><div><br></div></div></div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">2015-06-08 16:28 GMT+02:00 Victor Olaya <span dir="ltr"><<a href="mailto:volayaf@gmail.com" target="_blank">volayaf@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You can use the instance of ModelerAlgorithmProvider that is stored in<br>
the Processing object.<br>
<br>
Like this:<br>
<br>
model = ModelerAlgorithm.fromFile("Path/to/your/model/file")<br>
model.provider = Processing.modeler<br>
Processing.modeler.algs.append(model)<br>
<br>
That will add your model to the list of available ones<br>
<br>
I guess you are the first one asking for this...and this is the best<br>
solution i can think of so far :-)<br>
<br>
Let me know if that works...<br>
<br>
I hope it helps<br>
<div><div><br>
<br>
<br>
2015-06-08 15:35 GMT+02:00 Etienne Trimaille <<a href="mailto:etienne.trimaille@gmail.com" target="_blank">etienne.trimaille@gmail.com</a>>:<br>
> Hi,<br>
><br>
> I'm working on a plugin and I need to use my own model inside.<br>
> I know how to add a new algorithm in processing but I didn't find something<br>
> on how to add a model to processing.<br>
><br>
> Is there a way to ship my model with the plugin ?<br>
> Or do I need to copy manually my model into the processing models folder<br>
> with Python ?<br>
><br>
> I saw the ModelerAlgorithmProvider (like the AlgorithmProvider) but I not<br>
> sure if I can do what I want with it.<br>
><br>
><br>
> Thanks,<br>
> Etienne<br>
><br>
</div></div>> _______________________________________________<br>
> Qgis-developer mailing list<br>
> <a href="mailto:Qgis-developer@lists.osgeo.org" target="_blank">Qgis-developer@lists.osgeo.org</a><br>
> <a href="http://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">http://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div></div>