2 years ago

#77499

test-img

Saverio Vasapollo

Create buttons in loop with different actions - Python

I am working on Dynamo for Revit. My code takes sheet numbers and other info, then creates labels and buttons for each IN element with a for loop. The GUI works fine and I have all the elements in place, but how do I tell each individual button to open a different sheet? See screenshot.

I need to understand the workflow, but here is the code of the loop if it helps:

# Create labels and buttons in loop
    y = 50
    a = 0
    for i in res:
        # creates section name label
        text = str(res[a][0])
        text = text[19:]
        text = text[:-1]
        labelSectionName = Label(Text = text)
        labelSectionName.Parent = self
        labelSectionName.Location = Point(gridColSecName,y)
        labelSectionName.Width = gridWidthSecName
        #labelSectionName.Height = 20
        
        # creates sheet number label
        text = str(res[a][2])
        labelSectionName = Label(Text = text)
        labelSectionName.Parent = self
        labelSectionName.Location = Point(gridColSheetNum,y)
        labelSectionName.Width = 50
        # create button for opening sheet
        button = Button()
        button.Parent = self
        button.Text = "Open Sheet"
        button.Location = Point(gridColButtSheet,y)
        # Register button event
        button.Click += self.?????????????????????????????????????

and this is the code for opening the sheet taken from another script

sheet = UnwrapElement(IN[0])
sheet_action=(IN[1])
output = []

if (str(sheet_action) == "Yes"):
    uidoc.RequestViewChange(sheet)
    output.append("ActiveView set to: " + sheet.Name)
else:
    pass

OUT = sheet_action

enter image description here

python

ironpython

revit-api

0 Answers

Your Answer

Accepted video resources