Skip to content

Commit 22495ef

Browse files
author
Ben Supnik
committed
for Petr - this gets into the main code base an option Ted coded a while
ago to hook in an "export selected" operator.
1 parent 9803be2 commit 22495ef

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

io_xplane2blender/xplane_export.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ class EXPORT_OT_ExportXPlane(bpy.types.Operator, ExportHelper):
4747
default="",
4848
)
4949

50+
only_selected_roots: bpy.props.BoolProperty(
51+
name = "Only Selected Roots",
52+
description = "If true, only valid selected roots will be exported",
53+
default=False
54+
)
55+
5056
export_is_relative: bpy.props.BoolProperty(
5157
name="Export Is Relative",
5258
description="Set to true when starting the export via the button (with or without the GUI on in case of unit testing)",
@@ -93,7 +99,9 @@ def execute(self, context):
9399
bpy.context.view_layer.update()
94100

95101
xplaneFiles = xplane_file.createFilesFromBlenderRootObjects(
96-
bpy.context.scene, bpy.context.view_layer
102+
bpy.context.scene,
103+
bpy.context.view_layer,
104+
self.only_selected_roots
97105
)
98106
for xplaneFile in xplaneFiles:
99107
if not self._writeXPlaneFile(xplaneFile, export_directory):

io_xplane2blender/xplane_types/xplane_file.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ class NotExportableRootError(ValueError):
5151

5252

5353
def createFilesFromBlenderRootObjects(
54-
scene: bpy.types.Scene, view_layer: bpy.types.ViewLayer
54+
scene: bpy.types.Scene,
55+
view_layer: bpy.types.ViewLayer,
56+
only_selected_roots: bool = False,
5557
) -> List["XPlaneFile"]:
5658
"""
5759
Returns a list of all created XPlaneFiles from all valid roots found,
@@ -60,9 +62,15 @@ def createFilesFromBlenderRootObjects(
6062
view_layer is needed to test exportability
6163
"""
6264
xplane_files: List["XPlaneFile"] = []
63-
for potential_root in (
64-
scene.objects[:] + xplane_helpers.get_collections_in_scene(scene)[1:]
65-
):
65+
66+
if only_selected_roots:
67+
potential_roots = [ob for ob in scene.objects if ob.select_get()]
68+
else:
69+
potential_roots = (
70+
scene.objects[:] + xplane_helpers.get_collections_in_scene(scene)[1:]
71+
)
72+
73+
for potential_root in potential_roots:
6674
try:
6775
xplane_file = createFileFromBlenderRootObject(potential_root, view_layer)
6876
except NotExportableRootError as e:

0 commit comments

Comments
 (0)