0
$\begingroup$

I have a mesh with a series of vertex groups, and each vertex group must be resized based on specific proportions (i.e. by a factor of 2, factor of 3, etc.).

The code I've been trying to run is:

enter image description here

However, this scales the entire object.

I've also tried:

enter image description here

However, this creates the attached imageenter image description here

I would like the end result to look like this (which was created by manually selecting the vertices and scaling):enter image description here

Is this at all possible?

Thank you!

$\endgroup$
  • $\begingroup$ Just a hint: It seems to me that line 17-20 in your first code need three indents less and line 19 is useless. But it will not solve the problem. $\endgroup$ – Dimali Sep 6 '17 at 20:41
  • 1
    $\begingroup$ It is preferred that you paste your code (prefix each line with 4 spaces to make a code block) rather than use screenshots. $\endgroup$ – sambler Sep 7 '17 at 5:27
  • $\begingroup$ @Dimali thank you for the hint. I just started coding for this (as in within the past few weeks) so my code may not always be right. I'm curious if you could elaborate on this though. I though that under a for loop there needed to be an indent, and I added line 19 because I realized that the vertex group wouldn't be highlighted unless that line was included. Should it be highlighted without that? Any comments are helpful! As I said, I'm an extreme novice when it comes to this. $\endgroup$ – user33993 Sep 7 '17 at 15:38
0
$\begingroup$

Using a scale amount of 0.2 means scale to 20% of the current size, to increase the size you want to use 1.2 to be 20% bigger than the existing size.

You can also simplify what you have by using two operators to set the active vertex group and then select the vertices in that group.

import bpy

sfac = 1.2
vgrp = 'Group'

obj = bpy.context.active_object

bpy.ops.object.mode_set(mode='EDIT')

bpy.ops.mesh.select_all(action='DESELECT')
bpy.ops.object.vertex_group_set_active(group=vgrp)
bpy.ops.object.vertex_group_select()
bpy.ops.transform.resize(value=(sfac,sfac,sfac))

bpy.ops.object.mode_set(mode='OBJECT')

Part of the issue I see in the first image is that having a mirror modifier causes the scaling to pull away from the centre of the object and I think most of them are going past the halfway point to give you inverted mesh in the middle. One option is to do this without the mirror modifier. The other may be to position the 3D cursor and use it as the pivot point but that may get difficult depending on what else you plan to do.

$\endgroup$
  • $\begingroup$ Thank you so much for the help! Initially that code didn't work as there was an error selecting the vertex group so I coupled it with my code and it worked! $\endgroup$ – user33993 Sep 7 '17 at 16:06
  • $\begingroup$ def scale(a,index): #selects vertices within vertex group vlist = [] for v in a.data.vertices: for g in v.groups: if g.group == index: vlist.append(v.index) for v in vlist: obj.data.vertices[v].select = True bpy.ops.mesh.select_all(action='DESELECT') bpy.ops.object.vertex_group_set_active() bpy.ops.object.vertex_group_select() bpy.ops.transform.resize(value=(1.2,1.2,1.2)) return vlist $\endgroup$ – user33993 Sep 7 '17 at 16:07
  • $\begingroup$ If this answer solved your problem consider marking it as the solution. $\endgroup$ – Dimali Sep 7 '17 at 16:12
  • $\begingroup$ @user33993 the vgrp = 'Group' defines the name of the group to resize, you need to adjust that to the proper group name. $\endgroup$ – sambler Sep 8 '17 at 4:56
  • $\begingroup$ @sambler I had typed the group name as a string (vgrp = 'Radiusdorsalfin' for example) and it still wasn't working for some reason. This was initially how I tried to select vertex groups, but so far the only code that has worked thus far was the code mentioned above. I'm not really sure why, though, because intuitively this should work. $\endgroup$ – user33993 Sep 9 '17 at 20:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.