-1
$\begingroup$

I have been climbing up the learning curve for script-driven object creation and configuration, often first achieving the effect I want manually (by pointing and clicking) and then wishing to recreate it in Python code. I found myself poring over the Properties panels (various, but let's use Materials and Textures as a good example), digging for property names and setting values according to what I saw in my blendfile, copying and pasting and writing scraps of python to use later in various scripts.

This is, to put it mildly, tedious :-) Also, it's not super-simple to recognise which properties still have their default values and which I have changed (I'm sure there are old, wise Blenderistas who have all the default values for every panel memorised, but I am far from there yet). So immediately it occurred to me that a bit of metacoding was desirable, that someone surely must have written some Blender python code that writes Blender python code based on Blender data structures (this is a trick I've pulled many times in other languages); such an addon could (if the info is available) compare all property values to the default values, and generate boilerplate code that imposes all the user's settings for that object, ready to plug into whatever script you like. Blender seems so data-driven that I was sure I would find this addon with only a modicum of googling...

After more than a modicum I haven't found it yet :-) So I was wondering if anyone knows of it by some other name than "code generation" or "metacode". If only Blender's internal language was Tcl instead of Python, I'd be all over it already :-) but I'm still struggling with unfamiliar Python syntax, not ready to write anything really clever yet. Or maybe there's some nifty Blender/Python feature that does the equivalent, of which I'm not yet aware?

EDIT: I have learned as I do more research that it is possible to get Blender to cough up the code that builds UI panels, via Other-Click -> Edit Source on a live panel. What I wish, then, is that I could "Edit Source" on Objects as well, and get a complete "this code will re-create this object" dump. So far the answer seems to be No, but it seems to me that it involves about the same level of introspection as the UI panel source dump... so hey, why not?

$\endgroup$
3
0
$\begingroup$

I'd recommend using the auto complete plugin. Not only does it auto correct your code, it also has few simple templates you can add into your code:auto complete add-on link

$\endgroup$
4
  • $\begingroup$ It is not quite what I had in mind, but very interesting and looks well worth installing. What I was hoping for was more like a script I could run, button I could press, that would emit (to a target file) legit Blender Python code to recreate the selected object (or even the whole scene) from scratch. Autocomplete is a little more interactive than what I was envisioning... I will certainly give it a try. $\endgroup$
    – Tazling
    Jan 14 '17 at 4:47
  • $\begingroup$ From a discussion at rightclickselect, comments by artistcdmj: There is this video tutorial on creating an addon for a complete mesh with all its vertices and faces and edges: youtube.com/watch?v=Ls01JTaaf1A (my note: this is probably the most game-changing Blender video tutorial I have ever watched... ) There is also the Creaprim addon for creating an add mesh from selection (this version was fixed by Spirou4D) github.com/artistCDMJ/creaprim/archive/master.zip $\endgroup$
    – Tazling
    Jan 16 '17 at 1:39
  • $\begingroup$ Here maybe is another piece of the puzzle (walks the object data tree listing properties, attributes, etc) wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/… $\endgroup$
    – Tazling
    Jan 16 '17 at 6:16
  • $\begingroup$ Just perform an action and copy the code in the console. $\endgroup$ Apr 27 '17 at 3:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.