简体   繁体   English

将on_click选项用于REVIT RPW flexform按钮

[英]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. 我知道按钮单击的默认值为FlexForm.get_values,我正在尝试调用自己的函数。 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 您需要创建一个继承自System.Windows.Window的新类。

    • why? 为什么? I don't know 我不知道
  2. You need to add the @staticmethod decorator before each function 您需要在每个函数之前添加@staticmethod装饰器

    • why? 为什么? I don't know 我不知道
  3. You need to specify the paramter sender and e 您需要指定参数sendere

    • 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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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