How do I get the value of an element?
- Dominant language
- Python
- Stars
- 10
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
Hi, I have a collision object with box shape. I want to access the `data` which contains the width/height/depth of the box:
(converted to JSON for readability)
```json
"embedded_collision_shape": {
"shapes": {
"shape_type": "TYPE_BOX",
"position": {
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"rotation": {
"w": 1.0,
"x": 0.0,
"y": 0.0,
"z": 0.0
},
"index": 0,
"count": 3,
}
"data": [
20.0,
0.05,
20.0
],
}
```
In my .collection the embedded object looks like:
```
"embedded_collision_shape {\\n"
" shapes {\\n"
" shape_type: TYPE_BOX\\n"
" position {\\n"
" x: 0.0\\n"
" y: 0.0\\n"
" z: 0.0\\n"
" }\\n"
" rotation {\\n"
" x: 0.0\\n"
" y: 0.0\\n"
" z: 0.0\\n"
" w: 1.0\\n"
" }\\n"
" index: 0\\n"
" count: 3\\n"
" }\\n"
" data: 20.0\\n"
" data: 0.05\\n"
" data: 20.0\\n"
"}\\n"
```
Using deftree:
```py
import deftree
tree = deftree.parse('level1.collection')
root = tree.get_root()
coll_shape = root \
.get_element("embedded_instances") \
.get_element("data") \
.get_element("embedded_components") \
.get_element("data") \
.get_element("embedded_collision_shape") \
for d in coll_shape.elements("data"):
print(d)
```
This outputs:
```
Element('data')
Element('data')
Element('data')
```
However I don't see a way to get their values, such as `20.0`
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.