Remove

sceneplates/remove.py
 1# © 2024 Autodesk, Inc. All rights reserved.
 2#
 3# Example to show how to create, query and remove scene plates
 4# This example is more complex as simple.py and create.py
 5# Please study this first
 6#
 7# vrSceneplateService is used to create, query and remove scene plates
 8# vrdSceneplateNode is used to change scene plate properties
 9#
10
11# We introduce this types to make the code more readable
12NodeType = vrSceneplateTypes.NodeType
13ContentType = vrSceneplateTypes.ContentType
14PositionType = vrSceneplateTypes.Position
15
16# This function summarizes all necessary steps to create a scene plate and set its properties.
17# First we have to create a node using the scene plate service and convert this to an plate.
18# Then we set different properties of the new created plate. 
19def createPlate(root, name, position): 
20    theNode = vrSceneplateService.createNode(root, NodeType.Frontplate, name)
21    thePlate = vrdSceneplateNode(theNode)
22    thePlate.setContentType(ContentType.Text)
23    thePlate.setText(name)    
24    thePlate.setFontColor(QVector3D(0.0, 0.5, 0.5))
25    thePlate.setPosition(position)
26
27# This function creates all used front plates
28def propagateScene(root):    
29    createPlate(root, "1", PositionType.TopLeft)
30    createPlate(root, "2", PositionType.Top)
31    createPlate(root, "3", PositionType.TopRight)
32    createPlate(root, "4", PositionType.Right)
33    createPlate(root, "5", PositionType.BottomRight)
34    createPlate(root, "6", PositionType.Bottom)
35    createPlate(root, "7", PositionType.BottomLeft)
36    createPlate(root, "8", PositionType.Left)
37
38# Query all scene plates
39# If no plates exists, create new plates
40# If plates exists remove all 
41def togglePlates():
42   thePlates = vrSceneplateService.getAllSceneplates()
43   if len(thePlates) > 0:
44       vrSceneplateService.removeNodes(thePlates)
45   else:
46       root = vrSceneplateService.getRootNode()
47       propagateScene(root)
48
49# Query parent object for all scene plate creation
50theRoot = vrSceneplateService.getRootNode()
51
52# Create text front plates attached to windows sides
53propagateScene(theRoot)
54
55# Define key R to remove or to create all scene plates
56keyR = vrKey(Key_D)
57keyR.connect(togglePlates)
58
59# Write instruction on console
60vrLogInfo("Press key 'd' to remove or create scene plates")