• Welcome to the Community Forums at HiveWire 3D! Please note that the user name you choose for our forum will be displayed to the public. Our store was closed as January 4, 2021. You can find HiveWire 3D and Lisa's Botanicals products, as well as many of our Contributing Artists, at Renderosity. This thread lists where many are now selling their products. Renderosity is generously putting products which were purchased at HiveWire 3D and are now sold at their store into customer accounts by gifting them. This is not an overnight process so please be patient, if you have already emailed them about this. If you have NOT emailed them, please see the 2nd post in this thread for instructions on what you need to do

Panels and Python and CSVs, oh my!

Robynsveil

Admirable
One of the loneliest endeavours one can embark on is that of self-taught add-on development. As a real Python developer can quickly determine from a cursory glance at my so-called "code", "self-taught" screams from every function.

But, it works.

So, my purposes have been satisfied, which were based on an insufferable laziness: I found painting shaders on figures imported from Poser to Blender a process needlessly tedious and repetitive. Even when copying and pasting entire shaders from mat zone to mat zone became a matter of Ctrl-C | Ctrl-V, doing that a few times became annoying, so a script seemed a good solution.

The original script worked, but it was very short on features.

Long-story-short, I've been adding features. "Oh, what a complex web we weave, when first we practice... to write apps." I know, not how it goes, but it's applicable.

Currently, the app looks like:



You select the figure to 'shader', select the figure type (original figure name) and click [Apply Shaders]. Works okay, *IF* all the .csv files were edited correctly and all conditions were met and so forth and so on. Errors sort-of happened in the background (console) which most users would never look at, and so the programme probably never seemed to "work right"... dunno, because I never got either complaints or comments or anything, really.

So, I started to trap errors, and most recently was able to get them to display in an error dialogue of sorts, in the foreground with an OK button:


Well, the OK doesn't close the dialogue, something I sort-of need to nut out why, and other stuff, but at least the error isn't hidden out of sight. I currently trap for 7 or 8 possible errors... but do warn folks to have a look in console if the software seems to be hanging somewhere.

In the meantime, here's where I'm hoping to be going soon...
 

Robynsveil

Admirable


So, why am I posting all this? Well, perhaps to put it out there, probably more like to alleviate that lonely feeling ... but also, if there's anyone who might be remotely interested in having a wee look at the code... wow, that would totally be welcome!

And no, i haven't forgotten about you, DaremoK3... :)
 
Last edited:

Robynsveil

Admirable
Well put, Bonnie.

The problem I'm encountering is this: my little script (well, it's actually 2 main scripts, __init__.py and make_shader.py - together they represent over a thousand lines of code) runs in a panel. You know, that thing in the 3D-View window that opens when you press [T]. What I'm trying to get working, one way or another, is presets... getting them to load from something like a .csv file *passively* - as in, the presets load when the script loads - but that doesn't seem possible. :( I might need to assign a button to load presets or something, not sure. o_O

But then, having more than one button on a panel seems a bit challenging to do, since the button fires off a bunch of stuff... :eek: uh, yeah, it's officially a headache, now.
 

Robynsveil

Admirable
Thank you, MissB... definitely getting there. Read up a bit last night on my tablet (a little light reading) on the proper way to trap Python "exceptions". The settings actually work: well, they appear in the nodes - the settings themselves aren't all that great. However, repainting shaders is trivial: make your change, click [Apply Shaders], enjoy the results.

One more big hurtle is writing the settings - all settings, really - to CSV. Currently, I just read them from CSV, which is cool, but if someone leaves off a double-quote or forgets to edit something, it all goes to custard, so setting things up correctly needs to happen on the panel, not in a plain-text editor.

ETA: Once I get the write bit sorted, I'll post the script to my github page.
 

Pendraia

Sage
Contributing Artist
Great to hear that your making progress...just some trivia for you relating to python...in Victoria where I teach they are starting to teach kids coding from an early age, working their way up to programming in Python, Javascript and C++. They have something called Code Club which is also promoting for the teachers to learn to code. Last day of term we had professional learning where we saw all these amazing robots for kids in grade 1/2 to learn how to code using simple block based directions.
 

Miss B

Drawing Life 1 Pixel at a Time
CV-BEE
That sounds very cool Pen. I know a few of us at GameDev.tv taking a Blender class have posted asking for them to teach some of the classes to youngsters. I know a good friend of mine's son turns 12 on the 23rd of this month, and he's been begging her for a laptop (as opposed to his tablet), so he can learn to create games.

It would be nice if they had something like Code Club here.
 

Pendraia

Sage
Contributing Artist
Many of the kids out here create games using different programs. They tend to be older and in their teens though. They start here with simple programs like Scratch and Scratch junior (iPad). If you want to chat more about this we should probably start a thread on it...sorry Robyn didn't meant to take the thread off course...
 

Miss B

Drawing Life 1 Pixel at a Time
CV-BEE
No problem Pen. I was just commenting on a thread folks taking the Blender/gaming courses at Udemy were trying to get started. BTW, Scratch was mentioned in one of the posts.
 

Robynsveil

Admirable
...sorry Robyn didn't meant to take the thread off course...

Not at all, that was pretty much the intent of the thread, so thank you for commenting. :) Those children are - and I, at 65, am - testament to the fact that it's never too early or too late to learn how to code. I'm pretty sure they are getting a far better foundation in it than I have: pretty-much all self-taught, so keep learning new concepts on good coding practice, stuff they'd be learning as a matter of course (pun intended).

For example, one of the challenges in writing a script is error-handling. Blender script errors tend to look ghastly and terribly unfriendly: they're very Python-eque, meaning to say they convey almost no information to the casual user. In Blender, they may briefly appear in a dialogue, which disappears in a puff of smoke when you move your mouse. I've tried to trap for common script environment errors, such as files not being where they need to be, or improperly named entries in config files, etc, by using the

Code:
try:
  some-task()
except:
  pass

...which works, because if some-task() fails, I can issue a message in a dialogue that the user would know how to act on (well, I hope I'm clear enough with instructions). Well, I recently picked up that the prefered way to do that try: except: thing is to use a qualifier with the except, so:

Code:
try:
  some-task-that-returns-text()
except ValueError:
  pass

It make the error more specific to trap and so not hiding other issues you're not explicitly trapping for.

As you can see, I'm doing lots and lots of light reading these nights....:laugh:
 

LisaB

HW3D Vice President & Queen Bee
Staff member
Co-Founder
Great thread! Thank you, @Robynsveil for sharing your processes here. I always admire those who can think and create in ways that do not come easily to me, such as coding.

I saw myself when you talked about the endless Ctrl+C/Ctrl+V thing. When I find myself doing something mindless and repetitive like that I get frustrated and want a "tool" to work on that while I focus on something else.

I also saw myself in that it helps to pull everything so far together to explain it to someone else. That's when the possibilities of solutions come rolling in. It is great to know others come up against the same things I do and then see the unfolding of "solution processes" in action here. :)
 

Pendraia

Sage
Contributing Artist
Not at all, that was pretty much the intent of the thread, so thank you for commenting. :)
Glad to hear that...

Those children are - and I, at 65, am - testament to the fact that it's never too early or too late to learn how to code.
Totally agree...it doesnt matter what it is, it's never too late to learn something. I went back and got my teaching degree at 43. I was 46 when I graduated. Mind you my head spun those first few weeks.
 

DaremoK3

Enthusiast
Very inspirational...

I wholeheartedly agree with the age/learning. I have been dabbling with coding for a little while, but it wasn't until a couple of years ago that I got interested enough to start studying it seriously in the hopes of creating some things I want/need. I am still at beginners level with a very trial-n-error workflow, but I am good at troubleshooting, so that helps.

I'm closer to the mid century mark myself, but still many years of play left...
 

DaremoK3

Enthusiast
So, Robyn, I had a play on both my Windows 7 box, and my laptop running virtual Puppy Linux (Fatdog64) with Blender 2.79, and I have run into an issue trying to use the it.

On Linux, it works to load the images from the csv_list, but I can't use the results due to one of several reasons with the Principled BSDF. Nothing to do with your addon. I get a crash to desktop trying to utilize the principled shaders on this virtual linux environment. I have tested against straight Cycles, and BI. Only activating the BSDF crashes. So, for right now, linux is not going to work for testing for me.

On Windows 7, I can't even get past the load shaders due to an error locating the csv_list. The path_list is set up correctly, and the csv_list is in the proper folder, but somehow an (Windows) error is preventing the execute from finishing. Says it can not find the folder - and/or does not exists.

I error tested this against your error trapping (removing csv_list), and that works perfectly. With csv_list in place, I get the Windows erroring. I tried tracing the error myself, and set up the textures environment to mirror your own, but I can not find the cause. I run as Administer, so there is no UAC issues (at least to my knowledge).

Below are images for error and path_list:

MakeShaders_ImageList_Error.jpg

MakeShaders_PathList.jpg


Help, please...
 

DaremoK3

Enthusiast
Oh, and I love your detailed instructions, but I think you need to add more specific directions for the path_list editing. It took me a hot minute after looking through your code to decipher that only pathP or pathN was needed depending on which OS one was on. Coding wise, posix or nt makes sense for P or N, but others might not know that N was the only place to put Windows path, and P only for Linux/MAC.

I at first, had my .blend path location in path P (that's how I initially read it), and thought you needed both .blend file location, and texture image location.
 

DaremoK3

Enthusiast
Also, I had a thought (more a theory of usage running around in my head) regarding automating the csv files from within Blender.

I believe you should be able to write to both files using strings, and path selections. This way you control the base csv files, and users fill in the blanks selecting the folder/files. You create a write file that inserts the files with your set up parameters, so there would be no user error (except for selecting wrong folders). You could even write csv_list to selected folder.

This is what I did for my quad retopo addon where a user would have to hand edit the command file for usage. I took it out of there hands, except for selecting parameters, and selecting folder location within Blender. Then execute writes the file with controlled attributes, so user can not mess up structure (quotes, spacing, parameter order, etc.).

What do you think?
 
Top