SView Help Center
English (US)

Annotation

Author: sviewngts Last Updated: 2026-10-31 17:40

Interface List

Interface Name Description
Create Annotation Create an annotation or edit an annotation
Delete Annotation Delete an annotation
Update Annotation Position Update the position where the annotation text is displayed
Create Gesture Annotation Create a gesture annotation
Delete Gesture Annotation Delete a gesture annotation
Set Visibility Set annotation visibility
Set Selected Set whether an annotation is selected
Serialize Serialize an annotation into JSON format
Deserialize Deserialize JSON format data into an annotation

Creating an Annotation

let action = new SView.Actions.AnnotationAction();
action.setScene(scene);
//Parameter description
//objID: Annotation ID: pass 0 when creating a new annotation; pass the ID of the annotation to be edited when editing an annotation.
//type: Annotation type; 0 for text annotation, 2 for sequence annotation
//firstPosition: Text annotation position
//secondPosition: Text annotation display position
//text: Annotation text
//fontColor: Annotation text color
//fontName: Annotation text font type
//fontSize: Annotation text font size
//frameColor: Annotation border color
//fillColor: Annotation fill color
//isLeader: Whether to show the leader line
//isEnvelope: Whether to show the outer frame
//isFixed: Whether to fix to the screen
//inTop: Whether to display in the frontend; currently controlled by a configuration item, just pass true
//isStub: Whether to use a short leader line
//modelPath: The assembly path of the associated model
//isEdit: Whether it is in the edit state
action.setParameter(objID: number, type: number, firstPosition: M3D.M3DMath.Vector3, secondPosition: M3D.M3DMath.Vector3,
   text: string,fontColor: M3D.M3DMath.Color, fontName: string, fontSize: number, frameColor: M3D.M3DMath.Color,
   fillColor: M3D.M3DMath.Color,isLeader: boolean, isEnvelope: boolean, isFixed: boolean, inTop: boolean,
   isStub: boolean, modelPath: string, isEdit: boolean);
action.execute();
let annotation = action.getShape();

Deleting an Annotation

let ret = false;
if (M3D.Shapes.ShapeHelper.isCorrelationModelView(annotation, scene)) {
	annotation.setVisible(false);
	ret = true;
} else {
	ret = shapes.removeShape(annotation.getId(), true);
}
if (ret) {
	selector.remove(annotation);
}

Updating the Annotation Position

let action = new SView.Actions.UpdatePositionAction();
//annotation is the annotation object; x and y are the position in the visualization viewport
action.setScene(scene);
action.setParameter(annotation,x,y);
action.execute();

Creating a Gesture Annotation

let action = new SView.Actions.PaintBrushAction(scene);
action.setScene(scene);
//Parameter description
//drawTypeList Gesture annotation type: 0 = line, 1 = circle, 2 = rectangle, 3 = triangle. Currently, only the line type supports drawing multiple at the same time; in all other cases, an array must still be passed.
//colorList The color of each line segment in the gesture annotation; of type an array of M3D.M3DMath.Color.
//pointArrayList The points of each line segment in the gesture annotation; of type a two-dimensional array of M3D.M3DMath.Vector2, where each row represents one gesture annotation line.
action.setParameter(drawTypeList, colorList, pointArrayList);
action.execute();

Deleting a Gesture Annotation

let ret = false;
if (M3D.Shapes.ShapeHelper.isCorrelationModelView(gesturesNote, scene)) {
    gesturesNote.setVisible(false);
    ret = true;
} else {
    ret = shapes.removeShape(gesturesNote.getId(), true);
}
if (ret) {
    selector.remove(gesturesNote);
}

Setting Annotation Visibility

//visible is of boolean type
annotation.setVisible(visible);

Setting Whether an Annotation Is Selected

//selected
selector.add(annotation);
//unselected
selector.remove(annotation);

Annotation Serialization

   Annotation serialization

//Get all annotations
let annotations = shapes.getShapes(M3D.Shapes.ShapeType.ANNOTATION_NOTE);
//Serialize the annotations
let annotationListJsonStr = M3D.Reader.AnnotationFactory.toJsonByAnnotations(annotationList);

   Gesture annotation serialization

//Get all gesture annotations
let gestureNoteList = shapes.getShapes(M3D.Shapes.ShapeType.THREED_GESTURE_NOTE);
//Convert the gesture annotations to JSON
for(let i=0;i<gestureNoteList.length;i++){
	let gestureNoteJsonStr = M3D.Reader.PaintBrushFactory.threeGestureNoteToJson(gestureNoteList[i]);
}

Annotation Deserialization

   Annotation deserialization

let jsonArray = JSON.parse(annotationListJsonStr);
let annotationJsonArray = jsonArray.annotations;
for(let i=0;i<annotationJsonArray.length;i++){
	let annotationJsonStr = JSON.stringify(annotationJsonArray[i]);
	let annotation = M3D.Reader.AnnotationFactory.fromJson(annotationJsonStr,scene);
	shapes.addShape(annotation);
	annotation.setVisible(true);
}

   Gesture annotation deserialization

let gestureNote = M3D.Reader.PaintBrushFactory.threeGestureNoteFromJson(gestureNoteJsonStr,scene);
shapes.addShape(gestureNote);
gestureNote.setVisible(true);