295 Commits

Author SHA1 Message Date
Brecht Van Lommel
a6b293daac Python Module: Bundle VFX library python bindings
When calling bpy.utils.expose_bundled_modules(), these modules are
added to sys.path.

This provides a solution/workaround to two problems:
* Using bpy together with packages like usd-core is problematic. Besides
  crashing due to C++ symbol conflicts, it's just impossible to import
  different versions of the same module, or to have distinct environment
  variables for both. (#127132)
* Blender add-ons using these VFX modules do not currently work with
  the bpy module.

This adds about 15MB to the bpy package.

Pull Request: https://projects.blender.org/blender/blender/pulls/133082
2025-01-17 10:13:31 +01:00
Campbell Barton
7481355397 Cleanup: scripts, unused variables & re-declaring built-ins 2025-01-02 15:11:15 +11:00
Campbell Barton
d64bd41ee9 Cleanup: wrap long lines 2025-01-02 15:11:14 +11:00
Campbell Barton
54e655f06a PyDoc: correct unbalanced back-tick 2025-01-02 15:03:54 +11:00
nutti
848ec77911 Fix: PyDocs: Title inconsistency on bpy.types.USDHook
Due to 8285d2d, titles "Inherited Properties" and "Inherited Functions" become hidden.
This PR fixes this issue.

Pull Request: https://projects.blender.org/blender/blender/pulls/132481
2025-01-01 07:40:37 +01:00
Michael Kowalski
9abe161b58 USD: USDHook.py format fix 2024-12-30 10:17:35 -05:00
Michael Kowalski
8285d2d82e USD: update USDHook.py example
Updated the example to include new hook functions
material_import_poll and on_material_import as well
as the new import_texture and export_texture
utilities which were introduced in #131559.

Also reformatted the existing documentation to include
subheaders and internal links, as the previous paragraph
format became difficult to follow.

Pull Request: https://projects.blender.org/blender/blender/pulls/132259
2024-12-30 15:50:08 +01:00
Charles Flèche
0df5d8220b USD: Add new get_prim_map API callable from python on_import hooks
When importing an USD, the Blender object names do not necessarily match
Prim names:

```
#usda 1.0
def Xform "xform1"
{
  def Mesh "MyObject"  # Will be imported as "MyObject"
}
def Xform "xform2"
{
  def Mesh "MyObject"  # Will be imported as "MyObject.001"
}
def Xform "xform2"
{
  def Mesh "MyObject"  # Will be imported as "MyObject.002"
}
```

This makes it difficult in the [USD Import Hooks]
(https://docs.blender.org/api/current/bpy.types.USDHook.html) to link a
Blender object back to its source Prim for additional processing. A
typical use cases for games is to generate UVs, create and apply a
material on the fly when importing a collision shape that does not have
a visual representation (hence no materials) based on some Prim
attributes, but that the artist needs to differenciate in Blender's
viewport.

The Import context exposes a new method `get_prim_map()` that returns a
`dict` of `prim path` / `list of Blender ID`.

For example, given the following USD scene,
```
/
 |--XformThenCube [def Xform]
 |   `--Cube [def Cube]
 |--XformThenXformCube [def Xform]
 |   `--XformIntermediate [def Xform]
 |       `--Cube [def Mesh]
 |--Cube [def Cube]
 `--Material [def Material]
     `--Principled_BSDF [def Shader]
```

the `get_prim_map()` method will return a map as:

```python
@static_method
def on_import(import_context):
  pprint(import_context.get_prim_map())
```

```json
{
  "/Cube": [bpy.data.objects["Cube.002"], bpy.data.meshes["Cube.002"]],
  "/XformThenCube": [bpy.data.objects["XformThenCube"]],
  "/XformThenCube/Cube": [bpy.data.objects["Cube"], bpy.data.meshes["Cube"]],
  "/XformThenXformCube": [bpy.data.objects["XformThenXformCube"]],
  "/XformThenXformCube/XformIntermediate": [bpy.data.objects["XformIntermediate"]],
  "/XformThenXformCube/XformIntermediate/Cube": [bpy.data.objects["Cube.001"], bpy.data.meshes["Cube.001"]],
  "/Material": [bpy.data.materials["Material"]],
}
```

Co-authored-by: Odréanne Breton <odreanne.breton@ubisoft.com>
Co-authored-by: Sttevan Carnali Joga <sttevan.carnali-joga@ubisoft.com>
Co-authored-by: Charles Flèche <charles.fleche@ubisoft.com>
2024-12-11 21:36:09 +01:00
Bastien Montagne
fcc1c89923 API Doc: improvements/fixes regarding new requirements for __init__/__del__ 2024-11-19 15:37:04 +01:00
Bastien Montagne
b1d044bfb8 Merge branch 'blender-v4.3-release' 2024-11-11 16:17:04 +01:00
Bastien Montagne
69a7948575 Doc: Py API: Add more info about UNDO operator option.
Essentially, any operator modifying Blender data should enable this
`UNDO` option, else bad things (corruption, crashes...) are likely to
happen.

* Added a new Operator example to explain this topic.
* Updated some existing Operator examples that were not correct anymore.
* Added a new small section in the gotchas page linking to it.
* Added also short reminder about this in the `UNDO` 'tooltip'
  description itself.

Related to #77557.
2024-11-11 16:13:37 +01:00
Campbell Barton
ba3c53f200 Merge branch 'blender-v4.3-release' 2024-11-03 22:04:48 +11:00
Campbell Barton
d920ef5425 Merge branch 'blender-v4.3-release' 2024-11-03 22:04:44 +11:00
Campbell Barton
e97e2e4b6d Merge branch 'blender-v4.3-release' 2024-11-03 22:04:42 +11:00
Campbell Barton
091ee2833b PyDoc: replace references to the deprecated "bgl" with "gpu"
Also correct bullet-points in gpu.state.blend_set.
2024-11-03 21:50:33 +11:00
Campbell Barton
b00550916c PyDoc: correct use of single back-ticks 2024-11-03 21:50:33 +11:00
Campbell Barton
901359abf7 Cleanup: replace doc-strings with comments for internal logic
There is no need to store text in memory for comments on functions
that aren't exposed publicly and are only of used when reading
the code.
2024-11-03 21:50:33 +11:00
Campbell Barton
b3919319fb Merge branch 'blender-v4.3-release' 2024-11-02 15:44:18 +11:00
Campbell Barton
c056d03f93 Cleanup: move binary operator to line end in Python scripts 2024-11-02 15:43:26 +11:00
Campbell Barton
f1eb98c427 Merge branch 'blender-v4.3-release' 2024-10-28 09:38:05 +11:00
Campbell Barton
59c52ef2cf Cleanup: remove unused import in CLI example 2024-10-28 09:36:28 +11:00
Campbell Barton
f3c2deac3e Cleanup: replace U+00A0 with space
Using ASCII space is sufficient in source.
2024-10-09 16:34:39 +11:00
Spencer Magnusson
183112ad40 Docs: update AddonPreferences comment on __package__ use in extensions
Ref: !127661
2024-09-16 20:17:27 +10:00
Campbell Barton
97179b10fb Refactor: make "sys_info" an internal module, rename for clarity
- Move sys_info into an internal module to avoid having so many
  top level modules for Blender's internal functionality.
- Rename system_info sub-modules that pre-fill URL's for clarity.
- Move top-level exception handling into the operator.
- Report an error if an unexpected exception occurs.
- Use `Exception` instead of `BaseException` as there is no reason to
  catch the additional exceptions.
- Remove use of sys_info from the command line example,
  replace with in-lined system info.
2024-09-06 11:11:26 +10:00
Campbell Barton
8febf15ea5 Fix missing import in cli command registration example 2024-09-06 10:38:00 +10:00
Campbell Barton
fe6ab4f344 PyDoc: corrections to formatting and resolve warnings
Use RST formatting for doc-strings used in Python API docs
as well as minor corrections, also add links for foreach_get/set.
2024-08-19 10:48:06 +10:00
Hans Goudey
4333277aa8 Cleanup: Formatting 2024-08-15 12:45:05 -04:00
Falk David
d09fb76caa Docs: Python API: Add section about using attributes
This adds a section at the top of the `bpy.type.Attribute` about
how to use the attribute API in python.

Pull Request: https://projects.blender.org/blender/blender/pulls/126367
2024-08-15 17:42:47 +02:00
Campbell Barton
dc74a98b9e Cleanup: remove unused imports 2024-07-23 15:58:21 +10:00
Brecht Van Lommel
9068ea6d45 Merge branch 'blender-v4.2-release' 2024-06-14 15:48:27 +02:00
Brecht Van Lommel
1fec22e350 Fix #104061: RenderEngine Python example does not work in background mode
And add example of how to use bl_use_gpu_context.
2024-06-14 15:47:49 +02:00
Brecht Van Lommel
012a6fc573 Cleanup: make format 2024-06-12 17:43:44 +02:00
Matthew Hinson
a04d0b932f Fix: Broken Dependency Graph Python API example
Fix blender/blender-manual#104712

Pull Request: https://projects.blender.org/blender/blender/pulls/122563
2024-06-12 17:21:52 +02:00
Campbell Barton
98986c6562 Python: replace '%' with str.format for examples & templates
Use modern/preferred string formatting for user facing scripts.
2024-04-12 15:33:40 +10:00
Aaron Carlisle
8d12c58f2c Docs: Use reference links when possible when linking to other API 2024-03-29 22:54:12 -04:00
Hans Goudey
e6808cd558 Cleanup: Make format 2024-03-28 20:55:23 -04:00
Jesse Yurkovich
af7a34dee7 ImportHelper: Common methods for FileHandler drag and drop support
Provide common implementations for two operations that all Python
FileHandlers will typically use.

- `poll_file_object_drop` To be used inside the FileHandler `poll_drop`
   callback
- `invoke_popup` To be used inside the Operator `invoke` callback

The above code closely mirrors what is currently done inside the
existing Blender c++ FileHandlers.

Pull Request: https://projects.blender.org/blender/blender/pulls/119774
2024-03-29 01:22:51 +01:00
Julian Eisel
d470b65f6d Merge branch 'blender-v4.1-release' 2024-03-22 12:28:46 +01:00
Julian Eisel
303014bfac Fix #108078: Crash when inverting results in pose library sidebar
a958ae36e8 introduced support for UI lists to reference items that would
never be shown, regardless of filter settings. This was to skip assets
in the asset view template that were not of the requested type. UI list
sorting code wasn't updated to account for such items that should be
entirely ignored.

Pull Request: https://projects.blender.org/blender/blender/pulls/109157
2024-03-22 12:25:39 +01:00
Brecht Van Lommel
7a395e2e7f Revert changes from main commits that were merged into blender-v4.1-release
The last good commit was f57e4c5b98c075f3dfc61faebbcb43c99a778956.

After this one more fix was committed, this one is preserved as well:
67bd678887d7f8aec9f3b23bbf1aaf29f80d0da4.
2024-03-18 15:04:12 +01:00
nutti
dad9248897 Fix: Invalid RST bpy.utils.register_cli_command formatting
Titles can't be used because this text is indented.

Ref: !119320
2024-03-15 13:31:01 +11:00
Campbell Barton
9372e0dfe0 CLI: support defining custom commands via C++ & Python API
Add support for add-ons to define commands using the new argument
`-c` or `--command`.

Commands behave as follows:

- Passing in a command enables background mode without the need to pass
  in `--background`.
- All arguments following the command are passed to the command
  (without the need to use the `--` argument).
- Add-ons can define their own commands via
  `bpy.utils.register_cli_command` (see examples in API docs).
- Passing in `--command help` lists all available commands.

Ref !119115
2024-03-08 11:10:13 +11:00
Jesse Yurkovich
9e8bbc1129 Fix: USD hooks leak
If hooks are not unregistered Blender will report a leak on exit.

Store the hooks as unique_ptrs to remove manual memory management and
encapsulate the previous global list inside a function. These changes
ensure that everything is cleaned up on termination.

Also makes a small change to the hook documentation for a missing
`import` statement.

Pull Request: https://projects.blender.org/blender/blender/pulls/118294
2024-02-16 01:53:33 +01:00
Damien Picard
fa77e9142d UI: fix and improve a few messages
- "can not" -> "cannot" in many places (ambiguous, also see
  Writing Style guide).
- "Bezier" -> "Bézier": proper spelling of the eponym.
- Tool keymaps: make "Uv" all caps.
- "FFMPEG" -> "FFmpeg" (official spelling)
- Use MULTIPLICATION SIGN U+00D7 instead of MULTIPLICATION X U+2715.
- "LClick" -> "LMB", "RClick" -> "RMB": this convention is used
  everywhere else.
- "Save rendered the image..." -> "Save the rendered image...": typo.
- "Preserve Current retiming": title case for property.
- Bend status message: punctuation.
- "... class used to define the panel" -> "header": copy-paste error.
- "... class used to define the menu" -> "asset": copy-paste error.
- "Lights user to display objects..." -> "Lights used...": typo.
- "-setaudio require one argument" -> "requires": typo.

Some issues reported by Joan Pujolar and Tamar Mebonia.

Pull Request: https://projects.blender.org/blender/blender/pulls/117856
2024-02-05 17:08:17 +01:00
Michael Kowalski
ecbf3385c5 USD: basic support for on_import USD hooks
Added support for defining an on_import() function in
bpy.types.USDHook subclasses.  If on_import() is defined
on a given USD hook, it will be invoked in import_endjob().

The implementation closely follows the existing design of
export hooks.  USDHook.on_import() takes as an argument
an instance of an internally defined USDSceneImportContext
class which provides an accessor to the USD stage.

Also updated the USDHook documentation with an example
on_import() callback implementation.

Pull Request: https://projects.blender.org/blender/blender/pulls/117822
2024-02-05 14:26:02 +01:00
Campbell Barton
1fa896bb9a Cleanup: move bl_description to doc-strings
This is already done almost everywhere, prefer doc-strings unless
there is a reason for the tool-tip and Python doc-string to differ.
2024-01-23 13:59:15 +11:00
Thomas Dinges
64fc6d7890 Docs: Replace most wiki links with links to new developer docs
Exceptions:
* Links to personal wiki pages
* Pages that are not in the new developer docs yet (like Human Interface Guidelines)
* tools\check_wiki\check_wiki_file_structure.py needs a refactor
2024-01-18 16:49:38 +01:00
Campbell Barton
59dc67974a PyAPI: support returning non ID types when accessing Context.property
Previously accessing properties without an associated ID would return
None, even when the non-ID data was available.

Ref !116981
2024-01-10 23:43:29 +11:00
Guillermo Venegas
5b104fb3fa Cleanup: Silence warnings from 1254fee589
Introduced in 1254fee5898ba2a8e21bb6b64ee5f235248ff386

Also remove translation from CLOG statements.

Pull Request: https://projects.blender.org/blender/blender/pulls/116836
2024-01-06 06:53:42 +01:00
Guillermo Venegas
1254fee589 IO: Add support for Drag and Drop to FileHandlers
Added support to Drag and Drop to file handlers, part of #111242.

If file handlers are registered with an import operator they can now be
invoked with drag and drop path data.

Import operators must either declare a `filepath` StringProperty or both
a `directory` StringProperty and a `files` CollectionProperty depending
on if they support single or multiple files respectively.

Multiple FileHandlers could be valid for handling a dropped path. When
this happens a menu is shown so the user can choose which exact handler
to use for the file.

Pull Request: https://projects.blender.org/blender/blender/pulls/116047
2024-01-06 03:51:45 +01:00