Skip to content

Commit d178f36

Browse files
committed
New feature: before exporting a collection check its view_layer.exclude + verification test
1 parent 53d302f commit d178f36

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

ext.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,32 @@ class BFCollection:
163163
Extension of Blender Collection.
164164
"""
165165

166+
def get_layer_collection(self, context, _layer_collection=None):
167+
"""!
168+
Return related layer_collection in current context.
169+
@param context: the Blender context.
170+
@param _layer_collection: internal use for recursivity.
171+
@return layer_collection related to self in current context.
172+
"""
173+
if not _layer_collection:
174+
_layer_collection = context.view_layer.layer_collection
175+
found = None
176+
if _layer_collection.name == self.name:
177+
return _layer_collection
178+
for c in _layer_collection.children:
179+
found = self.get_layer_collection(context, _layer_collection=c)
180+
if found:
181+
return found
182+
166183
def to_fds(self, context):
167184
"""!
168185
Return the FDS formatted string.
169186
@param context: the Blender context.
170187
@return FDS formatted string, eg. "&OBST ID='Test' /".
171188
"""
172-
if self.hide_render:
173-
return
189+
layer_collection = self.get_layer_collection(context)
190+
if self.hide_render or layer_collection.exclude:
191+
return # exclude from exporting
174192
obs = list(self.objects)
175193
obs.sort(key=lambda k: k.name) # alphabetic by name
176194
lines = list(ob.to_fds(context) for ob in obs)
@@ -187,6 +205,7 @@ def register(cls):
187205
@param cls: class to be registered.
188206
"""
189207
Collection.to_fds = cls.to_fds
208+
Collection.get_layer_collection = cls.get_layer_collection
190209

191210
@classmethod
192211
def unregister(cls):
@@ -195,6 +214,7 @@ def unregister(cls):
195214
@param cls: class to be unregistered.
196215
"""
197216
del Collection.to_fds
217+
del Collection.get_layer_collection
198218

199219

200220
class BFScene:

0 commit comments

Comments
 (0)