2
$\begingroup$

I'm trying to set up a workflow which involves as many reusable parts as possible.

I've written a vecCircle module which places a circle but it's not working because the example code I used is from a 2.5 doc source and there is no equivalent in 2.6. I'm using 2.74 and it looks like the API is a 2.6 API - I presume that's right.

The example from http://wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Cookbook/Code_snippets/Three_ways_to_create_objects

Includes the code

ob = bpy.context.object

which is an error in my pydev instance due to this being ro in this release. Can anyone tell me how the following should be rewritten? I'm not a python noob but blender Python noob.

def createMeshFromPrimitive(name, origin):
    bpy.ops.mesh.primitive_cone_add(
        vertices=4, 
        radius=1, 
        depth=1, 
        cap_end=True, 
        view_align=False, 
        enter_editmode=False, 
        location=origin, 
        rotation=(0, 0, 0))

    ob = bpy.context.object
    ob.name = name
    ob.show_name = True
    me = ob.data
    me.name = name+'Mesh'
    return ob
$\endgroup$
3
  • $\begingroup$ are you sure you meant 'Circle' and not 'Cone' ? $\endgroup$
    – zeffii
    Commented Sep 21, 2015 at 10:20
  • $\begingroup$ I want to create circles at the moment, but the code snippet I was hoping could be explained from the old API doc creates cones. $\endgroup$
    – volvox
    Commented Sep 22, 2015 at 17:22
  • $\begingroup$ seen as you are using a much newer version of Blender than is referenced in the 2.5 cookbook, you should read the API of the current release (it has a great search feature) . I've shown you where to find the docs. $\endgroup$
    – zeffii
    Commented Sep 22, 2015 at 17:51

2 Answers 2

2
$\begingroup$

The snippet you pasted relies on old API calls, and when it is run in a recent version of Blender it will produce the following exception / Error message

TypeError: Converting py args to operator properties: : 
keyword "radius" unrecognized
Error: Python script fail, look in the console for now...

Bookmark this link www.blender.org/api/250PythonDoc/, it points at the latest docs automatically. You can also use the help menu.

enter image description here

See the current API page for bpy.ops.mesh.primitive_cone_add, You'll see that now (September 2015) must specify radius1 or radius2, radius doesn't exist anymore. And cap_end is now end_fill_type

Parameters:  

  - vertices (int in [3, 10000000], (optional)) – Vertices
  - radius1 (float in [0, inf], (optional)) – Radius 1
  - radius2 (float in [0, inf], (optional)) – Radius 2
  - depth (float in [0, inf], (optional)) – Depth
  - end_fill_type (enum in [‘NOTHING’, ‘NGON’, ‘TRIFAN’], (optional)) –
  - (....)

For the circle example you might use something like this.

import bpy

def makePrimitiveCircle(objName, v, r, f, loc, rot, layers=[0]):
    bpy.ops.mesh.primitive_circle_add(
        vertices=v, 
        radius=r, 
        fill_type=f, 
        view_align=False, 
        enter_editmode=False, 
        location=loc, 
        rotation=rot,
        layers=[(i in layers) for i in range(20)])
    ob = bpy.context.active_object
    ob.name = objName
    ob.show_name = True
    me = ob.data
    me.name = objName + 'Mesh'
    return ob

f = makePrimitiveCircle('pizza', 20, 1.2, 'NGON', (1,2,0), (0,0,0))
print(f)  # does return the new object
# <bpy_struct, Object("pizza")>  


# you could use this to specify layers directly..
makePrimitiveCircle('pizza', 20, 1.2, 'NGON', (1,2,0), (0,0,0), layers=[0,3,5])
$\endgroup$
1
  • $\begingroup$ Thanks, but I didn't get this error. $\endgroup$
    – volvox
    Commented Sep 22, 2015 at 17:48
0
$\begingroup$

The following code in my module did the trick. Although it meant the scene runs with the most recent object selected.

## create mesh and object
#
bpy.ops.mesh.primitive_circle_add(vertices=v, radius=r, fill_type=f, view_align=False, enter_editmode=False, location=(locX, locY, locY), rotation=(rotX, rotY, rotZ), layers=l)
ob = bpy.context.scene.objects.active
ob.name = objName
ob.show_name = True
me = ob.data
me.name = objName+'Mesh'
return ob
$\endgroup$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .