I created cylinders using the bpy.ops.mesh.primitive_cylinder_add() command (I used this example). How can I update their radius (or any other property) using python script, instead of deleting the objects and recreate them? I'm using those cylinders to display connection between areas in the brain, as part of an addon I'm implementing. I want to let the user to pick the radius of the cylinders (for rendering purposes), or to automatically change them according to the connections' strength (which may vary).

  • $\begingroup$ Creation is usually viewed as a one way operation with no long term guarantees. Do you allow editing of the mesh such that the result is no longer recognizable to most people as a sphere? What is the larger picture of what you are trying to do? You may get more help by answering that question. $\endgroup$ – atomicbezierslinger Jan 27 '16 at 19:14
  • $\begingroup$ My question is still the same above in the comments. I tend to think at this time I can not provide any insight to you. I do not understand your larger goal. Please place you work in the question rather than a link. Please state your experience with Python. $\endgroup$ – atomicbezierslinger Jan 28 '16 at 5:21
  • $\begingroup$ The link is just for the code how I created the cylinder. My end users are going to work wit Blender. I changed the layout and added some buttons. One of the options is to create connections between areas in the brain. I want to let the users the option to change the cylinders properties (like radius) after they created them. Does it make more sense? $\endgroup$ – Noam Peled Jan 28 '16 at 16:15

An example using a custom property with an update method.

import bpy
from bpy.props import FloatProperty
context = bpy.context
scene = context.scene

def bond_strength(self, context):
    self.scale.x = self.scale.y =  self.bond_strength
    return None

# create a custom property on all objects
bpy.types.Object.bond_strength = FloatProperty(name="Strength",
                                               default = 1.0,
                                               precision = 4,

# adds a slider to UI object properties panel. # would be in a custom Panel
if True: # only need to run this once
    def show_strength(self, context):
        self.layout.prop(context.object, "bond_strength")
    bpy.types.OBJECT_PT_context_object.remove(show_strength) # put in unregister   

# add a primitive

#create more
cyl = context.active_object  # newly created cylinder

for i in range(4):
    cyl = cyl.copy()
    cyl.bond_strength *= 0.5
    cyl.location.x += 2
|improve this answer|||||

You can set the scale of any of the XYZ axis in Python which can effectively change the radius.

You can also consider shape keys.

Since any mesh object can be edited we do have a worst case scenario. Near Worse case scenario might be all vertices deleted except 1 vertex.

|improve this answer|||||
  • $\begingroup$ So given that I already created a cylinder, what script should I use to change its radius, lets say from 0.05 to 0.1? $\endgroup$ – Noam Peled Jan 28 '16 at 0:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.