Mesh World Script ??

I’ve been beating my head against the wall and could definitely use some insight/help. The attached file contains a hex-grid for a mesh-style world for a game similar to Civ IV. The grid was created by starting with a circle, changing the vertices to 6, then rotating in edit mode – the rest was done using modifiers.

I’ve been trying to develop a script in v2.5 to duplicate this process, but with limited documentation of the function changes I have been totally unsuccessful. I can add a circle, but have not found the python command to change the number of vertices to 6 or enter edit mode to rotate the mesh 15 deg (I’ve looked at the transform function, but not sure how it works).

So, bottom line is … help!? Any inputs or feedback would be appreciated! Thanks!

meshworld.blend (558 KB)

A2G

bpy.ops.mesh.primitive_circle_add( arguments )
arguments are here http://www.blender.org/documentation/250PythonDoc/bpy.ops.mesh.html

orinoco56 - you’re my new hero! :slight_smile: … didn’t know that info was available for the 2.5 version. Has answered MANY of my questions regarding other functions as well. TY TY TY !!!

Follow up question on structure/syntax …


from bpy import *
ops.mesh.primitive_circle_add(vertices=6, radius=1.0)
ops.object.modifier_add(type='ARRAY')

The snippit above adds a hexagonal element and creates an array modifier. But what’s the syntax/structure for changing the array count to say 10?

Mouse over the ‘count’ in the properties window and it says “ArrayModifier.count”. I thought this meant assigning a pointer to the created element object and then simply accessing the value … but the following doesn’t work and my limited brain power is suffering greatly … can someone explain or show an example?


from bpy import *
element = ops.mesh.primitive_circle_add(vertices=6, radius=1.0)
ops.object.modifier_add(type='ARRAY')
element.count = 10 # THIS DOESN'T WORK ??? 

Thanks!

A2G

Hi,
You need to access the object itself as the variable ‘element’ in your code doesn’t store it, try printing its value to see what it contains.

Try this instead of your last line to change the array,

data.objects['Circle'].modifiers['Array'].count = 10

This code assumes that your new circle object is call ‘Circle’ and your new array is called ‘Array’. Be careful because if there’s already an object in the scene call ‘Circle’ when you run the script it won’t work as expected. To see this just run the script twice and have a look.
Enjoy,
Truman

majority of operators in bpy.ops don’t return the added object but ‘{FINISHED}’
so everytime you must first make a reference for the added object, so you can access it when you want

from bpy import *

ops.mesh.primitive_circle_add(vertices=6, radius=1.0)
obj_act = context.active_object
obj_act.name = “myObjName”

ops.object.modifier_add(type=‘ARRAY’)
mod_act = context.scene.objects[“myObjName”].modifiers[0]
mod_act.name = “myModifierName”
mod_act.count = 5

TrumanBlending & Orinoco56 - Thanks for the replys! I did try printing the operator that was returned by the primitive_circle_add function and yes, it returned a ‘{FINISHED}’ response, which sent me off on a new tanget to understand the return values, what they meant, and why in 2.5 they changed from returning the object itself. My head is still reeling from that little excursion …

As for snippits - I was working towards something similar to what TrumanBlending replied, but Orinoco56’s snippit seems a little cleaner since I’ll need to eventually add multiple sets of array modifiers. Definitely appreciate the feedback - your examples helped me to understand several other questions that have been pending in my noggin !!! TY!

A2G