我对IronPython比较陌生。 我可以得到被选中的单选按钮,但我不知道如何在脚本中传递 "logoToUpdate "这个变量。 另外,有没有更精简的方法来完成这种类型的表单?
这是我的代码。 最后一行是我在logoToUpdate变量中没有得到任何文本的地方。
import clr
clr.AddReference("RevitAPIUI")
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
from System.Drawing import Color, Font, FontStyle, Point
from System.Windows.Forms import (Application, BorderStyle, Button, CheckBox,
Form, Label, Panel, RadioButton)
class CountForm(Form):
def __init__(self):
self.Text = 'Radio Button Trial'
self.Width = 450
self.Height = 275
self.label = Label()
self.label.Text = "Choose a radio button"
self.label.Location = Point(10, 20)
self.label.Height = 50
self.label.Width = 250
self.CenterToScreen()
self.radio1 = RadioButton()
self.radio1.Text = "Default"
self.radio1.Location = Point(30, 50)
self.radio1.Width = 75
self.radio1.Checked = True
self.Controls.Add(self.radio1)
self.radio2 = RadioButton()
self.radio2.Text = "PIN01"
self.radio2.Location = Point(30, 80)
self.radio2.Width = 75
self.radio2.Checked = False
self.Controls.Add(self.radio2)
self.radio3 = RadioButton()
self.radio3.Text = "PIN02"
self.radio3.Location = Point(110, 80)
self.radio3.Width = 75
self.radio3.Checked = False
self.Controls.Add(self.radio3)
button = Button()
button.Text = "Continue"
button.Location = Point(175, 175)
button.Click += self.buttonPressed
self.Controls.Add(self.label)
self.Controls.Add(button)
def buttonPressed(self, sender, args):
if self.radio1.Checked == True:
logoToUpdate = "(Default) Selected"
elif self.radio2.Checked == True:
logoToUpdate = "(PIN01) Selected"
else:
logoToUpdate = "(PIN02) Selected"
self.Close()
form = CountForm()
Application.Run(form)
print "logoToUpdate Selected = " + logoToUpdate
回答了我自己的问题,不得不在logoToUpdate变量中添加 "form."。
def buttonPressed(self, sender, args):
if self.radio1.Checked == True:
form.logoToUpdate = "VA Titleblock Consultant Logo (Default)"
elif self.radio2.Checked == True:
form.logoToUpdate = "VA Titleblock Consultant Logo (PIN01)"
else:
form.logoToUpdate = "VA Titleblock Consultant Logo (PIN10)"
self.Close()
form = CountForm()
Application.Run(form)
Answer = form.logoToUpdate
print Answer