0

I have a get and set method for my properties. As an example, I'm getting the x dimension of a vertex selection. The get is simple enough. For the set, how can I get the delta or change in the Property value?

As in, if I have an object that is 6m in X, then the value being passed to my in my set function would be 6m. How can I then run my code to find the current size so that I can multiply the x coordinates by the change in value?

Here's some code for demonstration purposes:

def get_dim_x(self):
    obj = bpy.context.object
    v_x = [v.co for v in obj.data.vertices]
    dimension_x = max(v_x)-min(v_x)
    return dimension_x

def set_dim_x(self,value): # How do I get the delta/change in value without recursion? dim_x = get_dim_x(self)

for v in obj.data.vertices:
    if dim_x  != 0:
        v.co.x *= value/dim_x

class EXAMPLE_PG_props(PropertyGroup):
dimension_x: FloatProperty(name = "Dimension X", default = 0.0, step = 100, get = get_dim_x, set = set_dim_x )

Thanks!

  • Maybe a dumb question, but why don't you use obj.dimensions directly ? – Gorgious Feb 01 '23 at 08:08
  • @Gorgious, thanks for the reply. This is just an example to demonstrate how I might need to manipulate the value based on the current delta. It has come up in other situations. I found the post below but I'm not sure how I'd get the value in my case without using self["dimension_x"], which was ill-advised. https://blender.stackexchange.com/questions/49264/how-to-use-set-get-property-callbacks-correctly – Dr. Pontchartrain Feb 01 '23 at 08:11
  • AFAIK this is the only way to avoid recursion and it is not likely to change any time soon – Gorgious Feb 01 '23 at 09:17
  • may i ask why you are calling get_dim_x in set_dim_x instead of just using a variable? (as it is "normally" done in programming languages) – Chris Feb 01 '23 at 16:53
  • @Chris, what do you mean? Can you provide a code example please? – Dr. Pontchartrain Feb 01 '23 at 17:40
  • yes i will, if you are willing to provide a correct example which is runnable and without errors at all. Your provided code has at least 2 errors...obj is not defined and you are mixing vector/list properties with floatProperty. – Chris Feb 02 '23 at 06:18

0 Answers0