Skip to main content

Selection In Headless

The headless API is intended to represent interactive CAD tasks in program code. This means that we basically have no user interface to interact with. We describe our intentions with code, line by line. This has a lot of advantages, but there are also difficulties we have to deal with. Especially tasks where we normally select geometry with the cursor, is not practicable. In this cases we would have to know where the exact position of geometry is found in the global coordinate system. This is hardly possible.

For this task we have implemented a method, which allows us to interact with the graphic on the screen. The method is called selectGeometry and can be found in the documentation of the History API.

📝 Note: To use this method, you need to add the BuerliGeometry component to your application and set selection property true. Otherwise the selection of geometry won't work.

The selectGeometry method allows you to filter the types of graphic that are selectable. There's another optional parameter to define how many selections can be made before continuing with executing code. By default one selection is needed.

Here is a code snippet how to use the selectGeometry method.

const selections = await api.selectGeometry([GraphicType.LINE])

The return value contains a lot of information about the made selection. If you want to continue with the graphic id of the selected graphic, e.g. to add a chamfer or use it as a reference, you will find the id in the "graphicId" property. In the following code snippet, the made selection will be used in the chamfer method.

const selections = await api.selectGeometry([GraphicType.LINE])
await api.chamfer(part, ChamferType.EQUAL_DISTANCE, => sel.graphicId), 2, 2, 45)

There are also use cases where selections are not desired, because we don't want to let the user select anything. In this case there's another method called findGeometry. Within a part we can look for a specific type of graphic at a specific global position. The following code snippet shows an example where we want to find some planes at two different positions.

const planeIds = await api.findGeometry(part, GraphicType.PLANE, [[{x: 50, y: 50, z: 100}], [{x: 100, y: 50, z: 50}]])

If the positions are correct it will return an array containing the two graphic ids of the found planes. We can use this ids for further operations.

See the selection in action in the next video.


Selection in headless API using selectGeometry() method

You can find the whole example in our public application buerli-examples