pyRevit and RAM Elements

a new blog post about a tool I created for the structural software RAM Elements integrating with pyRevit:

Let me know what you all think!

Hi @atki224, nice work!

I have a few coding style suggestions:

  • split your code into logical functions, so that it will be easier to read (if you name your function properly, than one can just read the main part of the script to undesrtand what it does) - this also comes in handy to reduce duplicated code, just create a function and call it multiple times instead
  • to avoid to much indentation, you can invert the if condition and use sys.exit() to exit early; if the code is organized in function, a return would do the same
  • you can move the NudosRestric2 == 1 check directly inside the first query to save some memory and computation time
  • you can simplify the handling of nullables in the coordinates with int(float(row.get("NudosX") or "0"))) and so on;
  • instead of GetElementIdIterator, use ToElements to directly get the elements
  • I’m pretty sure you can also use a Collector filter to get the family by name; and maybe pyrevit offers a convenience function in the pyrevit.revit.db.query module (there are too many I can’t remember :sweat_smile: )
  • you start many nested transactions, is this wanted or just a copy/paste result? :wink: generally you can wrap your code into a single transaction, so that if something goes wrong, nothing gets written to the database. If you use subtransaction, and an error occurs, your db could be in a “halfway state”. There are times when this is wanted, and sub-transaction are ok, though.
  • some of the code inside of a transaction just read data; so the transaction is useless (IIRC, it’s been a while since I’ve used revit api)
  • elif tg.status == DB.TransactionStatus.Committed can just be an else since you already checked the opposite; and you can even remove the else if you exit the script in the if branch
  • same with the if result == "Yes", you can invert it and exit early; or you can keep that check and move everything below into a function (or more than one since that paet is huge)

@sanzoghenzo

thank you for the feedback! definitely not a programmer by trade so wouldn’t otherwise know about many of your suggestions.

in particular your #7 suggestion regarding nested transactions, that sounds like a potential problem and will definitely work to get resolved. as to why I did it in the first place, I have no idea (lol).

1 Like