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
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)
else:
selection
# Creating an transaction object
t = DB.Transaction(doc, "TVA-Duplicate View")
# Starting a transaction
t.Start()
# Duplicate the selected view
for view in selection:
for repetition in range(3):
duplicated_views = view.Duplicate(DB.ViewDuplicateOption.AsDependent)
print(duplicated_views)
# Closes the transaction
t.Commit()
Thank you in advance