2
$\begingroup$

I'm trying to model a 'super egg' in Blender. https://en.wikipedia.org/wiki/Superegg

When sweeping the curve, the formulas for X and Y should be

X = abs(cos(t)**(2/2.5)) * sign(cos(t))
Y = abs(sin(t)**(2/2.5)) * sign(sin(t))

I'm having trouble translating those into the format that Blender wants.

I assume that it's Python syntax, so first I tried to solve that there doesn't seem to be a 'sign' function. So I added this in the 'A helper function'

0 if cos(u) == 0 else -1 if cos(u) < 0 else 1

When I then put abs(cos(u))**0.8*a into the formula for X, Blender gives me the error message TypeError: 'NoneType' object is not subscriptable which I can't make sense of.

Any help will be appreciated :)

enter image description here

$\endgroup$
1
  • $\begingroup$ I've fiddled around a bit with it. If I have the X formula as cos(u) it works. If I change it to abs(cos(u)) it fails. $\endgroup$ May 10, 2020 at 10:15

3 Answers 3

3
$\begingroup$

The problem was the abs function.

I opened up the script that creates the mesh ("..\Blender 2.82\2.82\scripts\addons\add_mesh_extra_objects\add_mesh_3d_function_surface.py"). It has a list of 'accepted' functions at the top and abs isn't included. However fabs is. When I changed the formula for X to fabs(cos(u))**0.8*a it worked as expected.

$\endgroup$
0
$\begingroup$

The error seems to be in the code that processes that string, which you did not include. "NoneType object is not subscriptable" means that you try to access a variable that is None with a subscription operator ([]) which is not anywhere in the code you presented here, so I assume the problem is elsewhere. This commonly happens when you expect a method of an object to return itself, e.g.

# correct
some_list = [1, 2, 3]
some_list.sort()
result = some_list[0]

# wrong
some_list = [1, 2, 3]
result = some_list.sort()[0] # TypeError, since sort method returns None.
$\endgroup$
3
  • $\begingroup$ Thank you for your reply. I don't have any Python code I've written myself. I tagged it with the python tag because the expression you write in Blender is passed on to Python's eval function, so it has to be valid Python syntax. $\endgroup$ May 10, 2020 at 9:50
  • $\begingroup$ Does it error out without the helper function? $\endgroup$
    – D. Skarn
    May 10, 2020 at 10:13
  • $\begingroup$ Yes. It seems to be the abs function that it doesn't like. $\endgroup$ May 10, 2020 at 10:25
0
$\begingroup$

I've done the same for another formula, albeit it only plots positive values since square root of negative value is not a real number. for z^2 = x^2 - y^2:

Y eq: u
X eq: v
Z eq: sqrt(fabs(u**2-v**2))
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .