When you use forms.ask_for_string() you can only collect one string input at a time.
I want to collect 2 ( key and the value of the parameter in my case) at a time.
Right now the procces from the user end looks like this:
input 1st string → click ok → input 2nd string → click ok → script continue to run…
I want it to be:
input 1st string & 2nd string-> click ok → script continue to run…
Script to open the form, fetch the input and print it:
import os
import wpf
from System.Windows import Window
from pyrevit import revit
# Create a class for the custom form
class CustomForm(Window):
def __init__(self):
xaml_path = os.path.join(os.path.dirname(__file__), 'CustomForm.xaml')
wpf.LoadComponent(self, xaml_path)
# Handler for the OK button
def OkButton_Click(self, sender, e):
input_value_1 = self.InputValue1TextBox.Text
input_value_2 = self.InputValue2TextBox.Text
# Do something with the inputs
self.DialogResult = True # Set the dialog result as true to close the window
self.Close()
# Handler for the Cancel button
def CancelButton_Click(self, sender, e):
self.DialogResult = False # Set the dialog result as false to indicate cancellation
self.Close()
# Main pushbutton logic
def main():
custom_form = CustomForm()
# Show the form and capture the dialog result
if custom_form.ShowDialog():
input_value_1 = custom_form.InputValue1TextBox.Text
input_value_2 = custom_form.InputValue2TextBox.Text
# Process the input values here
# For example, print them
print("Input Value 1:", input_value_1)
print("Input Value 2:", input_value_2)
with revit.Transaction('Use Custom Form'):
main()
With this you can use the “input_value_1” and “input_value_2” as variables for the rest of your script.