Skip to content

Commit 1b8e05b

Browse files
committed
Update versioning.py
1 parent a014b92 commit 1b8e05b

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

versioning.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,17 @@ def do_versioning(self):
156156
# Dictionary to temporarily store objects and their modifiers
157157
old_objects = {}
158158

159+
# First pass: store old objects and change conversion type
159160
for sketch in context.scene.sketcher.entities.sketches:
160161
if sketch.convert_type == 'NONE':
161162
continue
162163

163-
# Store references to the old objects before deleting them
164+
# Store references to the old objects
164165
sketch_id = str(sketch.slvs_index)
165166
old_objects[sketch_id] = {
166167
'mesh_obj': sketch.target_object,
167-
'curve_obj': sketch.target_curve_object
168+
'curve_obj': sketch.target_curve_object,
169+
'sketch': sketch
168170
}
169171

170172
# Clear links to objects but don't delete them yet
@@ -181,21 +183,24 @@ def do_versioning(self):
181183

182184
msg += " {}".format(str(sketch))
183185

184-
# Trigger the conversion with the new convert type
185-
bpy.ops.view3d.slvs_update(solve=False)
186+
# Second pass: process each sketch individually
187+
for sketch_id, objects in old_objects.items():
188+
sketch = objects['sketch']
186189

187-
# Now copy modifiers from old objects to new objects
188-
for sketch in context.scene.sketcher.entities.sketches:
189-
sketch_id = str(sketch.slvs_index)
190-
if sketch_id not in old_objects:
191-
continue
190+
# Force creation of converted object for this sketch
191+
bpy.ops.view3d.slvs_update(solve=False)
192192

193+
# Ensure the new object is created
193194
if sketch.target_curve_object:
194195
# Try to copy from mesh object first, then curve object
195-
if old_objects[sketch_id]['mesh_obj']:
196-
copy_modifiers(old_objects[sketch_id]['mesh_obj'], sketch.target_curve_object)
197-
elif old_objects[sketch_id]['curve_obj']:
198-
copy_modifiers(old_objects[sketch_id]['curve_obj'], sketch.target_curve_object)
196+
if objects['mesh_obj']:
197+
copy_modifiers(objects['mesh_obj'], sketch.target_curve_object)
198+
elif objects['curve_obj']:
199+
copy_modifiers(objects['curve_obj'], sketch.target_curve_object)
200+
201+
logger.info(f"Copied modifiers to new object for sketch {sketch_id}")
202+
else:
203+
logger.warning(f"Failed to create new object for sketch {sketch_id}")
199204

200205
# Unlink and rename old objects instead of deleting them
201206
for sketch_id, objects in old_objects.items():
@@ -206,7 +211,7 @@ def do_versioning(self):
206211
for collection in old_obj.users_collection:
207212
collection.objects.unlink(old_obj)
208213
# Rename to indicate it's an old version
209-
old_obj.name = f"OLD_{old_obj.name}"
214+
old_obj.name = f"OLD_{old_obj.name}_{sketch_id}"
210215

211216
# Process curve object
212217
if objects['curve_obj']:
@@ -215,6 +220,6 @@ def do_versioning(self):
215220
for collection in old_obj.users_collection:
216221
collection.objects.unlink(old_obj)
217222
# Rename to indicate it's an old version
218-
old_obj.name = f"OLD_{old_obj.name}"
223+
old_obj.name = f"OLD_{old_obj.name}_{sketch_id}"
219224

220225
logger.warning(msg)

0 commit comments

Comments
 (0)