how to debug (e.g. reveal) object attributes. i'm really frustrated.

hello,

I’m trying to position and modify geometry of a set of metaballs (capsules), but i cannot figure out why the “size_x” attribute is not available. Where is it?

Also, I’m really upset that I cannot find a way to display or determine attributes of a structure. I understand that there is no ‘debug’ in blender/python but at least I would like to know what the attributes of a structure are… i’ve searched on this and come up with nothing.

how the hell do you program anything if you can’t debug/find the attributes of an array or structure???

so far everything works below except i cannot set the magnitude (or length) of the capsule. nothing works.

I’ve attached my code below but for some reason it looks very strange on my screen (all white). doing the best i can here. it should be simple.

The problem part of the code is at the ‘cylinder.size_x = mag’ line where it just fails and says that there is no ‘size_x’ attribute. HOWEVER, that is clearly an attribute when i try to edit it in the blender gui. i’ve tried going into edit mode (in python) and performing the mag change but I just get the same error.

WTF!!! i feel really stupid.



"""
Blender script. Draws metaball 'capsules' along lines.
Written by T.C.Doeh (tensortek.com) 4/11/2013
Based upon code by Patrick Fuller, [email protected]


"""


import bpy
from math import acos, degrees, pi
from mathutils import Vector


import json
          
colors = {"medgray": (50, 50, 50), "light_gray": (118, 118, 118), "gray": (11, 11, 11)}   


# Normalize to [0,1] and make blender materials
for key, value in colors.items():
    value = [x / 255.0 for x in value]
    bpy.data.materials.new(name=key)
    bpy.data.materials[key].diffuse_color = value
    bpy.data.materials[key].specular_intensity = 0.5


    # Don't specify more parameters if these colors
    if key == "gray" or key == "light_gray" or key == "medgray":
        continue


    # Transparency parameters
    bpy.data.materials[key].use_transparency = True
    bpy.data.materials[key].transparency_method = "RAYTRACE"
    bpy.data.materials[key].alpha = 0.1 if key == "clear" else 0.95
    bpy.data.materials[key].raytrace_transparency.fresnel = 0.1
    bpy.data.materials[key].raytrace_transparency.ior = 1.15






def draw_network(network, edge_thickness=1.2, node_size=2.1, directed=True):
    """ Takes assembled network/molecule data and draws to blender """


    bpy.ops.object.select_all(action='DESELECT')


    # Draw edges
    ecount = 0
    for edge in network["edges"]:
        ecount += 1
        # Get source and target locations by drilling down into data structure
        source_loc = network["nodes"][edge["source"]]["location"]
        target_loc = network["nodes"][edge["target"]]["location"]


        diff = [c2 - c1 for c2, c1 in zip(source_loc, target_loc)]
        cent = [(c2 + c1) / 2 for c2, c1 in zip(source_loc, target_loc)]
        mag = sum([(c2 - c1) ** 2
                  for c1, c2 in zip(source_loc, target_loc)]) ** 0.5


        # Euler rotation calculation
        v_axis = Vector(diff).normalized()
        v_obj = Vector((1, 0, 0))
        v_rot = v_obj.cross(v_axis)
        angle = acos(v_obj.dot(v_axis))


        # Copy mesh primitive to create edge
        #bpy.ops.object.select_all(action='DESELECT')
        bpy.ops.object.metaball_add(type = 'CAPSULE',rotation = (0,-pi/2,0))
        cylinder = bpy.context.object
        cylinder.active_material = bpy.data.materials["light_gray"]
        cylinder.location = cent
        cylinder.size_x = mag
        #return
        #edge_cylinder.size_x = mag
        #bpy.ops.object.mode_set(mode='OBJECT')
        cylinder.rotation_mode = "AXIS_ANGLE"
        cylinder.rotation_axis_angle = [angle] + list(v_rot)
        #bpy.context.scene.objects.link(cylinder)
        #shapes.append(edge_cylinder)
        #shapes_to_smooth.append(edge_cylinder)


    # If the starting cube is there, remove it
    if "Cube" in bpy.data.objects.keys():
        bpy.data.objects.get("Cube").select = True
    bpy.ops.object.delete()


    # Join shapes
    #for shape in shapes:
    #    shape.select = True
    #bpy.context.scene.objects.active = shapes[0]
    #bpy.ops.object.join()


    # Center object origin to geometry
    bpy.ops.object.origin_set(type="ORIGIN_GEOMETRY", center="MEDIAN")


    # Refresh scene
    bpy.context.scene.update()


# If main, load json and run
if __name__ == "__main__":
    with open("edgenode.json") as network_file:
        network = json.load(network_file)
    draw_network(network)
    

The Blender Python API: http://www.blender.org/documentation/blender_python_api_2_66_release/# is a handy source of info. The link is also available via the Blender Help menu.

If I understand your code, then the Object scale command is what you’re after. A search of “size_x” in the API page brings up seven results-- none of which look to be associated with objects.

dir(cylinder) in the console will show what is available for your cylinder. I think.

Use dir() or, import getmembers from inspect

 from inspect import getmembers

and print that to show the name-> value or each attribute. ALso, ask questions!

UI doesn’t show Size X/Y/Z for capsule meta elements, for other types it does however. Just hover one of those props and the tooltip will show you the bpy type, which you can find easily in the API docs.

e.g.
bpy.context.object.data.elements.active.size_x = 5

Blender’s data structures are object oriented, how could that be represented as an array? It’s polyhierarchical…

Hi,
thanks for all of the replies and info! i’m working the suggestions here and on a solution. what i’m trying to do is have separate meta-capsules for each ‘line’ of the ‘mesh’. Each meta-capsule has a different length (e.g. size_x). i’m trying to understand how to make separate meta objects… I would just make ‘elements’ but there is a 20 element limit for each meta object so that’s out. I’ve got about 2000. So for now it makes the most sense to me to make each meta-capsule a single object with one element and then size_x the element. My crude first shot at this unfortunately right now seems too slow.

Probably I’m missing something obvious, but it’s getting closer. I’ve got a basic script working but I’m still trying to understand the mball structure…

Thanks very much again for all the suggestions and I’ll give an update asap.