我是一名建筑师,他逐渐喜欢通过Revit编写代码。但不幸的是,由于我仍然是一个绝顶聪明的人,我需要任何愿意加入的人的帮助。我也是一个无名氏,所以我不知道在社区里发布这样的问题是不是可以,也不例外,这些问题更多的是辅导问题,而不是解决问题。但不管怎样,事情是这样的: 我正在尝试创建一个能够同时从Revit族编辑器中删除多个参数的应用程序。我在C#方面已经取得了成功,但是由于作为初学者更容易入门,我想转到Python,所以我做了很多浏览工作,但由于OOP知识有限,没有任何帮助。 如何在列表框中显示族参数名称,或者如果列表框中有字符串名称,如何将所选项目与FamilyParameterSet中的实际参数进行比较?你知道吗
我有一个开始代码,我可以收集所有参数从家庭经理。我把它列入名单。然后一个选项是使用要在listbox中列出的参数的Name属性,但我不知道如何返回并签出列表,也不知道如何循环列表以将参数集中的名称与从listbox中选择的名称进行比较。所以我选择了另一个选项,直接将族参数放在列表框中,但是我无法显示实际的Name属性。 这段C代码可能对我有所帮助,但我不知道如何用Python重新创建它,因为我的OOP经验实在太差了。 Items on ListBox show up as a class name
doc = __revit__.ActiveUIDocument.Document
mgr = doc.FamilyManager;
fps = mgr.Parameters;
paramsList=list(fps)
senderlist =[]
class IForm(Form):
def __init__(self):
self.Text = "Remove multiple parameters"
lb = ListBox()
lb.SelectionMode = SelectionMode.MultiSimple
for n in fps:
lb.Items.Add(n.Definition.Name)
lb.Dock = DockStyle.Fill
lb.SelectedIndexChanged += self.OnChanged
self.Size = Size(400, 400)
self.CenterToScreen()
button = Button()
button.Text = "Delete Parameters"
button.Dock = DockStyle.Bottom
button.Click += self.RemoveParameter
self.Controls.Add(button)
def OnChanged(self, sender, event):
senderlist.append(sender.SelectedItem)
def RemoveParameter(self,sender,event):
for i in paramsList:
if i.Definition.Name in senderlist:
t = Transaction(doc, 'This is my new transaction')
t.Start()
mgr.RemoveParameter(i.Id)
t.Commit()
Application.Run(IForm())
我需要函数RemoveParameter具有所有的.Id比例的族参数,以便从族参数集中删除它们。在代码的开头(对于不了解Revit API的人)“fps”表示FamilyParameterSet,它被转换为Python列表“paramsList”。因此我需要从列表框中选择的项中删除fps的成员。你知道吗
您从Revit到代码的旅程非常熟悉!你知道吗
首先,看起来您的代码中有一些C#遗留问题。您需要记住从C#到Python有几个关键的转变—在您的示例中,有两行需要缩进,正如运行代码时的错误所示:
经验法则是在冒号
:
之后需要缩进,这也使得代码更具可读性。还有一些分号;
在前几行-不需要它们!你知道吗否则代码就差不多了,我在下面的代码中添加了注释:
从这里开始,额外的功能只是为用户润色一下:
ListBox
BuiltIn
参数(尝试删除一个参数并查看它抛出的错误)让我知道这是怎么回事!你知道吗
相关问题 更多 >
编程相关推荐