-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
620c642
commit 341dd33
Showing
6 changed files
with
56 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import bpy | ||
from bpy.types import Collection | ||
|
||
|
||
def create_collection( | ||
name: str = "NewCollection", parent: Collection | str | None = None | ||
) -> Collection: | ||
if isinstance(parent, str): | ||
try: | ||
parent = bpy.data.collections[name] | ||
except KeyError: | ||
parent = bpy.data.collections.new(name) | ||
bpy.context.scene.collection.children.linke(parent) | ||
try: | ||
coll = bpy.data.collections[name] | ||
except KeyError: | ||
coll = bpy.data.collections.new(name) | ||
if parent is None: | ||
bpy.context.scene.collection.children.link(coll) | ||
else: | ||
parent.children.link(coll) | ||
|
||
return coll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,34 @@ | ||
import bpy | ||
from bpy.types import Collection | ||
from .bpyd.collection import create_collection | ||
|
||
|
||
def mn(): | ||
"""Return the MolecularNodes Collection | ||
def mn() -> Collection: | ||
"Return the 'MolecularNodes' collection, creating it first if required" | ||
return create_collection("MolecularNodes") | ||
|
||
The collection called 'MolecularNodes' inside the Blender scene is returned. If the | ||
collection does not exist first, it is created. | ||
""" | ||
coll = bpy.data.collections.get('MolecularNodes') | ||
if not coll: | ||
coll = bpy.data.collections.new('MolecularNodes') | ||
bpy.context.scene.collection.children.link(coll) | ||
return coll | ||
|
||
def data() -> Collection: | ||
"Return the MolecularNodes/data collection and disable it" | ||
name = ".MN_data" | ||
|
||
def armature(name='MN_armature'): | ||
coll = bpy.data.collections.get(name) | ||
if not coll: | ||
coll = bpy.data.collections.new(name) | ||
mn().children.link(coll) | ||
return coll | ||
try: | ||
return bpy.data.collections[name] | ||
except KeyError: | ||
collection = create_collection(name=name, parent=mn()) | ||
|
||
bpy.context.view_layer.layer_collection.children["MolecularNodes"].children[ | ||
collection.name | ||
].exclude = True | ||
return collection | ||
|
||
def data(suffix=""): | ||
"""A collection for storing MN related data objects. | ||
""" | ||
name = f"MN_data{suffix}" | ||
|
||
collection = bpy.data.collections.get(name) | ||
if not collection: | ||
collection = bpy.data.collections.new(name) | ||
mn().children.link(collection) | ||
def frames(name: str = "") -> Collection: | ||
"Return a collection for storing the objects that are the frames of a trajectory" | ||
return create_collection(f".data_{name}_frames", parent=data()) | ||
|
||
# disable the view of the data collection | ||
bpy.context.view_layer.layer_collection.children['MolecularNodes'].children[name].exclude = True | ||
return collection | ||
|
||
|
||
def frames(name="", parent=None, suffix="_frames"): | ||
"""Create a Collection for Frames of a Trajectory | ||
Args: | ||
name (str, optional): Name of the collection for the frames. Defaults to "". | ||
parent (_type_, optional): A blender collection which will become the parent | ||
collection. Defaults to the MolecularNodes collection if None. | ||
""" | ||
coll_frames = bpy.data.collections.new(name + suffix) | ||
if not parent: | ||
mn().children.link(coll_frames) | ||
else: | ||
parent.children.link(coll_frames) | ||
|
||
return coll_frames | ||
|
||
|
||
def cellpack(name="", parent=None, fallback=False): | ||
def cellpack(name: str = "") -> Collection: | ||
"Return a collection for storing the instances for a CellPack Ensemble" | ||
full_name = f"cellpack_{name}" | ||
coll = bpy.data.collections.get(full_name) | ||
if coll and fallback: | ||
return coll | ||
|
||
coll = bpy.data.collections.new(full_name) | ||
|
||
if parent: | ||
parent.children.link(coll) | ||
else: | ||
data().children.link(coll) | ||
|
||
return coll | ||
return create_collection(full_name, parent=data()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters