3

I am trying to build a processing script using "Create new script from template". I want the user to have the opportunity to insert multiple values into one field.

def initAlgorithm():        
   self.addParameter(
        QgsProcessingParameterNumber(
            self.INPUT3,
            self.tr('Insert Numbers')
         )
...
...
def processAlgorithm():
   source3=self.parameterAsInt(
       parameters,
       self.INPUT3,
       context)

I know that QgsProcessingParameterNumber allows inserting only one value and there is no allowMultiple option. Which command should I use to get data like [1,2,3,8,7] from one inputbox?

QGIS v3.20.

1
  • I added the parameters as QgsProcessingParameterString separated by commas then transformed it to integers.
    – Annie S.
    Dec 14 '21 at 14:09
3

Use QgsProcessingParameterString and split the string by comma as below:

def initAlgorithm():        
    self.addParameter(
        QgsProcessingParameterString(self.INPUT3,self.tr('Insert Numbers'))

...

def processAlgorithm():
    source3 = self.parameterAsString(parameters, self.INPUT3, context)

    numbers = source3.split(",")
2
  • I already did that. I wanted to know if there was another way but thank you!
    – Annie S.
    Dec 20 '21 at 9:37
  • I am aware of that. It's better to add as a proper answer. People don't tend to read comments. Jan 2 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.