Custom Constraint Implementation¶
Tip
You may check how built-in Constraints are implemented here.
You may create your own custom Constraint implementation by following steps.
- Run
AutoSetSyntax: Create New Constraintfrom the command palette1. -
It will create a template like
Example
from __future__ import annotations from AutoSetSyntax.plugin import AbstractConstraint, ViewSnapshot class MyOwnConstraint(AbstractConstraint): """Your custom `Constraint` must inherit `AbstractConstraint` and implement the `test` method.""" def is_droppable(self) -> bool: # Optionally, you can implement `is_droppable` to indicate that this object # can be dropped under certain circumstances by the optimizer. return False def test(self, view_snapshot: ViewSnapshot) -> bool: # Your job is to implement this function, at least. # This function tests the `view_snapshot`. return False -
Decide the constraint name of your
Constraint.Say, if your class name is
MyOwnConstraint, the constraint name is decided by- Remove
Constraintsuffix from the class name. (MyOwnConstraint»MyOwn) - Convert it into snake case. (
MyOwn»my_own)
That is, you can use it via
"constraint": "my_own"in a constraint rule. - Remove
-
At least, implement the
testmethod. -
Save your implementation in
Packages/AutoSetSyntax-Custom/constraints/. Conventionally, the file name used is the constraint name,my_own.py. -
Restart ST and check whether your implementation is loaded via Debug Information.
-
Command palette: Ctrl+P for Windows/Linux. Cmd+P for macOS. ↩