Commit: c722c5204f55105d725de8358e5d83e09c6d5fd9
Author: Brecht Van Lommel
Date:   Wed Jul 17 14:41:50 2019 +0200
Branches: master
https://developer.blender.org/rBc722c5204f55105d725de8358e5d83e09c6d5fd9

Fix T67075: make object.visible_get() and similar APIs more forgiving

When objects are not in the view layer, just return false rather than throwing
an error. As far as the script is concerned the object is not visible or
selected when it's not in the current view layer.

===================================================================

M       source/blender/makesrna/intern/rna_object_api.c

===================================================================

diff --git a/source/blender/makesrna/intern/rna_object_api.c 
b/source/blender/makesrna/intern/rna_object_api.c
index a891e11a944..15f79ea3e89 100644
--- a/source/blender/makesrna/intern/rna_object_api.c
+++ b/source/blender/makesrna/intern/rna_object_api.c
@@ -98,11 +98,13 @@ static void rna_Object_select_set(
   Base *base = BKE_view_layer_base_find(view_layer, ob);
 
   if (!base) {
-    BKE_reportf(reports,
-                RPT_ERROR,
-                "Object '%s' not in View Layer '%s'!",
-                ob->id.name + 2,
-                view_layer->name);
+    if (select) {
+      BKE_reportf(reports,
+                  RPT_ERROR,
+                  "Object '%s' can't be selected because it is not in View 
Layer '%s'!",
+                  ob->id.name + 2,
+                  view_layer->name);
+    }
     return;
   }
 
@@ -113,10 +115,7 @@ static void rna_Object_select_set(
   WM_main_add_notifier(NC_SCENE | ND_OB_SELECT, scene);
 }
 
-static bool rna_Object_select_get(Object *ob,
-                                  bContext *C,
-                                  ReportList *reports,
-                                  ViewLayer *view_layer)
+static bool rna_Object_select_get(Object *ob, bContext *C, ViewLayer 
*view_layer)
 {
   if (view_layer == NULL) {
     view_layer = CTX_data_view_layer(C);
@@ -124,11 +123,6 @@ static bool rna_Object_select_get(Object *ob,
   Base *base = BKE_view_layer_base_find(view_layer, ob);
 
   if (!base) {
-    BKE_reportf(reports,
-                RPT_ERROR,
-                "Object '%s' not in View Layer '%s'!",
-                ob->id.name + 2,
-                view_layer->name);
     return false;
   }
 
@@ -144,11 +138,13 @@ static void rna_Object_hide_set(
   Base *base = BKE_view_layer_base_find(view_layer, ob);
 
   if (!base) {
-    BKE_reportf(reports,
-                RPT_ERROR,
-                "Object '%s' not in View Layer '%s'!",
-                ob->id.name + 2,
-                view_layer->name);
+    if (hide) {
+      BKE_reportf(reports,
+                  RPT_ERROR,
+                  "Object '%s' can't be hidden because it is not in View Layer 
'%s'!",
+                  ob->id.name + 2,
+                  view_layer->name);
+    }
     return;
   }
 
@@ -165,10 +161,7 @@ static void rna_Object_hide_set(
   WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
 }
 
-static bool rna_Object_hide_get(Object *ob,
-                                bContext *C,
-                                ReportList *reports,
-                                ViewLayer *view_layer)
+static bool rna_Object_hide_get(Object *ob, bContext *C, ViewLayer *view_layer)
 {
   if (view_layer == NULL) {
     view_layer = CTX_data_view_layer(C);
@@ -176,19 +169,13 @@ static bool rna_Object_hide_get(Object *ob,
   Base *base = BKE_view_layer_base_find(view_layer, ob);
 
   if (!base) {
-    BKE_reportf(reports,
-                RPT_ERROR,
-                "Object '%s' not in View Layer '%s'!",
-                ob->id.name + 2,
-                view_layer->name);
     return false;
   }
 
   return ((base->flag & BASE_HIDDEN) != 0);
 }
 
-static bool rna_Object_visible_get(
-    Object *ob, bContext *C, ReportList *reports, ViewLayer *view_layer, 
View3D *v3d)
+static bool rna_Object_visible_get(Object *ob, bContext *C, ViewLayer 
*view_layer, View3D *v3d)
 {
   if (view_layer == NULL) {
     view_layer = CTX_data_view_layer(C);
@@ -199,21 +186,13 @@ static bool rna_Object_visible_get(
   Base *base = BKE_view_layer_base_find(view_layer, ob);
 
   if (!base) {
-    BKE_reportf(reports,
-                RPT_ERROR,
-                "Object '%s' not in View Layer '%s'!",
-                ob->id.name + 2,
-                view_layer->name);
     return false;
   }
 
   return BASE_VISIBLE(v3d, base);
 }
 
-static bool rna_Object_holdout_get(Object *ob,
-                                   bContext *C,
-                                   ReportList *reports,
-                                   ViewLayer *view_layer)
+static bool rna_Object_holdout_get(Object *ob, bContext *C, ViewLayer 
*view_layer)
 {
   if (view_layer == NULL) {
     view_layer = CTX_data_view_layer(C);
@@ -221,21 +200,13 @@ static bool rna_Object_holdout_get(Object *ob,
   Base *base = BKE_view_layer_base_find(view_layer, ob);
 
   if (!base) {
-    BKE_reportf(reports,
-                RPT_ERROR,
-                "Object '%s' not in View Layer '%s'!",
-                ob->id.name + 2,
-                view_layer->name);
     return false;
   }
 
   return ((base->flag & BASE_HOLDOUT) != 0);
 }
 
-static bool rna_Object_indirect_only_get(Object *ob,
-                                         bContext *C,
-                                         ReportList *reports,
-                                         ViewLayer *view_layer)
+static bool rna_Object_indirect_only_get(Object *ob, bContext *C, ViewLayer 
*view_layer)
 {
   if (view_layer == NULL) {
     view_layer = CTX_data_view_layer(C);
@@ -243,11 +214,6 @@ static bool rna_Object_indirect_only_get(Object *ob,
   Base *base = BKE_view_layer_base_find(view_layer, ob);
 
   if (!base) {
-    BKE_reportf(reports,
-                RPT_ERROR,
-                "Object '%s' not in View Layer '%s'!",
-                ob->id.name + 2,
-                view_layer->name);
     return false;
   }
 
@@ -741,7 +707,7 @@ void RNA_api_object(StructRNA *srna)
   func = RNA_def_function(srna, "select_get", "rna_Object_select_get");
   RNA_def_function_ui_description(
       func, "Test if the object is selected. The selection state is per view 
layer");
-  RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
+  RNA_def_function_flag(func, FUNC_USE_CONTEXT);
   parm = RNA_def_pointer(
       func, "view_layer", "ViewLayer", "", "Use this instead of the active 
view layer");
   parm = RNA_def_boolean(func, "result", 0, "", "Object selected");
@@ -760,7 +726,7 @@ void RNA_api_object(StructRNA *srna)
   RNA_def_function_ui_description(
       func,
       "Test if the object is hidden for viewport editing. This hiding state is 
per view layer");
-  RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
+  RNA_def_function_flag(func, FUNC_USE_CONTEXT);
   parm = RNA_def_pointer(
       func, "view_layer", "ViewLayer", "", "Use this instead of the active 
view layer");
   parm = RNA_def_boolean(func, "result", 0, "", "Object hideed");
@@ -779,7 +745,7 @@ void RNA_api_object(StructRNA *srna)
   RNA_def_function_ui_description(func,
                                   "Test if the object is visible in the 3D 
viewport, taking into "
                                   "account all visibility settings");
-  RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
+  RNA_def_function_flag(func, FUNC_USE_CONTEXT);
   parm = RNA_def_pointer(
       func, "view_layer", "ViewLayer", "", "Use this instead of the active 
view layer");
   parm = RNA_def_pointer(
@@ -789,7 +755,7 @@ void RNA_api_object(StructRNA *srna)
 
   func = RNA_def_function(srna, "holdout_get", "rna_Object_holdout_get");
   RNA_def_function_ui_description(func, "Test if object is masked in the view 
layer");
-  RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
+  RNA_def_function_flag(func, FUNC_USE_CONTEXT);
   parm = RNA_def_pointer(
       func, "view_layer", "ViewLayer", "", "Use this instead of the active 
view layer");
   parm = RNA_def_boolean(func, "result", 0, "", "Object holdout");
@@ -799,7 +765,7 @@ void RNA_api_object(StructRNA *srna)
   RNA_def_function_ui_description(func,
                                   "Test if object is set to contribute only 
indirectly (through "
                                   "shadows and reflections) in the view 
layer");
-  RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
+  RNA_def_function_flag(func, FUNC_USE_CONTEXT);
   parm = RNA_def_pointer(
       func, "view_layer", "ViewLayer", "", "Use this instead of the active 
view layer");
   parm = RNA_def_boolean(func, "result", 0, "", "Object indirect only");

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to