Run dyn script after Selecting model elements node

I’m working in Revit 2024 in dynamo version below

image

I’ve been working on a dimensioning script that is placed in a tab using PyRevit via Aussie Bim Guru tutorial. I’m able to run the script and dimension all elements in view (categories specified) or I’m able to do it by selection via the Data shapes UI. Hoping to remove a few steps in the “by selection workflow”.

Current workflow with the Data shapes UI is

  1. Select button on push button - UI Appears
  2. Press select Walls in UI
  3. Select Walls
  4. Press finish button in Revit
  5. Press Data Shapes button to execute command.

Is there a way remove the UI and have these steps instead?

  1. Select button on push button (prompts to select walls or specified category)
  2. Select Walls
  3. Press finish button and the dyn. script runs

image
image
image

I’ve searched on the forum and haven’t found a solution. If anyone could point me in the right direction or tell me the challenges with this I’d be grateful.

Thanks

You can certainly simply your script down, but from a user POV, will everyone else know that they need to select the walls and click “Finish” without a popup message directing them to?

Without seeing your graph, not sure why you are having to do step 5. That part could possibly be eliminated.

You can create your own custom selection method using python to select the walls and have the selection outputted directly (search the forum for that code). The rest of your graph should execute automatically without anymore interaction.

But keeping the user in mind with a popup message, ultimately, you are really only eliminating step 5 in your script.

Step 5 means he has to press “ok” on the data shapes menu.

No you are eliminating 3 clicks / steps actually

How are you liking the pyRevit tab? I’ve also created a toolbar. It’s so much better than using the Dynamo Player because the scripts are very easily findable.

Exactly there is an alternative to the data shapes al together. Somewhere on the forum I saw @john_pierson’s code appear for viewports. I use it for selecting viewports, as the function is always the same and no extra inputs are required.

I then used ChatGPT to alter the selection to walls. So make sure to test. Either way, put this in a python node in your script:

# Copyright(c) 2017, john pierson
# @60secondrevit, http://sixtysecondrevit.com
# Thanks to Dimitar and Troy Gates for Guidance
# and this blog http://pythoncvc.net/?p=116

import clr
import msvcrt
clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument
uidoc = DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)

# Show TaskDialog to instruct user
TaskDialog.Show('Select your walls!', 'In your Revit window, pick walls in desired order then press the ESC key to finish.')

# Set up selection
sel1 = uidoc.Selection
obt1 = Selection.ObjectType.Element

class CustomISelectionFilter(Selection.ISelectionFilter):
    def __init__(self, nom_categorie):
        self.nom_categorie = nom_categorie
    def AllowElement(self, e):
        if e.Category.Name == self.nom_categorie:
            return True
        else:
            return False
    def AllowReference(self, ref, point):
        return True

msg1 = 'In your Revit window, pick walls in desired order then press the ESC key to finish.'
out1 = []
flag = True

while flag:
    try:
        # Change filter to "Walls" category
        el1 = doc.GetElement(sel1.PickObject(obt1, CustomISelectionFilter("Walls"), msg1).ElementId)
        out1.append(el1.ToDSType(True))
    except:
        flag = False

OUT = out1

Yes, I understand that, but even with using Data-Shapes you can set up the script to where you shouldn’t have to do anything after you have selected the walls and clicked “Finish”. At that point the script should execute the dimensioning and close out automatically.

Not really. If you notice, his first step is actually initiating the command whether it’s from player or the Revit menu. Then the selecting elements code that you provide below, invokes (3) more steps. So all together - (1) Initiate the command. (2) Select OK from the task dialog message. (3) Select the walls. (4) Hit ESC key.

1 Like

Thanks Staylor - You’re right they wouldn’t know to select the walls. We’ll create a guide for users and will do demo’s of the tool.

Thanks RR - knowing there’s an instructional prompt option is helpful. I’m liking the Pyrevit tab alot. I have about 10 pushbutton tools for automation and it’s much less intimidating for users to use a pushbutton than the dynamo player.

1 Like

I love it too, also for myself. The Dynamo player is a hassle. However it has one feature that the toolbar buttons won’t have by default. That’s the fact you can just set inputs and remember them. Let’s say I am distributing views on a sheet, I want even spacing of 10mm between them. I change my mind and want to set it to 15.
With Dynamo player, I can just set a slider and adjust it and rerun. With the toolbar you can’t and have to start over entirely.

HOWEVER it is possible to store the information to a textfile or csv and that’s what I’ve been learning since last week with the help of this forum.

You might want to look into that too :).

I would love to compare toolbars btw, but I think that’s better for PM. Glad you’ve been helped with that python code

1 Like

You can do this by saving config files for users in the appdata folder. Sort of like what I’m doing here:
[SHARING] Remembering data shapes input for next run, this is made for Dynamo but the idea is the same, a python script reads and writes to a .json file and uses either a default value, or a value from the config as the next input. I’d recommend using json over .txt any day simply because of typing issues

I don’t know much about .json or putting things in their appdata folder. So I rather not touch it yet. But evenutally I will learn.

I just stored it in the Button folder instead. Because windows has multiple users or other things that just messes the configuration. I also wanted to make it project specific.

For the particular script in question I needed the input stored as you can see. Last week I was able to accomplish it (except for the selected viewports, I think that’s too risky for a button. For Dynamo player it would work)