Add and remove annotations

annotations.py
 1# © 2024 Autodesk, Inc. All rights reserved.
 2
 3import random
 4
 5box1 = createBox(1000,1000,1000,10,10,10,1,1,0)
 6box1.setName("box1")
 7
 8def addAnnotation():
 9
10    # create annotation
11    annotation = vrAnnotationService.createAnnotation("annotation"); # identifier, made unique on creation
12    # set text
13    annotation.setText("Example description text\nwith 2 lines.");
14    
15    # change label size
16    annotation.setSize(0.5)
17    # random line color (border and arrow)
18    r = random.random()
19    g = random.random()
20    b = random.random()
21    lineColor = QColor();
22    lineColor.setRgbF(r, g, b)
23    annotation.setLineColor(lineColor)
24
25    # change label opacity
26    backgroundColor = annotation.getBackgroundColor()
27    backgroundColor.setAlphaF(0.9) #change alpha
28    annotation.setBackgroundColor(backgroundColor)
29
30    # pick a position for the new annotation
31    vrAnnotationService.pickAnnotation(annotation)
32
33def deleteAllAnnotations():
34    for annotation in vrAnnotationService.getAnnotations():
35        vrAnnotationService.deleteAnnotation(annotation)
36 
37
38# Press "A" to add a new annotation
39keyA = vrKey(Key_A)
40keyA.connect(addAnnotation)
41
42# Press "D" to delete all annotations
43keyD = vrKey(Key_D)
44keyD.connect(deleteAllAnnotations)