Prompt user Input

Hi everyone.
I am developing a simple script that basically duplicates (AsDependent) user selected views (through Revit project browser) a certain amount of times. I got it to work (statically) but I would like the user to input how many times the view needs to be duplicated.

Is there any way of prompting the user to make an input so I can assign it to a variable which will be on my loop transaction? I couldn’t find anything in the Revit API that prompts the user to give an input, but maybe I am missing something here?
Can WinForms be a solution? I just want to be sure about my possibilities before I start digging on another software that I don’t know about :laughing:

from Autodesk.Revit.DB import View, Document
from Autodesk.Revit.DB.Structure import AnalyticalModel
from Autodesk.Revit.UI import TaskDialog 
import Autodesk.Revit.DB as DB
import Autodesk.Revit.UI as UI

uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document

# Taken from the RevitPythonShell
def get_selected_elements(doc):
    """Get selected elements in the Revit UI"""
    return [doc.GetElement(id)
                for id in __revit__.ActiveUIDocument.Selection.GetElementIds()]

# Assign the selected elements to a variable
selection = get_selected_elements(doc)

# Check if user selected any views previously
if len(selection) == 0:
	# Show a dialog if the user didn't choose any view 
	UI.TaskDialog.Show("Duplicate Views", "Choose one or more views first.", UI.TaskDialogCommonButtons.Ok)

# Creating an transaction object
t = DB.Transaction(doc, "TVA-Duplicate View")
# Starting a transaction

# Duplicate the selected view
for view in selection:
	for repetition in range(3):
		duplicated_views = view.Duplicate(DB.ViewDuplicateOption.AsDependent)
# Closes the transaction

Thank you in advance :slight_smile:

Take a look at “Asking For Text Input” section here and see if this helps :slight_smile:

1 Like

Thank you very much, I will have a look :slight_smile:

1 Like

It worked like charm. The forms module is really useful, thank you @eirannejad

By the way, I didn’t see any button to click and mark your answer as the “solution”. Is this something that forum creators want/don’t want to implement? Or is this functionality just not available?
It would be much easier for someone else to find the answer to the OP.


@jcarolino You could built on top of that one too. Pimp it a bit.
Especially as almost everything is already in place. #beLazy

@Jean-Marc if you meant the script posted above, yes it is my intention to pimp it further.
When finished I can post it here if anyone is interested (I am learning as I go so it might take a while). :grimacing:

no I was meaning pimping the builtin fonctiunality of pyRevit instead fo recreating your whole script from scratch

I did not remember that section in Notion. Very nice. Don’t have to go through the module to figure that out!

@jcarolino Oh yeah. I just actiavted the option :smiley: Thanks for letting me know. Feel free to mark the Solution here