Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

easier access to materials with a node #6

Closed
JacquesLucke opened this issue Oct 2, 2014 · 19 comments
Closed

easier access to materials with a node #6

JacquesLucke opened this issue Oct 2, 2014 · 19 comments

Comments

@JacquesLucke
Copy link
Owner

No description provided.

@JacquesLucke JacquesLucke changed the title easier access to materials easier access to materials with a node Oct 2, 2014
@zeffii
Copy link

zeffii commented Oct 2, 2014

here material refers to a string in this node self.material

row.prop_search(self, 'material', bpy.data, 'materials', text='', icon='MATERIAL_DATA')

if there are materials in the .blend this finds them, selecting one will assign the material name to self.material

@JacquesLucke
Copy link
Owner Author

oh that Looks extremly useful. I didn't know this prop_search thing
thanks :)

@zeffii
Copy link

zeffii commented Oct 2, 2014

There's plenty of nuggets like this in Sverchok, but I understand if you want to figure stuff out by yourself.

@JacquesLucke
Copy link
Owner Author

I will figure them out myself but if you have tips, feel free to share them :D

I dont now if you took a look at my code. Maybe you have some ideas how I can imrove my style or so.
I think you have way more experience than me :)

@zeffii
Copy link

zeffii commented Oct 2, 2014

I'll read your code base carefully, so far it looks nice and clean.

@zeffii
Copy link

zeffii commented Oct 2, 2014

but a great talk to absorb is: http://www.youtube.com/watch?v=OSGv2VnC0go
( Transforming Code into Beautiful, Idiomatic Python ) by Raymon Hettinger

@JacquesLucke
Copy link
Owner Author

Thanks for this link. Will watch this after my driving lesson :D
I often searched such videos but rarely found something really useful.
Then I bought the book 'clean code' and I like it a lot. Very helpful tips in there

@JacquesLucke
Copy link
Owner Author

thanks again :D pretty interesting stuff shown in this talk.

@zeffii
Copy link

zeffii commented Oct 3, 2014

Use a pep8 checker or pep-8 auto-formatter. First you will battle with it for a little, then you will see they are quite handy. What do you code in? Sublime? Vim? Gedit?

Avoid using variable names object and list, because they are builtin function names . Also they aren't helping you describe the content of the variable.

see: subheading "Avoiding dots"
Reduce the amount of dot chained lookups, especially in tight loops for speed.
This is what you do when you use aliasing too,

objects = bpy.data.objects
obj = objects['Cube']

If you can alias something once, before a tight loop that can help improve efficieny. Frequent access to objects is faster than the full path bpy.data.objects.

Aesthetically I like to push this into most things with dots. If you use bpy.props.FloatProperty 3 times, import it as from bpy.props import FloatProperty once at the top. If you need a whole collection of them do

from bpy.props import (
    FloatProperty, StringProperty, IntProperty, EnumProperty
)

yes this makes the import list a bit longer, but I defend that by saying we don't spend much time looking at the import list. But I must admit this is more style than anything, because these properties are generally only made explicit in the class body. If you have many many property definitions then you will want to import them first else you get a wall of text

@zeffii
Copy link

zeffii commented Oct 3, 2014

addendum: http://www.youtube.com/watch?v=DJtef410XaM (The Clean Architecture in Python : Brandon Rhodes) you will also learn a few things from Mr Rhodes.

@JacquesLucke
Copy link
Owner Author

I'm currently coding in Notepad++
Okay, will Keep that in mind that I shouldn't use the function names as variables. makes totally sense

Most of the time I already try to avoid dots, but you are right. I never imported FloatProperty , etc before using it.

I will Change that after the my current Project. I try to write something like another little Interpreter that generates a string that I can compile at runtime and then I want to run this on every Frame Change or so.

@zeffii
Copy link

zeffii commented Oct 3, 2014

most of bpy is a massive dict. (or behaves like a dict) . look up the .get() method for dicts, it will return a None if the key isn't present, you can also pass a fallback values .get(somekey, somefallback)

@JacquesLucke
Copy link
Owner Author

jep. I used this get method multiple time already.

Yeahh. it works.

@zeffii
Copy link

zeffii commented Oct 3, 2014

@JacquesLucke
Copy link
Owner Author

okay. your right :D
But I removed this file in my local branch.

@zeffii
Copy link

zeffii commented Oct 3, 2014

i'll fork (soon) and experiment too, there are things i'd like to try that don't make sense to implement Sverchok at this point

@JacquesLucke
Copy link
Owner Author

for example?

@zeffii
Copy link

zeffii commented Oct 3, 2014

various easing functions

@JacquesLucke
Copy link
Owner Author

okay cool

I have 360 nodes running at 20 fps. I think thats quite good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants