User:Paradox-01/Blender/Research: Difference between revisions
Paradox-01 (talk | contribs) mNo edit summary |
Paradox-01 (talk | contribs) mNo edit summary |
||
Line 53: | Line 53: | ||
: So in theory it is possible to [https://www.youtube.com/watch?v=eCvuQHlKPEk edit the Blender source code] to add an dnd file importer. | : So in theory it is possible to [https://www.youtube.com/watch?v=eCvuQHlKPEk 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. | :: 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. | ||
Line 150: | Line 148: | ||
[...] | [...] | ||
===Building Blender=== | |||
https://wiki.blender.org/wiki/Building_Blender | |||
https://wiki.blender.org/wiki/Building_Blender/Windows | |||
* https://www.youtube.com/watch?v=eCvuQHlKPEk | |||
* vid that gives an overview of the source code: https://www.youtube.com/watch?v=tCdx7gzp0Ac - for example they show where to find command line args | |||
cd C:\blender-git\blender | |||
update files | |||
make update | |||
(re)create build, the first build will take a couple of minutes, further builds take about a minute or less | |||
make | |||
===wm_window.c === | |||
blender-with-libraries-3.1.0\blender-3.1.0\source\blender\windowmanager\intern\wm_window.c | |||
A simple test of opening a dropped file with notepad: | |||
char processFile[255]; | |||
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, "notepad.exe " ); | |||
strcat(processFile, stra->strings[a] ); | |||
system(processFile); | |||
... | |||
} | |||
Notepad will open with dropped file. Blender will hang and possible crash if Notepad is not closed. | |||
So, either the dropped files need to be processed right away or that part must be made independent using fork or create process ... | |||
* https://docs.microsoft.com/de-de/windows/win32/procthread/creating-processes |
Revision as of 08:20, 16 June 2022
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/myscript.py" 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 "\cube.py", 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:
blender-with-libraries-3.1.0\blender-3.1.0\source\blender\windowmanager\intern\wm_playanim.c
blender-with-libraries-3.1.0\blender-3.1.0\source\blender\windowmanager\intern\wm_window.c
- 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:
bpy.data.scenes["Scene"].(null) = True bpy.data.scenes["Scene"].(null) = False
Yea what an useless log. Documentation where are you? https://docs.blender.org/manual/en/latest/scene_layout/object/properties/instancing/collection.html?highlight=collection#basic-usage
No helpful for scripting. Google? https://blender.stackexchange.com/questions/158998/how-to-hide-one-level-for-all-collections-with-python
Oh wait, there's the scripting ... only a little more useful ... https://docs.blender.org/api/current/bpy.types.LayerCollection.html#bpy.types.LayerCollection.hide_viewport
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 = bpy.data.collections.new('My Collection3') bpy.context.scene.collection.children.link(collection) # NOTE the use of 'collection.name' to account for potential automatic renaming layer_collection = bpy.context.view_layer.layer_collection.children[collection.name] 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 print(bpy.context.view_layer.active_layer_collection.collection) #<bpy_struct, Collection("Collection9") at 0x000001E090E84B88> # geez... next stop regex to get content betwee the quote signs # https://blender.stackexchange.com/questions/44382/blender-python-select-an-object-with-the-sequence-of-letters-in-a-name
Outliner
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
UI:
Scripting:
[...]
Random session #3
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:
- https://docs.blender.org/manual/en/latest/addons/interface/context_menu.html
- https://blenderartists.org/t/context-sensitive-menu-in-blender/515689
[...]
Building Blender
https://wiki.blender.org/wiki/Building_Blender https://wiki.blender.org/wiki/Building_Blender/Windows
- https://www.youtube.com/watch?v=eCvuQHlKPEk
- vid that gives an overview of the source code: https://www.youtube.com/watch?v=tCdx7gzp0Ac - for example they show where to find command line args
cd C:\blender-git\blender
update files
make update
(re)create build, the first build will take a couple of minutes, further builds take about a minute or less
make
wm_window.c
blender-with-libraries-3.1.0\blender-3.1.0\source\blender\windowmanager\intern\wm_window.c
A simple test of opening a dropped file with notepad:
char processFile[255]; 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, "notepad.exe " ); strcat(processFile, stra->strings[a] ); system(processFile); ... }
Notepad will open with dropped file. Blender will hang and possible crash if Notepad is not closed.
So, either the dropped files need to be processed right away or that part must be made independent using fork or create process ...