0

I am new to Python and scripting in general, so forgive me if this is already asked, I do not know what to look for. I am looking for a way to create a set of variables linked by a formula that goes two ways. When I create a field for each of the variables and I redefine one, I want all the fields to update accordingly.

So for example, if I have a*b=c == 2*3=6. 3(or b) is a given, we cannot change it. However, when I change 6 to a 9 I want the 2 to automatically change to a 3. So basically apply the inverse formula.

What subjects should I study in order to correctly realize this?

I am trying to create an easy way to do a so called " vertigo effect" or "trombone effect" in a 3D program with python. So variables I am dealing with are focal length, sensor size, field of view in degrees, distance to subject etc etc and I want to link them all together. Can I create some sort of form?

  • 2
    You could use a dedicated solver library like one discussed herehttps://stackoverflow.com/questions/10499941/how-can-i-solve-equations-in-python However, I would recommend working out a set of equations yourself for any given unknown and just intercepting the right event and recalculating the variable in question. If you search for "blender vertigo effect", you will find it. I suggest first asking on a Blender forum say in Reddit whether what you want already exists. I found some hits. Dont do the programming when you do not have to. – Leonid Mar 20 '19 at 16:20
  • If this is an educational programming exercise for yourself, then depending on how simple the formula is, you could e.g. create a "Formula" class with access methods, which update variables when any of them is changed. Python supports such behavior through descriptors, see e.g. this post: https://www.blog.pythonlibrary.org/2016/06/10/python-201-what-are-descriptors/ – Inon Peled Mar 20 '19 at 16:27
  • @leonid Thank you for your tips. This is an exercise for myself in order to learn how to program. I found this challenging enough. I am aware of all the formulas and how the variables relate to each other, I just need to find a way to apply it. I will look up the solver library. – Toonhimself Mar 20 '19 at 16:32
  • @Toonhimself There does exist an API for writing add-ons for Blender but this is not something I would jump to right away as a noob - too many different technologies in one and too stee of a learning curve. https://docs.blender.org/api/blender_python_api_2_65_5/bpy.types.Panel.html#bpy.types.Panel If you will learn better when graphics is involved, tr going through the https://realpython.com/pygame-a-primer/ tutorial for example. – Leonid Mar 20 '19 at 16:51

1 Answers1

0

Using blender, you can define a custom panel that can display specific properties that you want the user to adjust. To automate altering multiple values, you can use bpy.props to create properties that you will allow the user to adjust. Each custom property can define a set() function that will be triggered when the user modifies the property, you can then have that function alter other related values as needed.

Once you get started, blender.stackexchange is a better place to ask for help with blender specific scripting.

sambler
  • 6,917
  • 1
  • 16
  • 23