
Code: Select all
# Search comments for tyre flags
if tyre_string in comments[ (each_element - 1) ]:
print(comments[ (each_element - 1) ] + comments[ each_element ] + "\n")
ascii_num += 1
# Set width of tyre
depth = position_m[ (each_element) ] - position_m[ (each_element - 1) ]
# Generate inner diameter cylinder for boolean difference
bpy.ops.mesh.primitive_cyli:?: nder_add(vertices=32, radius=Rad, depth=(depth + 1.0),
end_fill_type='NGON', view_align=False, enter_editmode=False,
location=(0, ((position_m[ each_element ] + position_m[each_element - 1])/2.0), 0),
rotation=((pi/2),0,0), layers=(True, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False))
# Assign active object to a variable for later identification
cyl1 = bpy.context.active_object
cyl1_name = bpy.context.active_object.name
# Diagnostic print to console
print(cyl1)
# Generate outer diameter cylinder for boolean difference
bpy.ops.mesh.primitive_cylinder_add(vertices=32, radius=(Rad + (Rad * 0.50
)),
depth=(depth), end_fill_type='NGON', view_align=False, enter_editmode=False,
location=(0, ((position_m[ each_element ] + position_m[ (each_element - 1) ])/2.0), 0),
rotation=((pi/2.0),0,0), layers=(True, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False, False, False, False, False))
# Assign active object to a variable for later identification
cyl2 = bpy.context.active_object
# Diagnostic print
print(cyl2)
# Apply material to outer tyre
bpy.context.object.data.materials.append(tyre_mat)
# Conduct boolean difference to generate tyre
bpy.ops.object.select_all(action='DESELECT')
# Set active object to outer cylinder
bpy.context.scene.objects.active=cyl2
# Create modifier
bpy.ops.object.modifier_add(type='BOOLEAN')
# Select modifier object to inner diameter cylinder
cyl2.modifiers[0].object = cyl1
# Set operation
cyl2.modifiers[0].operation = 'DIFFERENCE'
# Conduct boolean
bpy.ops.object.modifier_apply(apply_as='DATA', modifier=cyl2.modifiers[0].name)
# Remove inner diameter cylinder after boolean
bpy.ops.object.select_all(action='DESELECT')
# Select inner diameter cylinder as active
bpy.context.scene.objects.active=cyl1
# Diagnostic information for console
temp=bpy.context.active_object.name
print("Active object is: " + temp)
# Delete active object
bpy.ops.object.delete(use_global=True)
else:
print ('Tyre ID not found at %i \n' % (each_element))
This code builds a piece of machinery from data in a CSV file. The "tyres" are constructed from a boolean difference of two cylinders. The goal is to create an automated script to generate this machinery and its animation without user intervention. The user starts the tool from the panel, selects their input file, and Blender does the rest. My problem is that the object deletion is not working within the script itself.
I can delete the inner cylinder within the interface in the 3D View context. I can assign the inner cylinder to variable in the console, make it active, and then run the bpy.ops.object.delete(use_global=True) and the object is deleted. In the script, however, I cannot seem to get it to work. I receive no errors on the console...the boolean happens correctly, but the inner cylinders still exist.
How may I delete these inner cylinders from within the python script? Am I calling the wrong delete operation? What additional information may you all need from me to look into this?
Thanks,