Can anyone help me with this scripting problem, that has me cussing-up a storm. I am writing an operator script, that creates a custom object, using a curve and a bevel object.
The problem that keeps coming back to bite me, is the bevel object. I really want to just use a Blender operator to create a circle, for the bevel. The trouble is, Blender could name it “Circle”, or “Circle.001”, or "Circle.002, etc. so, my script loses track of the name, and crashes. I can’t keep the circle as the active object, because the main curve has to be active, to receive the bevel. So, I need to be able to call the circle by name—whatever name Blender happens to assign to it.
Is there some kind of “dummy variable” that i could use, like one of the double-underscore" (like, “name”)? I only use that bevel object for a few lines of code, before it is deleted. The user never sees to bevel circle or its name. It is only used by the python code.
Or, is there a better, more reliable way to do this, that is completely different?
P.S. I’ve also gone the route of creating my own circle, with a hard-coded name, from scratch, using math functions. It works. But, from time to time, a glitch again leads to an inconsistency in names (".001", “.002”, etc) leading to an error crash.
Well, after much research, and a few SWAG’s, I found a way to accomplish what I wanted. Here is a sample of the code that I came up with:
bpy.ops.mesh.primitive_circle_add(vertices=self.XsecRes,radius=self.Radius) # create bevel object
bpy.ops.object.convert(target='CURVE',keep_original= False) # convert bevel to curve object
__bvl_name=bpy.context.object.name # get bevel object's assigned name
bpy.ops.object.select_pattern(pattern=__bvl_name,case_sensitive=True) # select bevel object by assigned name
bpy.context.scene.objects.active=bpy.data.objects[__bvl_name] #make bevel object active using assigned name
bpy.ops.object.delete() #delete bevel object
The value “__bvl_name” is a string variable, which holds whatever name that Blender assigned to the circle in line 1. If Blender gave the circle, the name: “Circle.004”, line 3 would be equivalent to the expression: __bvl_name=“Circle.004”. Now, __bvl_name can be used anywhere that a string argument is required. Note its use in the third-to-last and second-to-last lines—commands to first to select the circle, and then, to make it the active object. The last line simply deletes the circle (now, the active object) when it is no longer needed.
Also, a double-underscore was used at the beginning of the variable name, to further reduce the possibility of conflicts outside of the operator’s class.