Search code examples
revit-apirevitpythonshell

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


Currently, I made a tool to rename view numbers (“Detail Number”) on a sheet based on their location on the sheet. Where this is breaking is the transactions. Im trying to do two transactions sequentially in Revit Python Shell. I also did this originally in dynamo, and that had a similar fail , so I know its something to do with transactions.

Transaction #1: Add a suffix (“-x”) to each detail number to ensure the new numbers won’t conflict (1 will be 1-x, 4 will be 4-x, etc)

Transaction #2: Change detail numbers with calculated new number based on viewport location (1-x will be 3, 4-x will be 2, etc)

Better visual explanation here: https://www.docdroid.net/EP1K9Di/161115-viewport-diagram-.pdf.html Py File here: http://pastebin.com/7PyWA0gV

Attached is the python file, but essentially what im trying to do is:

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

Attached is py file


Solution

  • So this issue actually had nothing to do with transactions or doc regeneration. I discovered (with some help :) ), that the problem lied in how I was setting/getting the parameter. "Detail Number", like a lot of parameters, has duplicate versions that share the same descriptive param Name in a viewport element.

    Apparently the reason for this might be legacy issues, though im not sure. Thus, when I was trying to get/set detail number, it was somehow grabbing the incorrect read-only parameter occasionally, one that is called "VIEWER_DETAIL_NUMBER" as its builtIn Enumeration. The correct one is called "VIEWPORT_DETAIL_NUMBER". This was happening because I was trying to get the param just by passing the descriptive param name "Detail Number".Revising how i get/set parameters via builtIn enum resolved this issue. See images below.

    Please see pdf for visual explanation: https://www.docdroid.net/WbAHBGj/161206-detail-number.pdf.html