From OniGalore
Jump to navigation Jump to search

The default install path on Windows is

C:\Program Files\Blender Foundation

where each bigger version gets its own folder

Blender 3.1
Blender 2.93
Blender 2.83

Blender horror reloaded

Random session #1

Script log

Almost all actions in Blender get logged. You need to open the "info" window to see it.

bpy.ops.mesh.primitive_cube_add(size=2, enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))

Python console

Logged commands can be copied into the python console. Press enter key to execute.

Actual script files can be run like this but look out for pitfalls.

filename = "/full/path/to/"
exec(compile(open(filename).read(), filename, 'exec'))

You can translate file paths you get from Explorer's address bar by turning "\" into "\\".

Text editor window

You can collected logged commands in a python file if you use the text editor.

What to test it? Pressing the play button. Ups, it gave an error? But where is the fricking System Console to see the actual error?

A google search later:

Window > Toggle System Console
Traceback (most recent call last):
 File "\", line 1, in <module>
NameError: name 'bpy' is not defined
Error: Python script failed, check the message in the system console

It might by kind of counter intuitive because you are already in Blender but - as this error shows - you need to import any library used by the code.

import bpy
bpy.ops.mesh.primitive_cube_add(size=2, enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))

No drag and drop support

Unbelievable, but after all these years drag and drop support is almost zero.

If you try to drop a DAE or OBJ into the viewport it shows a plus icon but nothing will happen after the drop.

Actually dropped files are detected as the System Concole shows.
drop file filePath
So in theory it is possible to edit the Blender source code to add an dnd file importer.
It seems BLEND is currently the only file type where dnd is truly supported. This could give a hint where to look into the source and add more types.
The string "drop file" is found two times in source:
The simplest thing possible might be to pass the detected file to a Python script and let it handle the import.
Test: modify string, compile to an exe and see whether that's the correct file at all.

Would it be reasonable to program a workflow using another GUI and targeting Blender via command line?

Let's see... The idea with XSI was to sort "functional" objects under different layers.

Unfortunately Blender doesn't log that. When you hide/show a layer (nowadays a.k.a. "collection") you will see this:["Scene"].(null) = True["Scene"].(null) = False

Yea what an useless log. Documentation where are you?

No helpful for scripting. Google?

Oh wait, there's the scripting ... only a little more useful ...

import bpy
bpy.context.layer_collection.children['Collection'].hide_viewport = True

So far so good.

To place an object on a specific layer into a specific collection we have to create it or set it active.

create obj on new layer
import bpy
collection ='My Collection3')
# NOTE the use of '' to account for potential automatic renaming
layer_collection = bpy.context.view_layer.layer_collection.children[]
bpy.context.view_layer.active_layer_collection = layer_collection
bpy.ops.mesh.primitive_plane_add(enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
create obj on existing layer
import bpy
layer_collection = bpy.context.view_layer.layer_collection.children["Collection9"]
bpy.context.view_layer.active_layer_collection = layer_collection
bpy.ops.mesh.primitive_plane_add(enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
just get the active collection
import bpy
#<bpy_struct, Collection("Collection9") at 0x000001E090E84B88>
# geez... next stop regex to get content betwee the quote signs


When click the second icon (Display Mode) of the Outliner you can change the Layer View to Data API. This might be helpful for logging one or another command by toying around in properties.

Random session #2

More Python

Remember to ... Edit > Preferences

Interface: Display: Edit[x] Python Tooltips

Python-generated UI

Reading for later:

windows, tabs, panels




Random session #3

Dynamic context menus

The idea is to give function objects (CJBO) a dynamic context menu, either by analyzing its given collection name and/or further tags/properties given to the object.

Reading for later:


Build Blender
cd C:\blender-git\blender

update files

make update 

(re)build, the first build takes a couple of good minutes, further builds take about a minute


Final executable will be saved to


If there is not enough disk space this fails almost silently. (Progress visible in CMD will simply stop.)

Build Blender with Visual Studio

cd C:\blender-git\blender
make full nobuild

In solution explorer open "CMakePredefinedTargets", right-click "INSTALL", click "build" ("Erstellen" in German).

Proof of concept

Unorthodox but could be effective.

Blender, drag'n'drop event of an oni file ->
context aware conversion manager.exe ->
OniSplit.exe ->
Blender continues to run, converted files get read by python scripts, these are chosen based on what four letter file prefix the oni file had

For example this would greatly automate level modding.

Objects would be tagged and placed on suitable layers. (CJBO management.)

This could replace the outdated XSI workflow and its addon.



By default only one file of dropped ones will be detected.

system(processFile); could be used but then Blender hangs until the child has process finished.

Therefore let's use CreateProcess.

#include <windows.h> // CreateProcess
#include "BPY_extern_run.h" // run py scripts
 char processFile[255];
 char fn[255]; // py file (the more python, the less C)


 ZeroMemory( &si, sizeof(si) );
 si.cb = sizeof(si);
 ZeroMemory( &pi, sizeof(pi) );
 if (ddd->dataType == GHOST_kDragnDropTypeFilenames) {
         GHOST_TStringArray *stra = ddd->data;
         for (int a = 0; a < stra->count; a++) {
           printf("drop file %s\n", stra->strings[a]);

           strcpy(processFile, "C:\\Windows\\system32\\notepad.exe ");
           strcat(processFile, stra->strings[a]);

           // Start the child process.
               // visual studio create only successful code if "L" is used before the strings
               // don't use L with blender
               "C:\\Windows\\system32\\notepad.exe",  // No module name (use command line)
               processFile,                           // Command line
               NULL,   // Process handle not inheritable
               NULL,   // Thread handle not inheritable
               FALSE,  // Set handle inheritance to FALSE
               0,      // No creation flags
               NULL,   // Use parent's environment block
               NULL,   // Use parent's starting directory
               &si,    // Pointer to STARTUPINFO structure
               &pi);   // Pointer to PROCESS_INFORMATION structure

           // Wait until child process exits.
           // wait for onisplit to convert files ?
           WaitForSingleObject(pi.hProcess, INFINITE);

           // Close process and thread handles.

            strcpy(fn, "C:\\blender-git\\");
           // C (context) looks like some crazy voodoo, this shouldn't even work right now, but it does
           // for Blender specific stuff a context is needed otherwise the program will crash
           bool ok;
           ok = BPY_run_filepath(C, fn, NULL);

           printf("file was processed\n");


1) replace notepad with own exe (writing more code in C is a pain)

2) research path reading in C (get folder/file/extension) so own exe can use relative path when it is placed alongside Blender

3) Looks like Blender cannot accept new inputs? ರ_ರ .................. (ノಠ益ಠ)ノ彡┻━┻

This means some part of the analysis has to be done in C.

4) Deciding how to distribute this Blender variant.

Long-term goals could be to include Delano's addon and provide a way to automate the updating of Blender with these extras.

Notes for further customizations

  • Catching getActive Events would be interesting.
  • Blender Server
  • Globals are located in

The files close to main would need to be edited if Blender shall became a single-instance application. If started with hypothetical "singleInstance" arg, that would allow a permanent command line communication.

  • Pipe communication.