Function arguments Python

is it possible to affect a value from a list to an argument with a loop?
image

args[i]=Lst[i]

Hello,

You can now call myfunc(**args) : is that what you are looking for ?

I’ve got a lot of arguments to specify, so i would like to make a loop to enter a value in each arguments, on the captur, you can see in args there is a dictionary with a lot of thing like client…
in list i know how i can do an iteration to enter the value in a list, but in this dictionary, i don’t know how i can do this iteration.

How do you want to enter the value for each key? With a prompt for each value? A single dialog box where you can enter them all? A separate list of values?

on the capture you can see the list:
Lst=['client','projet','contact','tel','Devis','Date','Prestation']
in the variable array, you can see the “old-style instance or ProjArg”: args, that it contain 34 Item in a dictionary: Client,Projet,Contact,Tel…
i would like to put the first item of the list in the first item of args, the second in the second…
but i don’t know how i can call the ‘Client’ of the dictionary of args…

If I understand the question correctly:

Dictionaries (in Python, Ironpython 2.7) do not preserve order, so you cannot use i. Somewhere, you will have to associate the list index i with a dictionary key of args. At that point you may as well turn Lst into a dict and just use dict.update().

Hello,
let’s change our approach, how can I create in Init Method, attribute with a loop,
in my document, i’ve got a lot of Document user text, and for my Eto form, i have to create one argument for one Document user text, so… it’s the same thing for each argument:

def __init__(self):
        
        if rs.GetDocumentUserText('DocUserText1'):
            self.DocUserText1=rs.GetDocumentUserText('DocUserText1')
        else:
            self.DocUserText1 = 'DocUserText1'
            
        if rs.GetDocumentUserText('DocUserText2'):
            self.DocUserText2=rs.GetDocumentUserText('DocUserText2')
        else:
            self.DocUserText2 = 'DocUserText2'
....

i’ve maybe 10 doc user text, so with a loop, it will be better, no?

reverse too!!
when all my arguments are filling, i would like to put them in a doc usertext:

if rs.GetDocumentUserText('DocUserText1')!=self.DocUserText1:
    self.DocUserText1=rs.GetDocumentUserText('DocUserText1')
if rs.GetDocumentUserText('DocUserText2')!=self.DocUserText2:
    self.DocUserText1=rs.GetDocumentUserText('DocUserText2')

Hello,

I think I am failing to understand what you are trying to do and why, but does this help?

import rhinoscriptsyntax as rs

class OnlyForPeace(object):
    def __init__(self, args = None):
        for arg in args:
            self.__dict__[arg] = arg
        print self.__dict__
        
obj = OnlyForPeace(['bob','sue'])

I think, that the fact of not knowing what object programming is, I do not program in the right way, and do not use the method and class functions in the right way, and that without good training, I would not advance and wastes your time …

my program is however simple, I want to display a form with text boxes and check boxes, and all its text boxes and check boxes would be pre-filled with User texts documents.

I already have scripts that allow me to find the name of the client, the project name, the surfaces, and the dimensions of the projects, but they are all separated from each other, and I would like to collect them on the same form .

to follow an extract of my program to see the general architecture which I copied on an example of creation of Eto form on GitHub.
but I must not have understood the interest of the class.
it works, but fill in all the attributes one by one …
I find it strange.

# coding: utf-8
# Imports
import Rhino
import scriptcontext as sc
import Rhino.UI
import Eto.Drawing as drawing
import Eto.Forms as forms
import rhinoscriptsyntax as rs

class ProjArg():
    
    # Initializer
    def __init__(self):
        
        if rs.GetDocumentUserText('Client'):
            self.Client=rs.GetDocumentUserText('Client')
        else:
            self.Client = 'client'
            
        if rs.GetDocumentUserText('Projet'):
            self.Projet=rs.GetDocumentUserText('Projet')
        else:
            self.Projet = 'projet'
######################################################
######### repeat lines above for all subsequent Args about 15
#######################################################

class Projforms(forms.Dialog[bool]):
    
    # Initializer
    def __init__(self, args):
        self.Args = args
        # Initialize dialog box
        self.Title = 'FORMULAIRE PROJET'
        self.Padding = drawing.Padding(5)
        # Create layout
        layout = forms.DynamicLayout()
        layout.Padding = drawing.Padding(5)
        layout.Spacing = drawing.Size(5, 5)
        layout.AddRow(self.Client())
        layout.AddRow(self.LineContact())
        layout.AddRow(None) # spacer
        layout.AddRow(self.LineSurfaceMOD())
        layout.AddRow(None) # spacer
        layout.AddRow(None) # spacer
        layout.AddRow(self.Prest())
        layout.AddRow(None) # spacer
        layout.AddRow(self.CreateButtons())
        # Set the dialog content
        self.Content = layout
        
    #CLIENT & PROJET
    def Client(self):
        self.label_client = forms.Label(Text = 'Client:')
        self.textbox_client = forms.TextBox(SelectedText=self.Args.Client)
        self.label_projet=forms.Label(Text = 'Projet:')
        self.textbox_projet= forms.TextBox(SelectedText=self.Args.Projet)
        self.label_delais = forms.Label(Text = 'Délais:')
        self.textbox_delais = forms.TextBox(Text=self.Args.Date)
        self.label_devis=forms.Label(Text = 'Devis n°:')
        self.textbox_devis= forms.TextBox(Text=str(self.Args.Devis))
        layout = forms.DynamicLayout()
        layout.Spacing = drawing.Size(5, 5)
        layout.AddRow(self.label_client,self.textbox_client,self.label_projet,self.textbox_projet)
        layout.AddRow(self.label_delais,self.textbox_delais,self.label_devis,self.textbox_devis)
        return layout

def TestEtoform():
    args = ProjArg()
    dialog = Projforms(args)
    rc = dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)
    if rc:
        dialog.ApplyModif()

Do you have a sample file with the necessary user data input into it?

it’s just a test file:Ex.3dm (33.7 KB)

No idea?

Something like this?

# coding: utf-8
# Imports
import Rhino
import scriptcontext as sc
import Rhino.UI
import Eto.Drawing as drawing
import Eto.Forms as forms
import rhinoscriptsyntax as rs

keys = ['Client', 'Projet', 'Date', 'Delais', 'Devis', 'LineContact', 'LineSurfaceMOD', 'Prest']

class ProjArg():
    
    # Initializer
    def __init__(self):
        global keys
        for key in keys:
            if rs.GetDocumentUserText(key):
                self.__dict__[key] = rs.GetDocumentUserText(key)
            else:
                self.__dict__[key] = key.lower()
            

class Projforms(forms.Dialog[bool]):
    
    # Initializer
    def __init__(self, args):
        self.Args = args
        # Initialize dialog box
        self.Title = 'FORMULAIRE PROJET'
        self.Padding = drawing.Padding(5)
        # Create layout
        layout = forms.DynamicLayout()
        layout.Padding = drawing.Padding(5)
        layout.Spacing = drawing.Size(5, 5)
        layout.AddRow(self.Client())
        layout.AddRow(args.LineContact)
        layout.AddRow(None) # spacer
        layout.AddRow(args.LineSurfaceMOD)
        layout.AddRow(None) # spacer
        layout.AddRow(None) # spacer
        layout.AddRow(args.Prest)
        layout.AddRow(None) # spacer
#        layout.AddRow(self.CreateButtons())
        # Set the dialog content
        self.Content = layout
        
    #CLIENT & PROJET
    def Client(self):
        self.label_client = forms.Label(Text = 'Client:')
        self.textbox_client = forms.TextBox(SelectedText=self.Args.Client)
        self.label_projet=forms.Label(Text = 'Projet:')
        self.textbox_projet= forms.TextBox(SelectedText=self.Args.Projet)
        self.label_delais = forms.Label(Text = 'Délais:')
        self.textbox_delais = forms.TextBox(Text=self.Args.Date)
        self.label_devis=forms.Label(Text = 'Devis n°:')
        self.textbox_devis= forms.TextBox(Text=str(self.Args.Devis))
        layout = forms.DynamicLayout()
        layout.Spacing = drawing.Size(5, 5)
        layout.AddRow(self.label_client,self.textbox_client,self.label_projet,self.textbox_projet)
        layout.AddRow(self.label_delais,self.textbox_delais,self.label_devis,self.textbox_devis)
        return layout

def TestEtoform():
    args = ProjArg()
    dialog = Projforms(args)
    rc = dialog.ShowModal(Rhino.UI.RhinoEtoApp.MainWindow)
    if rc:
        dialog.ApplyModif()
        
if __name__ == '__main__':
    TestEtoform()

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)

yes thank you, i think i found nearly the same… but more complicated!
i searche now to make the return, if i change one thing in a txtbox, and validate, it change the document user text… with a loop of course! so i have to put all self.textbox_"Something".Text in a list or dictionary…