RNA paths from python tooltip/operator for viewport settings are wrong #124527

Closed
opened 2024-07-11 15:09:19 +02:00 by Simon Thommes · 6 comments
Member

System Information
Operating system: Linux-6.8.12-gentoo-x86_64-AMD_Ryzen_9_5950X_16-Core_Processor-with-glibc2.39 64 Bits, X11 UI
Graphics card: NVIDIA RTX A6000/PCIe/SSE2 NVIDIA Corporation 4.6.0 NVIDIA 550.90.07

Blender Version
Broken: version: 4.2.0 Beta, branch: blender-v4.2-release, commit date: 2024-07-08 19:36, hash: d527e3a6bd78
Worked: (newest version of Blender that worked as expected)

Short description of error
The RNA path that is generated for the python tooltip and by the Copy Full Data Path operator are incorrect for several settings, for example those of the viewport display.

image
image

The path is missing the components that navigate to the correct area + space within the screen

Wrong bpy.data.screens["Layout"].overlay.show_stats
Correct bpy.data.screens["Layout"].areas[3].spaces[0].overlay.show_stats

Exact steps for others to reproduce the error

  • hover over Statistics overlay toggle
  • right click and press Copy Full Data Path
  • paste in python console and hit enter
**System Information** Operating system: Linux-6.8.12-gentoo-x86_64-AMD_Ryzen_9_5950X_16-Core_Processor-with-glibc2.39 64 Bits, X11 UI Graphics card: NVIDIA RTX A6000/PCIe/SSE2 NVIDIA Corporation 4.6.0 NVIDIA 550.90.07 **Blender Version** Broken: version: 4.2.0 Beta, branch: blender-v4.2-release, commit date: 2024-07-08 19:36, hash: `d527e3a6bd78` Worked: (newest version of Blender that worked as expected) **Short description of error** The RNA path that is generated for the python tooltip and by the `Copy Full Data Path` operator are incorrect for several settings, for example those of the viewport display. ![image](/attachments/1a8b40b9-1dbb-4288-81f8-355865f1a5fd) ![image](/attachments/c5155b69-4960-4b85-9778-42274a2b3aa3) The path is missing the components that navigate to the correct area + space within the screen Wrong `bpy.data.screens["Layout"].overlay.show_stats` Correct `bpy.data.screens["Layout"].areas[3].spaces[0].overlay.show_stats` **Exact steps for others to reproduce the error** - hover over `Statistics` overlay toggle - right click and press `Copy Full Data Path` - paste in python console and hit enter
Simon Thommes added the
Type
Report
Status
Needs Triage
Severity
Normal
labels 2024-07-11 15:09:20 +02:00
Member

I think this might be the limitation of RNA get path... however in this situation I would expect it to have ... in the middle

I _think_ this might be the limitation of RNA get path... however in this situation I would expect it to have `...` in the middle
Member

Yeah, space paths are broken (also see a37ff68334).

Will confirm anyways

Yeah, space paths are broken (also see a37ff683348f7a1122e3a742da0e6219aed9c7c5). Will confirm anyways
Philipp Oeser added
Status
Confirmed
Module
Python API
Interest
User Interface
and removed
Status
Needs Triage
labels 2024-07-12 14:22:57 +02:00
Member

This has been bugging me for ages, will put on my desk to check on

This has been bugging me for ages, will put on my desk to check on
Philipp Oeser self-assigned this 2024-07-12 15:24:29 +02:00
Member

Something like the following will do the trick.
Can probably be used for a lot ore places/spaces.
Will try to check these and create a PR next week

diff --git a/source/blender/blenkernel/BKE_screen.hh b/source/blender/blenkernel/BKE_screen.hh
index 06889d474b5..61a015bfe48 100644
--- a/source/blender/blenkernel/BKE_screen.hh
+++ b/source/blender/blenkernel/BKE_screen.hh
@@ -675,6 +675,10 @@ ARegion *BKE_screen_find_main_region_at_xy(const bScreen *screen, int space_type
 ScrArea *BKE_screen_find_area_from_space(const bScreen *screen,
                                          const SpaceLink *sl) ATTR_WARN_UNUSED_RESULT
     ATTR_NONNULL(1, 2);
+/**
+ * \note used to get proper RNA paths for spaces.
+ */
+std::optional<std::string> BKE_screen_path_from_screen_to_space(const PointerRNA *ptr);
 /**
  * \note Using this function is generally a last resort, you really want to be
  * using the context when you can - campbell
diff --git a/source/blender/blenkernel/intern/screen.cc b/source/blender/blenkernel/intern/screen.cc
index 5f2b8504acf..2f5e687344d 100644
--- a/source/blender/blenkernel/intern/screen.cc
+++ b/source/blender/blenkernel/intern/screen.cc
@@ -13,6 +13,8 @@
 #  include "BLI_winstuff.h"
 #endif
 
+#include <fmt/format.h>
+
 #include <cmath>
 #include <cstdio>
 #include <cstring>
@@ -868,6 +870,22 @@ ScrArea *BKE_screen_find_area_from_space(const bScreen *screen, const SpaceLink
   return nullptr;
 }
 
+std::optional<std::string> BKE_screen_path_from_screen_to_space(const PointerRNA *ptr)
+{
+  bScreen *screen = (bScreen *)ptr->owner_id;
+  SpaceLink *link = (SpaceLink *)ptr->data;
+
+  int area_index;
+  LISTBASE_FOREACH_INDEX (ScrArea *, area, &screen->areabase, area_index) {
+    const int space_index = BLI_findindex(&area->spacedata, link);
+    if (space_index != -1) {
+      return fmt::format("areas[{}].spaces[{}].", area_index, space_index);
+    }
+  }
+
+  return nullptr;
+}
+
 ScrArea *BKE_screen_find_big_area(const bScreen *screen, const int spacetype, const short min)
 {
   ScrArea *big = nullptr;
diff --git a/source/blender/makesrna/intern/rna_space.cc b/source/blender/makesrna/intern/rna_space.cc
index e31d702087b..99f1cf7ef74 100644
--- a/source/blender/makesrna/intern/rna_space.cc
+++ b/source/blender/makesrna/intern/rna_space.cc
@@ -536,6 +536,7 @@ static const EnumPropertyItem rna_enum_curve_display_handle_items[] = {
 #ifdef RNA_RUNTIME
 
 #  include <algorithm>
+#  include <fmt/format.h>
 
 #  include "AS_asset_representation.hh"
 
@@ -1591,9 +1592,9 @@ static PointerRNA rna_SpaceView3D_overlay_get(PointerRNA *ptr)
   return rna_pointer_inherit_refine(ptr, &RNA_View3DOverlay, ptr->data);
 }
 
-static std::optional<std::string> rna_View3DOverlay_path(const PointerRNA * /*ptr*/)
+static std::optional<std::string> rna_View3DOverlay_path(const PointerRNA *ptr)
 {
-  return "overlay";
+  return fmt::format("{}{}", BKE_screen_path_from_screen_to_space(ptr).value_or(""), "overlay");
 }
 
 /* Space Image Editor */
Something like the following will do the trick. Can probably be used for a lot ore places/spaces. Will try to check these and create a PR next week ```C diff --git a/source/blender/blenkernel/BKE_screen.hh b/source/blender/blenkernel/BKE_screen.hh index 06889d474b5..61a015bfe48 100644 --- a/source/blender/blenkernel/BKE_screen.hh +++ b/source/blender/blenkernel/BKE_screen.hh @@ -675,6 +675,10 @@ ARegion *BKE_screen_find_main_region_at_xy(const bScreen *screen, int space_type ScrArea *BKE_screen_find_area_from_space(const bScreen *screen, const SpaceLink *sl) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1, 2); +/** + * \note used to get proper RNA paths for spaces. + */ +std::optional<std::string> BKE_screen_path_from_screen_to_space(const PointerRNA *ptr); /** * \note Using this function is generally a last resort, you really want to be * using the context when you can - campbell diff --git a/source/blender/blenkernel/intern/screen.cc b/source/blender/blenkernel/intern/screen.cc index 5f2b8504acf..2f5e687344d 100644 --- a/source/blender/blenkernel/intern/screen.cc +++ b/source/blender/blenkernel/intern/screen.cc @@ -13,6 +13,8 @@ # include "BLI_winstuff.h" #endif +#include <fmt/format.h> + #include <cmath> #include <cstdio> #include <cstring> @@ -868,6 +870,22 @@ ScrArea *BKE_screen_find_area_from_space(const bScreen *screen, const SpaceLink return nullptr; } +std::optional<std::string> BKE_screen_path_from_screen_to_space(const PointerRNA *ptr) +{ + bScreen *screen = (bScreen *)ptr->owner_id; + SpaceLink *link = (SpaceLink *)ptr->data; + + int area_index; + LISTBASE_FOREACH_INDEX (ScrArea *, area, &screen->areabase, area_index) { + const int space_index = BLI_findindex(&area->spacedata, link); + if (space_index != -1) { + return fmt::format("areas[{}].spaces[{}].", area_index, space_index); + } + } + + return nullptr; +} + ScrArea *BKE_screen_find_big_area(const bScreen *screen, const int spacetype, const short min) { ScrArea *big = nullptr; diff --git a/source/blender/makesrna/intern/rna_space.cc b/source/blender/makesrna/intern/rna_space.cc index e31d702087b..99f1cf7ef74 100644 --- a/source/blender/makesrna/intern/rna_space.cc +++ b/source/blender/makesrna/intern/rna_space.cc @@ -536,6 +536,7 @@ static const EnumPropertyItem rna_enum_curve_display_handle_items[] = { #ifdef RNA_RUNTIME # include <algorithm> +# include <fmt/format.h> # include "AS_asset_representation.hh" @@ -1591,9 +1592,9 @@ static PointerRNA rna_SpaceView3D_overlay_get(PointerRNA *ptr) return rna_pointer_inherit_refine(ptr, &RNA_View3DOverlay, ptr->data); } -static std::optional<std::string> rna_View3DOverlay_path(const PointerRNA * /*ptr*/) +static std::optional<std::string> rna_View3DOverlay_path(const PointerRNA *ptr) { - return "overlay"; + return fmt::format("{}{}", BKE_screen_path_from_screen_to_space(ptr).value_or(""), "overlay"); } /* Space Image Editor */ ```

General approach LGTM from a quick look, yes. :)

General approach LGTM from a quick look, yes. :)
Member

Fix is up, see !125365

Fix is up, see !125365
Blender Bot added
Status
Resolved
and removed
Status
Confirmed
labels 2024-08-05 16:54:57 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#124527
No description provided.