0
$\begingroup$

I have modeled a 3D image of a whale and have to scale the total length (in the y dimension) and then scale individual vertex groups (in the x and z direction).

The scaling factors used for the vertex groups are based on the radial measurement I want it to reflect divided by the radial measurement of the individual model. However, using measureit I have found that when scaling the length only in the y direction is still slightly changes the radial measurement of the vertex groups, and therefore changes what the scaling factor for the vertex groups should be.

Since I am working with a large amount of data I cannot scale the total length, measure the circumference of the vertex groups and then scale the vertex groups accordingly. Is there any way to insure that while scaling in the y direction all other measurements are secured in place?

The code I am using is as follows:

import bpy

obj = bpy.context.active_object
totallength = .843504
whale = [0]
vgrp = ['Face', 'Reye', 'Rpostpec', 'Rantdslfin', 'Rpostpdslfin', 'Ranus', 
'Rmidkeel', 'Rend']
sfac =[0.792018666, 0.792018666, 0.818984445,0.857604997,0.821038612,0.623493015,0.56712762,0.56712762] #list of all scaling factors for vertex groups


def scale(vgrp,sfac): 
    '''
    scale vertex group of name vgrp 
    based on scaling factor of name sfac
    '''
    bpy.ops.object.mode_set(mode='EDIT') #set program in edit mode
    bpy.ops.mesh.select_all(action='DESELECT') #deselect any previously selected vertex groups
    bpy.ops.object.vertex_group_set_active(group=vgrp) #set vertex group active based on name in vgrp
    bpy.ops.object.vertex_group_select() #select active vertex group
    bpy.ops.transform.resize(value=(sfac, 1, sfac)) #resize vertex group by sfac
    bpy.ops.object.mode_set(mode='OBJECT') #set program in object mode

def scale_whale(a,whale,vgrp,sfac):
    bpy.ops.object.mode_set(mode='OBJECT') #set program in object mode
    bpy.ops.transform.resize(value=(1, totallength, 1)) #resizes the length of the whale (only the y axis) based on an index in total length corresponding to the index in whale
    for v in vgrp:
        scale(v, sfac[vgrp.index(v)])


scale_whale(obj, whale, vgrp, sfac)

Here is a link to the file of my whale:

$\endgroup$
  • $\begingroup$ blender.stackexchange.com/questions/2848/why-avoid-bpy-ops $\endgroup$ – Ray Mairlot Jan 24 '18 at 16:31
  • $\begingroup$ @RayMairlot I am not seeing anything in that link pertaining to scale. Do you believe that using bpy.ops. is the problem, and if so do you suggest an alternative method? $\endgroup$ – user33993 Jan 24 '18 at 16:37
  • $\begingroup$ I just posted it as a general recommendation when doing python scripting in blender not as a specific solution to your problem. $\endgroup$ – Ray Mairlot Jan 24 '18 at 16:50
  • $\begingroup$ @batFINGER I chose to simplify the code in the question because I realized there were many unnecessary steps in my code in the file (I originally meant to loop all the data, however I realized I was unable to revert to the original model upon each iteration so chose to run through each iteration manually). Just something to keep in mind when running through the code from the .blend file. $\endgroup$ – user33993 Jan 24 '18 at 17:10

Your Answer

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

Browse other questions tagged or ask your own question.