Create Asset

sceneplates/createAsset.py
 1# © 2024 Autodesk, Inc. All rights reserved.
 2
 3# Example to show how create sceneplate assets
 4
 5# We introduce this types to make the code more readable
 6ContentType = vrSceneplateTypes.ContentType
 7
 8# Query parent object for all scene plate creation
 9theRoot = vrSceneplateService.getRootNode()
10
11theNode = vrSceneplateService.createNode(theRoot, vrSceneplateTypes.Frontplate, "Asset Test Frontplate")
12thePlate = vrdSceneplateNode(theNode)
13thePlate.setContentType(ContentType.Text)
14thePlate.setText("Hello world")
15
16# the name may be different form the name passed to create node (in case a sceneplate with this name already exists)
17sceneplateName = str(thePlate.getName())
18
19# this returns the currently selected sceneplate asset directory
20# so, you have to make sure that 
21directory = getSelectedAssetDirectory(VR_ASSET_SCENEPLATE)
22
23if len(directory) == 0:
24    print("ERROR: No sceneplate directory selected, open asset manager and select sceneplate directory.")
25else:
26    print(('Using directory:', directory))
27    # this converts a decoupled vrdObject into a vrdNodePtr 
28    sceneplateNode = vrNodePtr(thePlate.getObjectId())
29    
30    if not createSceneplateAsset(sceneplateNode, directory):
31        print("ERROR: Unable to create sceneplate asset")
32    else:
33        print("Created sceneplate asset")
34        # Load the stored asset again
35        sceneplateNode2 = loadSceneplateAssetByName(sceneplateName)
36        # And again by passing the directory
37        sceneplateNode3 = loadSceneplateAssetByName(sceneplateName, directory)
38        # Find the uuid of the asset and load the asset again
39        attachment = sceneplateNode3.getAttachment("AssetAttachment")        
40        uuid = vrFieldAccess(attachment).getString("uuid")       
41        sceneplateNode4 = loadSceneplateAssetByUUID(uuid)
42        # Overwriting one asset changes all assets
43        thePlate.setText("HELLO WORLD!")
44        overwriteSceneplateAsset(sceneplateNode)
45        
46
47