- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我是一名建筑师,通过 Revit 逐渐喜欢上了编码。但不幸的是,由于仍然是一个终极菜鸟,我需要任何愿意加入的人的帮助。我也是 Stackoverflow 菜鸟,所以我不知道它是否还可以,并且除了在社区中发布这样的问题之外更多辅导,然后解决问题。但无论如何,它是这样的:我正在尝试创建一个能够同时从 Revit 族编辑器中删除多个参数的应用程序。我在 C# 方面取得了成功,但由于我想转移到 Python,因为它更容易作为初学者进入,所以我做了很多浏览,但由于 OOP 知识有限而没有任何帮助。如何在列表框中显示 Family 参数名称,或者如果我在列表框中已有字符串名称,我如何将所选项目与 FamilyParameterSet 中的实际参数进行比较?
我有一个启动代码,可以从家庭管理器收集所有参数。我把它投到列表中。然后一个选项是使用要在列表框中列出的参数的名称属性,但我不知道返回并检查列表或循环列表以将参数集中的名称与从列表框中选择的名称进行比较。所以我选择了另一个选项,将 Family 参数直接放入列表框中,但我无法显示实际的 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 拥有 Family 参数的所有 .Id proportes,以便将它们从 Family 参数集中删除。在代码的开头(对于不知道 Revit API 的人)“fps”表示 FamilyParameterSet,它被转换为 Python 列表“paramsList”。所以我需要从列表框中选择的项目中删除 FPS 的成员。
最佳答案
您从 Revit 到编码的旅程很熟悉!
首先,您的 C# 代码中似乎有一些遗留问题。您需要牢记从 C# 到 Python 的几个关键转变 - 在您的情况下,根据运行代码时的错误,需要缩进两行:
Syntax Error: expected an indented block (line 17)
Syntax Error: expected an indented block (line 39)
根据经验,冒号 :
后需要缩进,这也使代码更具可读性。还有一些分号 ;
在前几行 - 不需要它们!
否则代码就差不多了,我在下面的代码中添加了注释:
# the Winforms library first needs to be referenced with clr
import clr
clr.AddReference("System.Windows.Forms")
# Then all the Winforms components youre using need to be imported
from System.Windows.Forms import Application, Form, ListBox, Label, Button, SelectionMode, DockStyle
doc = __revit__.ActiveUIDocument.Document
mgr = doc.FamilyManager
fps = mgr.Parameters
paramsList=list(fps)
# senderlist = [] moved this into the Form object - welcome to OOP!
class IForm(Form):
def __init__(self):
self.Text = "Remove multiple parameters"
self.senderList = []
lb = ListBox()
lb.SelectionMode = SelectionMode.MultiSimple
lb.Parent = self # this essentially 'docks' the ListBox to the Form
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):
self.senderList.append(sender.SelectedItem)
def RemoveParameter(self,sender,event):
for i in paramsList:
if i.Definition.Name in self.senderList:
t = Transaction(doc, 'This is my new transaction')
t.Start()
# wrap everything inside Transactions in 'try-except' blocks
# to avoid code breaking without closing the transaction
# and feedback any errors
try:
name = str(i.Definition.Name)
mgr.RemoveParameter(i) # only need to supply the Parameter (not the Id)
print 'Parameter deleted:',name # feedback to the user
except Exception as e:
print '!Failed to delete Parameter:',e
t.Commit()
self.senderList = [] # clear the list, so you can re-populate
Application.Run(IForm())
从这里开始,附加功能只是为用户完善它:
ListBox
BuiltIn
参数(尝试删除一个并查看它抛出的错误)让我知道这是如何工作的!
关于c# - IronPython 和 Revit API - 如何在列表框中显示项目属性(属性名称)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57437245/
我想用 revit api 控制加载族和创建类型的事件。有人可以给我一个方向吗?我不太了解我阅读的文档。 最佳答案 首先,您需要通过在 IExternalApplication OnStartup 方
我使用过 RevitPythonShell 和 Dynamo,但我想使用我现有的 Python IDE (Eclipse),我在其中配置了日志记录、调试、GitHub 集成等。 我对事务和整个 API
使用 Revit Python Shell,我尝试提示用户选择一个房间。我一直在阅读并实现此处描述的方法 Revit Python Pick Object / Select Object 。它工作正常
假设我想创建一个基于云的服务,该服务可以连接到 Revit Server 并获取模型数据、对其进行处理,然后在基于 Web 的界面中向用户返回一些有用的信息。然后用户修改模型并将更改提交到服务器。我的
我打开文件 A,其中链接了 x 个文件 B。文件 B 还链接了 x 个文件 C。我想知道文件 C 的位置名称。 我使用 dynamo for revit 收集文件 A 中的 RevitLinkInst
在 Revit API 中,我知道我可以获得当前正在运行的 Revit 实例的版本(ControlledApplication.VersionBuild,ControlledApplication.V
我正在尝试使用 Revit API 激活 View 。我想要做的正是提示用户选择一些墙,但是当用户被问到时,他无法切换 View 以选择更多墙(此时一切都变灰了)。 所以我想激活的 View (我的意
长期以来,我一直在使用 Autodesk Forge 的 Model Derivative API(成功)将 Revit 文件导出到 IFC。 但是,我注意到即使使用法语版软件(即 Revit FRA
我有一个非常“笼统”的问题。我正在使用 Revit API(使用 python)进行开发,有时我会观察到 Revit session 在我的测试和试验期间变得更慢(Revit 保持打开的时间越长,它似
我尝试使用 python 编辑我的 Revit.ini 文件,但是我仍然收到以下错误。今天大部分时间我都在用头撞墙。在此感谢任何帮助。 我一直在 python 2.7 上使用 ConfigParser
我需要为许多元素(>100'000 个项目)找到大纲。目标元素来自 FilteredElementCollector。像往常一样,我正在寻找最快的方法。 现在我尝试遍历所有元素以获取其 Bouding
有一个元素的参数有 5 个选择(组合框的样式)。我知道如何获取当前选定的选项,但是有没有办法检索其他 4 个选项? 最佳答案 它们存储在 SimilarObjectTypes作为 ElementSet
我想重写我的 Revit 插件之一,以便它通过 MVVM 使用 WPF,因为与 Windows 窗体相比,我更喜欢 WPF 的外观和功能。 我已将 Jeremy Tammik 的 Revit 模板向导
我看到一个已经运行多年的基准有一些奇怪的行为。该基准适用于 Autodesk Revit,它可以使用日志文件来自动执行任务和记录时间。基准测试将读取一系列模块化日志文件的 XML 文件,这些文件可以根
我有这段代码,但我不知道如何显示我选择的墙的位置、高度和长度: using System; using System.Collections.Generic; using System.Linq; u
是否可以在不运行 Revit 的情况下创建与 Revit 数据库模型交互的我自己的 Revit API 代码的单元测试。 如果是这样,如何实现。 最佳答案 我参与了其中提到的一些话题。我什至参与过一个
我对 C# 和编码还很陌生。如果可能的话,我正在寻找一些帮助来弄清楚如何修复这段代码以使其正常工作。 他们单独工作。我可以在功能区上创建一个新按钮并执行标准的 hello world。我还有一个宏,可
我正在尝试拦截 Revit 并阻止窗口打开。具体来说,我试图将基调应用于一个对象,然后让用户创建一个基调标签,但是我这样做的任何方式都让他们放置基调,但随后立即给他们对话框来选择一个基调,但我不' 希
我想在查看器中放置一些 Three.js 对象,并在 Revit 模型中获得该对象的估计坐标。如何将这些坐标转换为查看器坐标以放置对象? 最佳答案 由于 Forge 查看器默认会对加载的模型应用全局偏
在执行 IExternalCommand 时,我可以通过 ExternalCommandData 轻松获取应用程序和文档 UIApplication uiApp = commandDa
我是一名优秀的程序员,十分优秀!