@@ -37,6 +37,30 @@ def recalc_pointers(scene):
37
37
logger .debug ("Update entity indices:" + msg )
38
38
39
39
40
+ def copy_modifiers (source_obj , target_obj ):
41
+ """Copy modifiers from source object to target object"""
42
+ if not source_obj or not target_obj :
43
+ return
44
+
45
+ # Clear existing modifiers on target
46
+ while target_obj .modifiers :
47
+ target_obj .modifiers .remove (target_obj .modifiers [0 ])
48
+
49
+ # Copy modifiers from source to target
50
+ for mod in source_obj .modifiers :
51
+ new_mod = target_obj .modifiers .new (name = mod .name , type = mod .type )
52
+ # Copy attributes that are common to all modifier types
53
+ for attr in dir (mod ):
54
+ if attr .startswith ('__' ) or attr in {'rna_type' , 'type' , 'name' , 'bl_rna' }:
55
+ continue
56
+ try :
57
+ if hasattr (new_mod , attr ):
58
+ setattr (new_mod , attr , getattr (mod , attr ))
59
+ except (AttributeError , TypeError ):
60
+ # Skip attributes that can't be copied
61
+ pass
62
+
63
+
40
64
def do_versioning (self ):
41
65
42
66
logger .debug ("Check versioning" )
@@ -128,27 +152,69 @@ def do_versioning(self):
128
152
if version < (0 , 28 , 0 ):
129
153
# Handle old 'MESH' and 'BEZIER' convertion types
130
154
msg += "\n Update sketch conversion type to 'CURVE' for sketches:"
155
+
156
+ # Dictionary to temporarily store objects and their modifiers
157
+ old_objects = {}
158
+
131
159
for sketch in context .scene .sketcher .entities .sketches :
132
160
if sketch .convert_type == 'NONE' :
133
161
continue
134
162
135
- # Delete previously converted objects
163
+ # Store references to the old objects before deleting them
164
+ sketch_id = str (sketch .slvs_index )
165
+ old_objects [sketch_id ] = {
166
+ 'mesh_obj' : sketch .target_object ,
167
+ 'curve_obj' : sketch .target_curve_object
168
+ }
169
+
170
+ # Clear links to objects but don't delete them yet
136
171
if sketch .target_object :
137
172
sketch .target_object .sketch_index = - 1
138
- bpy .data .objects .remove (sketch .target_object , do_unlink = True )
139
173
sketch .target_object = None
174
+
140
175
if sketch .target_curve_object :
141
176
sketch .target_curve_object .sketch_index = - 1
142
- bpy .data .objects .remove (sketch .target_curve_object , do_unlink = True )
143
177
sketch .target_curve_object = None
144
178
145
179
# Change the conversion type
146
180
sketch .convert_type = 'CURVE'
147
181
148
182
msg += " {}" .format (str (sketch ))
149
183
150
- # Trigger the convertion with the new convert type
184
+ # Trigger the conversion with the new convert type
151
185
bpy .ops .view3d .slvs_update (solve = False )
152
-
186
+
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
192
+
193
+ if sketch .target_curve_object :
194
+ # 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 )
199
+
200
+ # Unlink and rename old objects instead of deleting them
201
+ for sketch_id , objects in old_objects .items ():
202
+ # Process mesh object
203
+ if objects ['mesh_obj' ]:
204
+ old_obj = objects ['mesh_obj' ]
205
+ # Unlink from all collections
206
+ for collection in old_obj .users_collection :
207
+ collection .objects .unlink (old_obj )
208
+ # Rename to indicate it's an old version
209
+ old_obj .name = f"OLD_{ old_obj .name } "
210
+
211
+ # Process curve object
212
+ if objects ['curve_obj' ]:
213
+ old_obj = objects ['curve_obj' ]
214
+ # Unlink from all collections
215
+ for collection in old_obj .users_collection :
216
+ collection .objects .unlink (old_obj )
217
+ # Rename to indicate it's an old version
218
+ old_obj .name = f"OLD_{ old_obj .name } "
153
219
154
220
logger .warning (msg )
0 commit comments