Makes No Sense

I have a problem that makes no sense. I have written and operator to create a custom object, using bezier curves. Here is part of the code:


class MESH_OT_primitive_cable_add(bpy.types.Operator):
    bl_idname="mesh.primitive_cable_add"
    bl_label="Stretch a Cable"
    bl_options={'REGISTER','UNDO'}
    
    E0=FloatVectorProperty(name="Start Point",subtype='XYZ',precision=5,step=1,default=[0.0,-1.0,0.0])
    E1=FloatVectorProperty(name="End Point",subtype='XYZ',precision=5,step=1,default=[0.0,1.0,0.0])
    Sag=FloatProperty(name="Cable Sag",precision=3,step=1,default=1.0)
    Solid=BoolProperty(name="Solidify",default=True)
    Radius=FloatProperty(name="Cable Radius",precision=4,step=1,default=0.1)
    CableRes=IntProperty(name="Sag Res",default=12,min=1)
    XsecRes=IntProperty(name="Circum Res",default=4,min=1)
          
    def execute(self,context):
        bpy.ops.object.select_all(action='DESELECT')
        Cable=HangCable(context,self.E0[0],self.E0[1],self.E0[2],self.E1[0],self.E1[1],self.E1[2],self.Sag,self.CableRes)
        context.scene.objects.link(Cable)
        Cable.select=True
        context.scene.objects.active=Cable
        bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY',center='MEDIAN')   # set origin            
        
        if self.Solid==True:
            Xsec=CreateBevel(self.Radius,self.XsecRes)  #Create Bezier Circle
            context.scene.objects.link(Xsec)
            bpy.data.objects["Xsec"].hide=True
            bpy.context.object.data.bevel_object=bpy.data.objects["Xsec"]  # bevel cable curve
            bpy.ops.object.convert(target='MESH',keep_original= False)   # convert active to mesh
            bpy.ops.object.shade_flat()
            context.scene.objects.unlink(Xsec)   # remove circle

        return {'FINISHED'}

HangCable() and CreateBevel() are functions that create custom bezier curves.

Now, the crazy part: If I add the expression: I=self.XsecRes*4 anywhere in the execute() function, the operator no longer works properly. “XsecRes” is used to set “resolution_u” of the bezier circle, in the CreateBevel() function. The value can be changed in the user interface. However, when I add I=self.XsecRes resolution_u can no longer be changed. The integer value of “XsecRes” changes—but, not resolution_u in the circle’s data.

How is this possible? I can find absolutely nothing to cause this!

I forgot to mention the rest of the crazy part. Even if I remove the line: I=self.Xsecres*4 and rerun the script, “resolution_u” still remains locked,even though the IntProperty XsecRes is changing. I literally have to close Blender and restart, to get that operator working properly again.

Well, as usual, the cause turned out to be something other than what it appeared to be. For some reason, at random intervals, this last line of code would fail to remove the object “Xsec”: context.scene.objects.unlink(Xsec) I had to replace it with this more convoluted piece of code:


            bpy.ops.object.select_all(action='DESELECT')
            Xsec.select=True
            context.scene.objects.active=Xsec
            bpy.ops.object.delete()
            Cable.select=True
            context.scene.objects.active=Cable

So far, it seems to be working. I have not had any more mysterious lock-ups. But, I’d better not speak too soon. That problem could still come back to bite me.