- 001
- 002
- 003
- 004
- 005
- 006
- 007
- 008
- 009
- 010
- 011
- 012
- 013
- 014
- 015
- 016
- 017
- 018
- 019
- 020
- 021
- 022
- 023
- 024
- 025
- 026
- 027
- 028
- 029
- 030
- 031
- 032
- 033
- 034
- 035
- 036
- 037
- 038
- 039
- 040
- 041
- 042
- 043
- 044
- 045
- 046
- 047
- 048
- 049
- 050
- 051
- 052
- 053
- 054
- 055
- 056
- 057
- 058
- 059
- 060
- 061
- 062
- 063
- 064
- 065
- 066
- 067
- 068
- 069
- 070
- 071
- 072
- 073
- 074
- 075
- 076
- 077
- 078
- 079
- 080
- 081
- 082
- 083
- 084
- 085
- 086
- 087
- 088
- 089
- 090
- 091
- 092
- 093
- 094
- 095
- 096
- 097
- 098
- 099
- 100
def do_creaprim(self, mesh, objname, addondir):
global message
objname = objname.replace(".", "")
objname = objname.replace(" ", "_")
bm = bmesh.new()
bm.from_mesh(mesh)
try:
txt = bpy.data.texts[str.lower("add_mesh_" + objname) + ".py"]
txt.clear()
except:
txt = bpy.data.texts.new("add_mesh_" + str.lower(objname) + ".py")
strlist = []
strlist.append("bl_info = {\n")
strlist.append("\"name\": \"" + objname + "\", \n")
strlist.append("\"author\": \"Gert De Roost\",\n")
strlist.append("\"version\": (1, 0, 0),\n")
strlist.append("\"blender\": (2, 65, 0),\n")
strlist.append("\"location\": \"Add > Mesh\",\n")
strlist.append("\"description\": \"Create " + objname + " primitive.\",\n")
strlist.append("\"warning\": \"\",\n")
strlist.append("\"wiki_url\": \"\",\n")
strlist.append("\"tracker_url\": \"\",\n")
strlist.append("\"category\": \"Add Mesh\"}\n")
strlist.append("\n")
strlist.append("\n")
strlist.append("if \"bpy\" in locals():\n")
strlist.append(" import imp\n")
strlist.append("\n")
strlist.append("\n")
strlist.append("import bpy\n")
strlist.append("import bmesh\n")
strlist.append("import math\n")
strlist.append("from mathutils import *\n")
strlist.append("\n")
strlist.append("\n")
strlist.append("\n")
strlist.append("\n")
strlist.append("class " + objname + "(bpy.types.Operator):\n")
strlist.append(" bl_idname = \"mesh." + str.lower(objname) + "\"\n")
strlist.append(" bl_label = \"" + objname + "\"\n")
strlist.append(" bl_options = {\'REGISTER\', \'UNDO\'}\n")
strlist.append(" bl_description = \"add " + objname + " primitive\"\n")
strlist.append("\n")
strlist.append(" def invoke(self, context, event):\n")
strlist.append("\n")
strlist.append(" mesh = bpy.data.meshes.new(name=\"" + objname + "\")\n")
strlist.append(" obj = bpy.data.objects.new(name=\"" + objname + "\", object_data=mesh)\n")
strlist.append(" scene = bpy.context.scene\n")
strlist.append(" scene.objects.link(obj)\n")
strlist.append(" obj.location = scene.cursor_location\n")
strlist.append(" bm = bmesh.new()\n")
strlist.append(" bm.from_mesh(mesh)\n")
strlist.append("\n")
strlist.append(" idxlist = []\n")
posn = 0
strlist.append(" vertlist = [")
for v in bm.verts:
if posn > 0:
strlist.append(", ")
posn += 1
strlist.append(str(v.co[:]))
strlist.append("]\n")
strlist.append(" for co in vertlist:\n")
strlist.append(" v = bm.verts.new(co)\n")
strlist.append(" bm.verts.index_update()\n")
strlist.append(" idxlist.append(v.index)\n")
posn = 0
strlist.append(" edgelist = [")
for e in bm.edges:
if posn > 0:
strlist.append(", ")
posn += 1
strlist.append("[" + str(e.verts[0].index) + ", " + str(e.verts[1].index) + "]")
strlist.append("]\n")
strlist.append(" for verts in edgelist:\n")
strlist.append(" try:\n")
strlist.append(" bm.edges.new((bm.verts[verts[0]], bm.verts[verts[1]]))\n")
strlist.append(" except:\n")
strlist.append(" pass\n")
posn1 = 0
strlist.append(" facelist = [(")
for f in bm.faces:
if posn1 > 0:
strlist.append(", (")
posn1 += 1
posn2 = 0
for v in f.verts:
if posn2 > 0:
strlist.append(", ")
strlist.append(str(v.index))
posn2 += 1
strlist.append(")")
strlist.append("]\n")
strlist.append(" bm.verts.ensure_lookup_table()\n")
strlist.append(" for verts in facelist:\n")