Skip to content

Commit 8089572

Browse files
committed
ensure proper scene namespace
1 parent 6584e4f commit 8089572

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

addon/ops/arduino_export.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ def export(self, positions, filepath, context):
4444
lines = self.join_by_chunk_size(commands, self.chunk_size)
4545

4646
if self.namespace:
47-
content += f"\nnamespace {context.scene.name} {{\n"
47+
scene_name = self.format_scene_name()
48+
content += f"\nnamespace {scene_name} {{\n"
4849

4950
content += (
5051
f"\nconst byte FPS = {fps};"
@@ -55,7 +56,7 @@ def export(self, positions, filepath, context):
5556
content += f'const byte PROGMEM ANIMATION_DATA[LENGTH] = {{\n{lines}}};\n'
5657

5758
if self.namespace:
58-
content += f"\n}} // namespace {context.scene.name}\n"
59+
content += f"\n}} // namespace {scene_name}\n"
5960

6061
with open(filepath, 'w', encoding='utf-8') as file:
6162
file.write(content)
@@ -73,3 +74,13 @@ def join_by_chunk_size(cls, iterable, chunk_size):
7374
@classmethod
7475
def format_hex(cls, byte):
7576
return f'{byte:#04x}'
77+
78+
@classmethod
79+
def format_scene_name(cls):
80+
valid_chars = set('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_')
81+
scene_name = ''.join(c if c in valid_chars else '_' for c in bpy.context.scene.name)
82+
83+
if scene_name[0].isdigit():
84+
scene_name = '_' + scene_name
85+
86+
return scene_name

0 commit comments

Comments
 (0)