Geometry is both “drawing” and “data”. In NOTE and DOC, geometry elements can be used for annotation, composition, or to present structured information alongside note content. This chapter covers three common capabilities: insert, read from lasso selection, and modify.
Insert Geometry
Call insertGeometry to insert a geometry element:
- In NOTE: inserted into the current page on the current layer of the currently opened note
- In DOC: inserted into the current page of the currently opened document
import { PluginCommAPI } from 'sn-plugin-lib';
/**
* Insert a circle geometry into the current page.
*/
async function insertCircle() {
const geometry = {
penColor: 0x9d, // Pen color for drawing the geometry
penType: 10, // Pen type for drawing the geometry
penWidth: 200, // Line width (min 100)
type: 'GEO_circle', // Geometry type
ellipseCenterPoint: { x: 300, y: 400 }, // Center point (pixel coordinates)
ellipseMajorAxisRadius: 120, // Major axis radius
ellipseMinorAxisRadius: 120, // Minor axis radius
ellipseAngle: 0, // Rotation angle (radians)
};
const res = await PluginCommAPI.insertGeometry(geometry);
console.log('insertGeometry:', res);
}
The type field values and data structure are defined in Geometry. Point coordinates use pixel coordinates.
Get Lasso Geometries
After selecting geometry elements with the lasso tool, call getLassoGeometries to read the selected geometry list.
import { PluginCommAPI } from 'sn-plugin-lib';
/**
* Read geometries in the current lasso selection.
*/
async function readLassoGeos() {
const res = await PluginCommAPI.getLassoGeometries();
if (!res?.success) {
console.error('getLassoGeometries error:', res?.error);
return;
}
const list = res.result ?? [];
console.log('lasso geometries:', list);
}
result is a list of Geometry.
You must create a lasso selection before calling this API. If there are no geometry elements in the lasso selection, the returned array is empty.
Modify Lasso Geometry
You can modify the currently lasso-selected geometry, for example adjust a circle radius or change a line point set.
Call modifyLassoGeometry to apply the modification:
import { PluginCommAPI } from 'sn-plugin-lib';
/**
* Modify the radius of a single circle geometry selected by lasso.
*/
async function updateLassoCircle() {
const res = await PluginCommAPI.getLassoGeometries();
if (!res?.success || !res.result || res.result.length !== 1) {
console.error('You must lasso-select exactly one geometry element to modify it');
return;
}
const geo = res.result[0];
if (geo.type === 'GEO_circle' || geo.type === 'GEO_ellipse') {
geo.ellipseMajorAxisRadius = (geo.ellipseMajorAxisRadius ?? 100) + 20;
geo.ellipseMinorAxisRadius = (geo.ellipseMinorAxisRadius ?? 100) + 20;
}
const mod = await PluginCommAPI.modifyLassoGeometry(geo);
console.log('modifyLassoGeometry:', mod);
}
This operation requires the current lasso selection to contain exactly one geometry element. Calling it with no lasso selection or multiple geometries will fail.