0

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

c.m
  • 93
  • 1
  • 1
  • 11

2 Answers2

3

As I explained in my answer to 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.

Summary of this entire thread including both problems addressed:

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

Jeremy Tammik
  • 7,333
  • 2
  • 12
  • 17
0

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

c.m
  • 93
  • 1
  • 1
  • 11
  • thank you for sharing the final solution. i cleaned up and published this thread on The Building Coder: http://thebuildingcoder.typepad.com/blog/2016/12/need-for-regen-and-parameter-display-name-confusion.html – Jeremy Tammik Dec 10 '16 at 08:50