Page MenuHome

add_mesh_custom.py

add_mesh_custom.py

#!BPY
"""
Name: 'Custom Mesh'
Blender: 248
Group: 'AddMesh'
"""
"""
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import BPyAddMesh
from Blender import Draw, Mesh, Object
def add_custom_mesh(PREF_MESH_NAME):
me = Mesh.Get(PREF_MESH_NAME)
if me:
verts = []
faces = []
for v in me.verts:
verts.append( v.co )
for f in me.faces:
tmp_verts = []
for v in f.verts:
tmp_verts.append( v.index )
faces.append( tmp_verts )
return verts, faces
raise Exception
def get_selected_mesh():
ob = Object.GetSelected()[0]
if ob:
me_name = ob.getData(name_only=True)
return add_custom_mesh(me_name)
raise Exception
def main():
PREF_MESH_NAME = Draw.Create("dummy")
PREF_USE_SELECTED_MESH = Draw.Create(True)
if not Draw.PupBlock('Add Custom Mesh', [
('Selected Mesh:', PREF_USE_SELECTED_MESH, 0, 1, 'Set this to 1 if you want to use the mesh block of the currently selected object'),
('Mesh Name:', PREF_MESH_NAME, 0.01, 100, 'Name of the mesh datablock to add'),
]): return
try:
if PREF_USE_SELECTED_MESH.val:
verts, faces = get_selected_mesh()
else:
verts, faces = add_custom_mesh(PREF_MESH_NAME.val)
except Exception, e:
print 'No suitable mesh block found!'
return
BPyAddMesh.add_mesh_simple('Custom', verts, [], faces)
main()

File Metadata

Mime Type
text/x-python
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
b2/27/a096f4e2ab898d70e22b0c75f537

Event Timeline