Picking points#
A script can stop part-way through and ask you to click points in the viewer, then carry on with whatever you picked. This is for the cases where the script cannot know the answer on its own — where an inlet sits on a scanned artery, which nodes carry a support, where a cut should start and end.
deck = shapes.rectangle(dim=(10.0, 10.0), corner=[-5.0, -5.0, 0.0], div=8, eltype="quad4")
draw(deck, name="deck")
supports = pick_points("Click the nodes where supports should go")
for i, point in enumerate(supports):
draw(shapes.sphere(radius=0.4).translate(point), name=f"support_{i}", color="red")
pick_points() returns a list of points, [[x, y, z], ...], in the order
you clicked them. If you want exactly one point, unpack it:
(start,) = pick_points("Pick the start node")
You pick on what has already been drawn#
When the script reaches pick_points(), everything drawn so far appears in
the viewer and the run pauses there. So draw the geometry you want to pick on
before the call — a script that asks for points before drawing anything leaves
nothing to click.
The run continues only when you press Confirm. Until then you can keep clicking to add points, and remove any that landed on the wrong node from the list in the top-right of the viewer. A mis-click is never final, and clicking never resumes the script on its own.
Points snap to nodes#
A picked point is always a node of a mesh, never an arbitrary spot on a surface. The nearest node to the pointer is highlighted as you move; where nodes sit in front of one another, the one nearest the camera wins. Zoom in if a model is dense and you need a specific one.
Only meshes that are visible can be picked. Hiding an object in the Visualization Settings panel takes its nodes out of play, which is a practical way to pick through a surface that is in the way.
Picking on one object in a multi-object scene#
A common flow draws a solid, picks points on it, derives something new from those points (a centerline, say), and then needs to pick points on that instead. Left alone, the earlier object is still visible — even semi-transparent — and its nodes keep competing for, and can block, picks meant for the new one.
Pass target= with the name given to the object’s draw() call to
restrict picking to it:
solid = shapes.cylinder(radius=2.0, length=10.0)
draw(solid, name="vessel", style={"faces": {"opacity": 0.3}})
inlet, outlet = pick_points("Pick the inlet and outlet nodes")
centerline = solid.centerline(inlet, outlet) # however it's derived
draw(centerline, name="centerline", color="orange")
cuts = pick_points("Pick the cut points", target="centerline")
target also accepts a list of names, when more than one object should stay
pickable:
pick_points("Pick anywhere on either", target=["vessel", "centerline"])
With no target, every visible object is pickable — the behavior described
above.
Things to know#
You have five minutes to answer. The banner shows the countdown. If it runs out the run stops, as it would on any other timeout — nothing is saved beyond what was drawn before the pause.
Cancel stops the whole run, not just the prompt.
The script waits for you, and that time is not charged to its own two-minute compute budget. Taking a while to choose will not time the script out.
A script can pause more than once. Each
pick_points()call is its own prompt, and the geometry drawn in between appears before the next one.`target=` restricts which drawn object(s) are pickable, by the name given to
draw(). Useful once a scene has more than one object and an earlier one would otherwise block picks meant for a later one.