diff --git a/openpype/hosts/blender/plugins/publish/validate_file_saved.py b/openpype/hosts/blender/plugins/publish/validate_file_saved.py index 44b33a573a..442f856e05 100644 --- a/openpype/hosts/blender/plugins/publish/validate_file_saved.py +++ b/openpype/hosts/blender/plugins/publish/validate_file_saved.py @@ -18,7 +18,7 @@ class SaveWorkfileAction(pyblish.api.Action): bpy.ops.wm.avalon_workfiles() -class ValidateFileSaved(pyblish.api.InstancePlugin, +class ValidateFileSaved(pyblish.api.ContextPlugin, OptionalPyblishPluginMixin): """Validate that the workfile has been saved.""" @@ -29,18 +29,33 @@ class ValidateFileSaved(pyblish.api.InstancePlugin, exclude_families = [] actions = [SaveWorkfileAction] - def process(self, instance): - if not self.is_active(instance.data): + def process(self, context): + if not self.is_active(context.data): return - if not instance.context.data["currentFile"]: + if not context.data["currentFile"]: # File has not been saved at all and has no filename raise PublishValidationError( "Current file is empty. Save the file before continuing." ) - if [ef for ef in self.exclude_families - if instance.data["family"] in ef]: + # Do not validate workfile has unsaved changes if only instances + # present of families that should be excluded + families = { + instance.data["family"] for instance in context + # Consider only enabled instances + if instance.data.get("publish", True) + and instance.data.get("active", True) + } + + def is_excluded(family): + return any(family in exclude_family + for exclude_family in self.exclude_families) + + if all(is_excluded(family) for family in families): + self.log.debug("Only excluded families found, skipping workfile " + "unsaved changes validation..") return + if bpy.data.is_dirty: raise PublishValidationError("Workfile has unsaved changes.")