2 顺序事务,设置详细信息编号 (Revit API / Python)

2 Sequential Transactions, setting Detail Number (Revit API / Python)

目前,我制作了一个工具,可以根据 sheet 上的位置重命名 sheet 上的视图编号(“详细信息编号”)。这是打破的地方是交易。我试图在 Revit Python Shell 中按顺序执行两个事务。我最初也是在发电机中这样做的,并且有类似的失败,所以我知道它与交易有关。

交易 #1: 为每个详细编号添加后缀(“-x”)以确保新编号不会冲突(1 将是 1-x,4将是 4-x,等等)

事务 #2: 根据视口位置使用计算出的新数字更改细节数字(1-x 为 3,4-x 为 2,等等)

这里有更好的视觉解释:https://www.docdroid.net/EP1K9Di/161115-viewport-diagram-.pdf.html 此处的 Py 文件:http://pastebin.com/7PyWA0gV

附件是 python 文件,但本质上我想做的是:

            # <---- Make unique numbers    
            t = Transaction(doc, 'Rename Detail Numbers')
            t.Start()
            for i, viewport in enumerate(viewports):
                            setParam(viewport, "Detail Number",getParam(viewport,"Detail Number")+"x")
            t.Commit()

            # <---- Do the thang        
            t2 = Transaction(doc, 'Rename Detail Numbers')
            t2.Start()
            for i, viewport in enumerate(viewports):
                            setParam(viewport, "Detail Number",detailViewNumberData[i])
            t2.Commit()

附上py文件

正如我在对 your comment in the Revit API discussion forum, the behaviour you describe may well be caused by a need to regenerate between the transactions. The first modification does something, and the model needs to be regenerated before the modifications take full effect and are reflected in the parameter values that you query in the second transaction. You are accessing stale data. The Building Coder provides all the nitty gritty details and numerous examples on the need to regenerate 的回答中所解释的那样。

整个线程的摘要,包括已解决的两个问题:

http://thebuildingcoder.typepad.com/blog/2016/12/need-for-regen-and-parameter-display-name-confusion.html

所以这个问题实际上与交易或文档生成无关。我发现(在一些帮助下 :)),问题在于我如何 setting/getting 参数。 "Detail Number",与许多参数一样,在视口元素中具有共享相同描述性参数名称的重复版本。

显然,这可能是遗留问题的原因,但我不确定。因此,当我尝试 get/set 详细编号时,它偶尔会以某种方式获取不正确的只读参数,一个名为“VIEWER_DETAIL_NUMBER”的参数它的内置枚举。正确的是“VIEWPORT_DETAIL_NUMBER”。发生这种情况是因为我试图通过传递描述性参数名称 "Detail Number" 来获取参数。通过内置枚举修改 get/set 参数的方式解决了这个问题。见下图。

请参阅 pdf 以获取视觉解释:https://www.docdroid.net/WbAHBGj/161206-detail-number.pdf.html