How to make a model available in CLI Python modules

Hello,
I am writing a CLI module and would like to have a model as an input to then use it as vtkPolyData. I have checked the provided example and inspected some of the C++ modules taking a model as input, for example ModelToLabelMap but it is still unclear to me how to do it.
I am trying some code resembling the C++ code but it is not working because ReadData cannot read the ModelNode:

modelNode = slicer.vtkMRMLModelNode()
modelStorageNode = slicer.vtkMRMLModelStorageNode()
modelStorageNode.SetFileName(sys.argv[1]) # sys.argv[1] is the input model provided by the GUI
modelNode = modelStorageNode.ReadData(modelNode)
polyModel = modelNode.getPolyData()

I have two questions:

  1. How can this be achieved in Python? (Apologies if this is obvious, I am just getting started with Slicer).
  2. what is the best way of practically developing a CLI module autogenerated GUI? Currently I am finding myself restarting Slicer every time I modify the GUI xml.

Thank you for any insight,
Luca

Your code snippet is generally OK, it just has a few errors. Something like this should work better:

    import slicer
    modelNode = slicer.vtkMRMLModelNode()
    modelStorageNode = slicer.vtkMRMLModelStorageNode()
    modelStorageNode.SetFileName(sys.argv[1]) # sys.argv[1] is the input model provided by the GUI
    success = modelStorageNode.ReadData(modelNode)
    polydata = modelNode.GetPolyData()

Thank you for the prompt reply, Andras, this is indeed working! I was importing slicer but did not notice the lower ā€˜gā€™.