I can create a mesh in blender with this script:
mesh = bpy.data.meshes.new("mymesh")
obj = bpy.data.objects.new("myobj", mesh)
bpy.context.scene.collection.objects.link(obj)
mesh.from_pydata([[0, 0, 0], [1, 0, 0], [1, 1, 0]], [], [[0, 1, 2]])
However, if I try to update the mesh data with from_pydata
again, it results in an error:
RuntimeError: internal error setting the array
Is there a way to update the mesh data after the mesh has been created?
(I'm trying to avoid deleting the object and creating it again with new data.)
The from_pydata
function takes lists of data and creates a mesh data block . Once you have the mesh data block you can adjust the mesh properties directly. These can be found in the vertices
, edges
andpolygons
properties of the mesh data.
obj.data.vertices[0].co.x = 1.25
Mostly this data should not be directly altered, any changes made while in edit mode will get overwritten as the edit mesh is stored as bmesh data. The bmesh module provides faster access and methods to alter mesh data and can also update the mesh while in edit mode.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.