Diamond structure generation

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

sladak
Posts: 2
Joined: Wed Jun 27, 2012 6:17 pm

Diamond structure generation

Postby sladak » Wed Jun 27, 2012 6:23 pm

Hi

I have written a script to generate a diamond structure (below). I have used cylinders to create the individual bonds. The problem is I need to mesh it such that there is no internal structure, and this is not the case where the cylinders intersect. Any ideas on how i can delete the internal structure of the bonds where the cylinders cross over, and then export it as a single object?

import bpy
#SPH V0.1
#Define cylinder width
cw=0.1 #minimum 0.1

#Define unit cell size (for one micron cylinders, take a=>2.2727273)
a=10.0

# DEFINE NUMBER OF CELLS
cellx=1
celly=1
cellz=1


#DEFINITION BLOCK - LEAVE ALONE FOR NOW

#Cylinder length
cl=0.43301*a
#Cylinder co-ord
cc=0.125*a

def makeMeshC1(x,y,z):
bpy.ops.mesh.primitive_cylinder_add(vertices=320,radius=cw,depth=cl,location=(x,y,z),rotation=(0.0,0.95531661812,0.785398))
return bpy.context.object
def makeMeshC2(x,y,z):
bpy.ops.mesh.primitive_cylinder_add(vertices=320,radius=cw,depth=cl,location=(x,y,z),rotation=(0.0,-0.95531661812,0.785398))
return bpy.context.object
def makeMeshC3(x,y,z):
bpy.ops.mesh.primitive_cylinder_add(vertices=320,radius=cw,depth=cl,location=(x,y,z),rotation=(3.14159,-0.942478,-0.785398))
return bpy.context.object
def makeMeshC4(x,y,z):
bpy.ops.mesh.primitive_cylinder_add(vertices=320,radius=cw,depth=cl,location=(x,y,z),rotation=(-3.14159,0.942478,-0.785398))
return bpy.context.object
def MakeSite(x,y,z):
makeMeshC1(x+cc,y+cc,z+cc)
makeMeshC2(x-cc,y-cc,z+cc)
makeMeshC3(x+cc,y-cc,z-cc)
makeMeshC4(x-cc,y+cc,z-cc)
bpy.ops.mesh.primitive_uv_sphere_add(size=cw,location=(x,y,z))
bpy.ops.mesh.primitive_uv_sphere_add(size=cw,location=(x+2.0*cc,y+2.0*cc,z+2.0*cc))
return bpy.context.object
def makeCell(x,y,z):
MakeSite(x,y,z)
MakeSite(x+0.5*a,y+0.5*a,z)
MakeSite(x+0.5*a,y,z+0.5*a)
MakeSite(x,y+0.5*a,z+0.5*a)
return bpy.context.object


# Structure generation run
for i in range(0,(cellx)):
for j in range(0,(celly)):
for k in range(0,(cellz)):
makeCell(i*a,j*a,k*a)

CoDEmanX
Posts: 894
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Postby CoDEmanX » Wed Jun 27, 2012 7:20 pm

you could use CreaPrim as a base, then integrate your code to make it dynamical:

http://blenderartists.org/forum/showthr ... ow-on-2.63

it's generally not a good idea imo, to use several operators to create primitives and stick them together. I'd rather use low-level mesh functions, as they are way faster and more flexible, but on the other hand a lot more difficult to program...
I'm sitting, waiting, wishing, building Blender in superstition...


Return to “Python”

Who is online

Users browsing this forum: No registered users and 0 guests