Issue getting string property value #92891

Open
opened 2024-10-13 14:05:10 +02:00 by Andrej · 0 comments
  1. Create a new .blend and run simple script below or use attached .blend file.
import bpy

bpy.types.Scene.test_string = bpy.props.StringProperty()
bpy.context.scene.test_string = "xxxx"
  1. Try to get test_string value using BAT. It seems string's IDPropertyData.pointer is leading to 0 DNA struct index and BAT misleadingly interprets it as DrawDataList. Is it a bug or it's just an internal thing to keep in mind for 0 DNA indices?

Found a workaround that it's possible to manually read bytes from bf.fileobj using block.file_offset and block.size, not sure if there's a simpler way to do it.

from pathlib import Path
from blender_asset_tracer import blendfile
from blender_asset_tracer.blendfile import iterators

bf_path = Path(r"blendfile_str_prop.blend")
bf = blendfile.open_cached(bf_path)
scene = bf.find_blocks_from_code(b"SC")[0]  # Search for SC (scene) data blocks.
id_property = scene.get_pointer((b"id", b"properties"))  # Is DATA file block.
assert id_property
list_base_id_prop = id_property.get_pointer((b"data", b"group", b"first"))
assert list_base_id_prop

string_prop = next(p for p in iterators.listbase(list_base_id_prop) if p[b"name"] == b"test_string")
print(string_prop[b"name"])  # test_string
print(string_prop[b"type"])  # 0, string.
str_len = string_prop[b"len"] # 5
data_ptr = string_prop.get_pointer((b"data", b"pointer"))
assert data_ptr
print(data_ptr.sdna_index, data_ptr.dna_type) # 0 index misleading user to type DrawDataList.

# Workaround.
bf.fileobj.seek(data_ptr.file_offset)
str_path = bf.header.endian.read_bytes0(bf.fileobj, data_ptr.size)
print(str_path)  # xxxx

1. Create a new .blend and run simple script below or use attached .blend file. ```python import bpy bpy.types.Scene.test_string = bpy.props.StringProperty() bpy.context.scene.test_string = "xxxx" ``` 2. Try to get `test_string` value using BAT. It seems string's `IDPropertyData.pointer` is leading to 0 DNA struct index and BAT misleadingly interprets it as DrawDataList. Is it a bug or it's just an internal thing to keep in mind for 0 DNA indices? Found a workaround that it's possible to manually read bytes from `bf.fileobj` using `block.file_offset` and `block.size`, not sure if there's a simpler way to do it. ```python from pathlib import Path from blender_asset_tracer import blendfile from blender_asset_tracer.blendfile import iterators bf_path = Path(r"blendfile_str_prop.blend") bf = blendfile.open_cached(bf_path) scene = bf.find_blocks_from_code(b"SC")[0] # Search for SC (scene) data blocks. id_property = scene.get_pointer((b"id", b"properties")) # Is DATA file block. assert id_property list_base_id_prop = id_property.get_pointer((b"data", b"group", b"first")) assert list_base_id_prop string_prop = next(p for p in iterators.listbase(list_base_id_prop) if p[b"name"] == b"test_string") print(string_prop[b"name"]) # test_string print(string_prop[b"type"]) # 0, string. str_len = string_prop[b"len"] # 5 data_ptr = string_prop.get_pointer((b"data", b"pointer")) assert data_ptr print(data_ptr.sdna_index, data_ptr.dna_type) # 0 index misleading user to type DrawDataList. # Workaround. bf.fileobj.seek(data_ptr.file_offset) str_path = bf.header.endian.read_bytes0(bf.fileobj, data_ptr.size) print(str_path) # xxxx ```
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-asset-tracer#92891
No description provided.