1

I have a model containing two meshes which need to be resized with python. Let's call them an artwork and a frame.

I want to resize the artwork depending on parameters passed in, but for simplicity have specified a width and height in the code below.

Once I have resized the artwork, I want to resize the frame to fit around it. What would be the best way to calculate this and the set the new vertice positions on my frame? In the code below the frame is 0.01349312067 thick. The frame has an inner edge and an outer edge.

So far, just trying to get the height correct, I have run into an error of 'BMVertSeq' object does not support item assignment when I try to write the new vertice values.

Any suggestions on how to make this work, or even a completely different approach are very welcome. Thanks

import bpy
import bmesh

artworkData = bpy.context.scene.objects['Back1.033'].data frameData = bpy.context.scene.objects['Frame1.034'].data

imgWidth = 744 imgHeight = 1000 multiplier = 5

artworkMesh = bpy.data.objects['Back1.033'] frameMesh = bpy.data.objects['Frame1.034']

artworkMesh.scale = ((imgWidth / 10000) * multiplier, (imgHeight / 10000) * multiplier, 0.015)

artworkData.update() frameData.update()

art = bmesh.new() art.from_mesh(artworkData) art.verts.ensure_lookup_table()

vert0Coordinates = bpy.data.objects['Back1.033'].matrix_world @ art.verts[0].co.xyz vert1Coordinates = bpy.data.objects['Back1.033'].matrix_world @ art.verts[1].co.xyz vert2Coordinates = bpy.data.objects['Back1.033'].matrix_world @ art.verts[2].co.xyz vert3Coordinates = bpy.data.objects['Back1.033'].matrix_world @ art.verts[3].co.xyz vert4Coordinates = bpy.data.objects['Back1.033'].matrix_world @ art.verts[4].co.xyz vert5Coordinates = bpy.data.objects['Back1.033'].matrix_world @ art.verts[5].co.xyz vert6Coordinates = bpy.data.objects['Back1.033'].matrix_world @ art.verts[6].co.xyz vert7Coordinates = bpy.data.objects['Back1.033'].matrix_world @ art.verts[7].co.xyz

import array as arr artHeights = arr.array('d', [vert0Coordinates[2], vert1Coordinates[2],vert2Coordinates[2],vert3Coordinates[2],vert4Coordinates[2],vert5Coordinates[2],vert6Coordinates[2],vert7Coordinates[2]])

Store the highest and lowest points of the artwork so we can calculate the frame from this

maxArt = -100 minArt = 100

for x in artHeights: if x > maxArt: maxArt = x elif x < minArt: minArt = x

frame = bmesh.new() frame.from_mesh(frameData) frame.verts.ensure_lookup_table()

vert0Coordinates = bpy.data.objects['Frame1.034'].matrix_world @ frame.verts[0].co.xyz #Set to minArt - 0.01349312067 new_location = vert0Coordinates new_location[0] = new_location[0] #X new_location[1] = new_location[1] #X new_location[2] = minArt - 0.01349312067 frame.verts[0] = bpy.data.objects['Frame1.034'].matrix_world.inverted() @ new_location #This is the line that causes the BMVertSeq mentioned in the question

and so on.... setting the coordinates for all 16 vertices.

frame.to_mesh(frameData)

artworkData.update() frameData.update()

enter image description here

mjuk
  • 111
  • 1
  • Set the vertex coordinate v.co , not the vertex v. ie frame.verts[0].co = some_vector – batFINGER Jun 15 '21 at 08:40
  • Thanks batFINGER, that fixed the 'BMVertSeq' object does not support item assignment error and the rest is all working! – mjuk Jun 15 '21 at 10:35

0 Answers0