Enter String and run

I want to change the strin and be able to run the whole Script

import clr
clr.AddReference('System.Windows.Forms')
clr.AddReference('System.Drawing')

from System.Drawing import Point
from System.Windows.Forms import Application, Button, Form, Label, TextBox

class SimpleTextBoxForm(Form):
    def __init__(self):
        self.Text = "Examp"

        self.Width = 220
        self.Height = 200

        self.textbox = TextBox()
        self.textbox.Text = IN[0]
        self.textbox.Location = Point(25, 55)
        self.textbox.Width = 150

        self.button1 = Button()
        self.button1.Text = 'Press Me'
        self.button1.Location = Point(25, 125)
        self.button1.Click += RUN

        self.AcceptButton = self.button1

        self.Controls.Add(self.textbox)
        self.Controls.Add(self.button1)

    def update(self, sender, event):
        self.label.Text = self.textbox.Text
        self.label.Text = self.textbox1.Text

form = SimpleTextBoxForm()
Application.Run(form)

@Christhian Not sure what you need. See if this points you in the right direction:

import clr
clr.AddReference('System.Windows.Forms')
clr.AddReference('System.Drawing')

from System.Drawing import Point
from System.Windows.Forms import Application, Button, Form, Label, TextBox

class SimpleTextBoxForm(Form):
    def __init__(self):
        self.Text = "Examp"

        self.Width = 220
        self.Height = 200

        self.textbox = TextBox()
        self.textbox.Text = IN[0]
        self.textbox.Location = Point(25, 55)
        self.textbox.Width = 150

        self.button1 = Button()
        self.button1.Text = 'Press Me'
        self.button1.Location = Point(25, 125)
        
        self.AcceptButton = self.button1

        self.Controls.Add(self.textbox)
        self.Controls.Add(self.button1)
        
        self.values = []
        self.button1.Click += self.update

    def update(self, sender, event):
        self.values.append(self.textbox.Text)
        self.Close()

form = SimpleTextBoxForm()
Application.Run(form)

OUT = form.values
2 Likes

Hi @Christhian ,

If you are running something like this from the Dynamo built into Revit/ Civil3D you can also use the Dynamo Player for inputs.

@AmolShah

If it works as expected, but I would like it not to be deleted once it is executed, for example I would like to put A1, A2, A3 without it being deleted and every time I put a text it is executed

Animation

It would be similar to Dynamo Player
Animation2

@Christhian Something like this?
Animation

import clr
clr.AddReference('System.Windows.Forms')
clr.AddReference('System.Drawing')

from System.Drawing import Point
from System.Windows.Forms import Application, Button, Form, Label, TextBox

class SimpleTextBoxForm(Form):
	def __init__(self):
		self.Text = "Example"

		self.Width = 220
		self.Height = 200

		self.textbox = TextBox()

		self.textbox.Location = Point(25, 55)
		self.textbox.Width = 155

		self.button1 = Button()
		self.button1.Text = 'Add'
		self.button1.Location = Point(25, 125)

		self.button2 = Button()
		self.button2.Text = 'Close'
		self.button2.Location = Point(110, 125)

		self.Controls.Add(self.textbox)
		self.Controls.Add(self.button1)
		self.Controls.Add(self.button2)

		self.values = []
		self.button1.Click += self.update
		self.button2.Click += self.close

	def update(self, sender, event):
		if self.textbox.Text != "":
			self.values.append(self.textbox.Text)
			self.textbox.Text = ""

	def close(self, sender, event):
		self.Close()

form = SimpleTextBoxForm()
Application.Run(form)

OUT = form.values
3 Likes

Thank you so much @AmolShah

But every time I put a word I would like the script to be executed, what it currently does is ADD store and just when I close it executes; I would like it to be executed as in the first code, only that it will not be deleted every time it is executed

Why not just use Dynamo Player?

1 Like

In Dynamo Player it works very well, it is just that I want to understand a little more python, I think Amol has made an excellent answer but it is not exactly what I want I suppose that I am not understood very well by the idiom.

I want that as in Dynamo Player once I change the type of text it is executed
A1 → RUN
A2-> RUN
A3-> RUN
but it does not kill that it closes every time it is executed

Hi @Christhian,

What about setting the Dynamo script to “automatic”?

what I want is that the window does not disappear once it is executed

I would like to give it a value and execute change the value and execute without having to open it again

Animation9

That would require a different UI, one with a ‘run’ button and a ‘finish’ button, just as @AmolShah posted.

However you would need to add a transaction to the actions that occur on each press of the run button.

@jacob.small Thanks for your answer, so if it is possible to do it, could you help me by recommending a book or guide that I could use.

I don’t have anything on hand, but effectively you’d need to wrap your code int he ‘update’ section of the code @AmolShah posted, only iterate over the file when you push update.

This gets difficult and cumbersome as your code runs.

1 Like

Thank you
When I understand a little more about python I hope I can achieve it, thank you very much for all the answers I will leave the @AmolShah answer marked, which was the closest to what I was trying to do.

2 Likes