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. Paracore sees this and:
- Gives the user 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 Windowand see how the selection filter changes. - Use
[Select(SelectionType.Point)]withpublic XYZ Pointto pick a location in 3D space.