Tutorial 4: Element Selection
Learn how to let the user "Pick" elements from the model, using Paracore's Strongly Typed Selection to safely get exactly what you need.
Finished Script: 03_Tutorials/Paracore_Fundamentals/04_ElementSelection.cs
What You'll Learn
- The
[Select]attribute - Strongly Typed Selection: Asking for a
Wallinstead of a generic ID - Modifying element parameters
Step 1: Define Inputs (The Smart Way)
In the past, you had to ask for a generic Reference or long (Element ID) and then manually find the object.
With Paracore Hydration, you just ask for the type you want.
public class Params
{
/// <summary>Select a Wall in Revit</summary>
[Select(SelectionType.Element)]
[Mandatory]
public Wall TargetWall { get; set; }
/// <summary>New comment text</summary>
public string Comment { get; set; } = "Updated by Paracore";
}
Notice public Wall TargetWall. Without any attributes, this would normally render a Wall dropdown. But because of the [Select(SelectionType.Element)] attribute, Paracore:
- Replaces the dropdown with a "Pick" button.
- Filters the selection so they can only pick a wall.
- Returns the actual
Wallobject to your script.
Step 2: Validate the Selection
Even though Paracore filters selection, the user might cancel or something might go wrong. Always check for null.
var p = new Params();
if (p.TargetWall == null)
{
Println("No wall selected.");
return;
}
Note: We don't need Doc.GetElement(id). We already have p.TargetWall!
Step 3: Modify the Element
Let's update the comments on the selected wall.
Transact("Update Wall Comment", () => {
// Modify the real Wall object directly
var param = p.TargetWall.get_Parameter(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS);
param?.Set(p.Comment);
Println($"Updated Wall {p.TargetWall.Id} with comment: {p.Comment}");
});
Step 4: Run and Verify
- Click the "Pick" button next to TargetWall.
- The Paracore window will minimize.
- Try to pick a Floor or Window -> Revit won't let you!
- Pick a Wall.
- Enter a comment and click Run Script.
- Select the wall in Revit and check its properties.
Try This
- Change
public Walltopublic Floorand see how the UI pick filter automatically restricts selection to floors. - Loadable Families: Note that there is no
WindoworDoorclass in Revit—they areFamilyInstances! For picking loadable components from the model, you use aReference(which inherently provides a "Pick" button that lets you pick any element). To restrict it specifically to Windows, constrain it using the[RevitElements]attribute:The[RevitElements(Category = "Windows")]public Reference WindowRef { get; set; }Referencetype inherently gives you the Pick button, while the Category constraint ensures you can only select Window instances! - Geometry and Points: Just like
Reference, geometric types inherently provide a Pick button in the Paracore UI. No[Select]attribute is needed!public XYZ? MyPoint { get; set; } // Lets you pick a 3D point in space.public Edge SelectedEdge { get; set; } // Lets you pick a geometric edge.public Face SelectedFace { get; set; } // Lets you pick a geometric face.