48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
"""Scene-level settings shared by asset and shot files."""
|
|
|
|
import math
|
|
|
|
from ... import config
|
|
from ...core import Check, Issue, contexts
|
|
|
|
|
|
class UnitsCheck(Check):
|
|
id = "units"
|
|
label = "Units"
|
|
description = "Unit system, unit scale and length unit follow the production specs."
|
|
category = "Scene"
|
|
contexts = contexts.ALL
|
|
fix_description = "Set the production units"
|
|
|
|
def run(self, ctx):
|
|
units = ctx.scene.unit_settings
|
|
if units.system != config.UNIT_SYSTEM:
|
|
yield Issue(f"Unit system is {units.system}, expected {config.UNIT_SYSTEM}")
|
|
if not math.isclose(units.scale_length, config.UNIT_SCALE_LENGTH, rel_tol=1e-6):
|
|
yield Issue(f"Unit scale is {units.scale_length:g}, expected {config.UNIT_SCALE_LENGTH:g}")
|
|
if config.UNIT_LENGTH and units.length_unit != config.UNIT_LENGTH:
|
|
yield Issue(f"Length unit is {units.length_unit}, expected {config.UNIT_LENGTH}")
|
|
|
|
def fix(self, ctx, issues):
|
|
units = ctx.scene.unit_settings
|
|
units.system = config.UNIT_SYSTEM
|
|
units.scale_length = config.UNIT_SCALE_LENGTH
|
|
if config.UNIT_LENGTH:
|
|
units.length_unit = config.UNIT_LENGTH
|
|
|
|
|
|
class FilenameCheck(Check):
|
|
id = "filename"
|
|
label = "File name"
|
|
description = "The file is saved and its name follows the naming pattern of the context."
|
|
category = "File"
|
|
contexts = contexts.ALL
|
|
|
|
def run(self, ctx):
|
|
if not ctx.filepath:
|
|
yield Issue("The file has never been saved")
|
|
return
|
|
pattern = config.FILENAME_PATTERNS.get(ctx.context_id)
|
|
if pattern and ctx.filename_match is None:
|
|
yield Issue(f"'{ctx.filename}' does not match {pattern}")
|