简体   繁体   中英

Using the on_click option for a REVIT RPW flexform button

I've been stumped by this for hours, can someone point me in the right direction?

I know the default for a button click is FlexForm.get_values, I'm trying to call my own functions. I can't figure out where I'm going wrong.

I know my mistake is in these two lines:

 Button('Proceed', on_click=proceed_pressed()),\
 Button('Cancel', on_click=cancel_clicked())\

thank you in advance.....full code below.....

# -*- coding: utf-8 -*-
import rpw
from rpw import revit, db, ui, DB, UI
import sys
from rpw.ui.forms import FlexForm, Label, ComboBox, TextBox, TextBox, Separator, Button, CheckBox

def proceed_pressed():
    print "proceed clicked"

def cancel_clicked():
    print "canceled clicked"


components = [\
 Label('Before Labeling Outlets:'),\
 CheckBox('checkbox0', 'Audit Outlets, Zones, and Floors BEFORE writing Outlet IDs',default=True),\
 CheckBox('checkbox1', 'Send Audit results to Excel',default=False),\
 Separator(),\
 Label('Pick Outlet Labeling Options:'),\
 ComboBox('combobox2', {'Label with ROOM NUMBERS': 1, 'Label with SEQUENTIAL NUMBERS': 2}),\
 Separator(),\
 CheckBox('checkbox3', 'Include Zone Information (IDF Room)', default=True),\
 CheckBox('checkbox4', 'Include Floor Number', default=True),\
 Separator(),\
 Button('Proceed', on_click=proceed_pressed()),\
 Button('Cancel', on_click=cancel_clicked())\
 ] 

form = FlexForm('Label Outlet', components) 
form.show() 

The below code will work for what you are looking for, with some easy to follow steps to build your own custom class of functions.

  1. You need to create a new class that inherits from System.Windows.Window

    • why? I don't know
  2. You need to add the @staticmethod decorator before each function

    • why? I don't know
  3. You need to specify the paramter sender and e

    • why? I don't know

Sorry I can't give a proper solution.

clr.AddReference("PresentationFramework")
from System.Windows import Window

class ButtonClass(Window):
    @staticmethod
    def proceed_pressed(sender, e):
        print("proceed clicked")

    @staticmethod
    def cancel_clicked(sender, e):
        print("canceled clicked")


from rpw.ui.forms import FlexForm, Label, ComboBox, TextBox, TextBox, Separator, Button, CheckBox

components = [
    Label('Before Labeling Outlets:'),
    CheckBox('checkbox0', 'Audit Outlets, Zones, and Floors BEFORE writing Outlet IDs',default=True),
    CheckBox('checkbox1', 'Send Audit results to Excel',default=False),
    Separator(),
    Label('Pick Outlet Labeling Options:'),
    ComboBox('combobox2', {'Label with ROOM NUMBERS': 1, 'Label with SEQUENTIAL NUMBERS': 2}),
    Separator(),
    CheckBox('checkbox3', 'Include Zone Information (IDF Room)', default=True),
    CheckBox('checkbox4', 'Include Floor Number', default=True),
    Separator(),\
    Button('Proceed', on_click=ButtonClass.proceed_pressed),
    Button('Cancel', on_click=ButtonClass.cancel_clicked)
 ] 

form = FlexForm('Label Outlet', components) 
form.show()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM