Blender draw list via script, Add Mesh: Extra Object - blender

I am trying to "visualize" a list of numbers from a .csv file.
I could do that by writing a blender script and thats what I already did.
But I would like to know how the Add Mesh: Extra Object - Math Function could help me (or other functions/addons/anything).
I would like to have a 2D Line (x=+1, y=0, z= value from list) that I would rotate afterwards.
In other words can I convert a list of numbers into a function ?
Sorry if that is a stupid question.
Thanks for the help.

Where The Extra Object - Math Function addon uses minU maxU and stepU as user input values that are used to calculate the value of u before evaluating the function to generate the mesh, you want to let the user input an int value and use it as an index into an array -
AvailZOptions = [1.3, 2.6, 5.2, 10.4]
lineEnd = [xvalue, yvalue, AvailZOptions[OptZUserChoice]]
Another option would be to get the zValue from a function -
def CalcZValue:
if OptZUserChoice = 1:
return 1.3
elif OptZUserChoice = 2:
return 2.6 * cos(x)
lineEnd = [xvalue, yvalue, CalcZValue]

Related

How to find out what arguments DM functions should take?

Through trial and error, I have found that the GetPixel function takes two arguments, one for X and one for Y, even if used on a 1D image. On a 1D image, the second index must be set to zero.
image list := [3]: {1,2,3}
list.GetPixel(0,0) // Gets 1
GetPixel(list, 0, 0) // Equivalent
How am I supposed to know this? I can't see anything clearly specifying this in the documentation.
This is best done by using the script function with an incorrect parameter list, running the script, and observing the error output:

Lua: Read userdata as number / Compare userdata with number

I am trying to import numbers from files and change them if they are at a certain value. I am using torch to get values form gesture and change them from 101 to 10 or from 100 to 9 if the input is the corresponding number (10 or 9). Unfortunately, I have figured out that in Lua, the input is of type userdata which cannot be converted to integers and not compared to integers or torch tensors.
So my question is: How can I check for equality of numbers if the input type is userdata?
Is there potentially a way to convert the input to a number such that comparison is possible?
gesture = matio.load(val, 'gesture')
print(type(gesture)) --prints `userdata`
print(gesture) --prints 10 (for example)
if gesture == th.FloatTensor({101}) then
gesture = th.FloatTensor({10})
print("101 Detected! New value is: ")
print(gesture)
os.exit(0)
elseif gesture == th.FloatTensor({100}) then
gesture = th.FloatTensor({9})
print("100 Detected! New value is: ")
print(gesture)
os.exit(0)
end
Just found an easier way
local gesture_int = gesture:uint()
This is fairly complex question and after testing through the hard way, I found a way to compare the userdata number with an integer.
print(type(gesture)) -> prints `userdata`
print(gesture) -> 10
gesture_str = tostring(gesture)
print(type(gesture_str)) -> prints `string`
gesture_int = tonumber(gesture_str)
print(type(gesture_int)) -> prints `number`
Single line solution is as follows
gesture_int = tonumber(tostring(gesture))
This new variable stores the userdata number as an integer.

How can I have increasing named variables?

I want a bunch of buttons, using QtGui to all have their own unique values, but when looping to create a grid of them, the button variable is overwritten.
I was trying to get something that would have each button have its own variable, like grid_btn01, grid_btn02, and so on.
Ideally, it would be like this
for x in range(gridx):
grid_btn + str(x) = GridBtn(self, x, y, btn_id)
But of course, this doesn't work.
consider using a python dictionary
,also i'm not familiar with Qt but double check what is the return value of this function maybe btn_id is the variable you should store
buttons = {}
for x in range(gridx):
buttons[x] = GridBtn(self,x,y,btn_id)
What you're asking may technicallybe possible in Python, but it's definitely the wrong approach.
Use a list instead:
grid_btns = []
for x in range(gridx):
y = ...
grid_btns.append(GridBtn(self, x, y, btn_id))

In Gimp script-fu, how can you access QuickMask functionality?

In the Gimp GUI, the QuickMask is very useful for many things, but this functionality doesn't seem to be directly available through script-fu. No obvious equivalents were apparent to me in the procedure browser.
In particular, putting the (value/gray) pixels of a layer into the selection mask is the basic thing I need to do. I tried using gimp-image-get-selection to get the selection channel's id number, then gimp-edit-paste into it, but the following anchor operation caused Gimp to crash.
My other answer contains the "theoretical" way of doing it - however, the O.P. found a bug in GIMP, as of version 2.6.5, as can be seem on the comments to that answer.
I got a workaround for what the O.P. intends to do: paste the contents of a given image layer to the image selection. As denoted, edit-copy -> edit-paste on the selection drawable triggers a program crash.
The workaround is to create a new image channel with the desired contents, through the copy and paste method, and then use gimp-selection-load to make the selection equal the channel contents:
The functions that need to be called are thus (I won't paste scheme code, as I am not proficient in all the parenthesis - I did the tests using the Python console in GIMP):
>>> img = gimp.image_list()[0]
>>> ch = pdb.gimp_channel_new(img, img.width, img.height, "bla", 0, (0,0,0))
>>> ch
<gimp.Channel 'bla'>
>>> pdb.gimp_edit_copy(img.layers[0])
1
>>> pdb.gimp_image_add_channel(img, ch, 0)
>>> fl = pdb.gimp_edit_paste(ch, 0)
> >> fl
<gimp.Layer 'Pasted Layer'>
>>> pdb.gimp_floating_sel_anchor(fl)
>>> pdb.gimp_selection_load(ch)
Using QuickMask through the User interface is exactly equivalent to draw on the Selection, treating the selection as a drawable object.
So, to use the equivalent of "quickmask" on script-fu all one needs to is to retrieve the Selection as a drawable and pass that as a parameter to the calls that will modify it -
And to get the selection, one just have to call 'gimp-image-get-selection'

Creating a log function with a custom base

I have a formula and this formula uses a log function with a custom base for example log with a base of b and value of x. In objective-c, I know there are log functions that calculate without a base and base of either 2 or 10.
Is there a function that has the ability to calculate a log function with a custom/variable base? or maybe there is an alternative method of completing this formula.
The basic idea of my formula is this log(1+0.02)(1.26825) (1+0.02 is the base). This should equal 12.000.
Like this:
double logWithBase(double base, double x) {
return log(x) / log(base);
}
You can calculate arbitrary logarithms with logbx = logcx / logcb, where c is one of the more readily available bases such as 10 or e.
For your particular example, loge1.26825 = 0.237637997 and loge1.02 = 0.019802627. That's 12.000 (within the limits of my calculator's accuracy): 0.237637997 / 0.019802627 = 12.000326876.
In fact, 1.0212 is actually 1.268241795 and, if you use that value, you get much closer to 12:
loge1.268241795 = 0.237631528
loge1.02 = 0.019802627
0.237631528 / 0.019802627 = 12.000000197.
Ray is right but here is a Obj-C method modification of it:
-(double) logWithBase:(double)base andNumber:(double)x {
return log(x) / log(base);
}