blender: relocate importing code into operator
This commit is contained in:
parent
ed79a6f129
commit
23522c6231
26
__init__.py
26
__init__.py
@ -12,7 +12,9 @@ if "bpy" in locals():
|
||||
import importlib
|
||||
if "import_gds" in locals():
|
||||
importlib.reload(import_gds)
|
||||
|
||||
if "gds" in locals():
|
||||
importlib.reload(gds)
|
||||
|
||||
import bpy
|
||||
|
||||
from bpy.props import (
|
||||
@ -21,6 +23,7 @@ from bpy.props import (
|
||||
StringProperty,
|
||||
EnumProperty,
|
||||
)
|
||||
|
||||
from bpy_extras.io_utils import (
|
||||
ImportHelper,
|
||||
ExportHelper,
|
||||
@ -102,6 +105,7 @@ class ImportGDS(bpy.types.Operator, ImportHelper, IOOBJOrientationHelper):
|
||||
def execute(self, context):
|
||||
# print("Selected: " + context.active_object.name)
|
||||
from . import import_gds
|
||||
from . import gds
|
||||
|
||||
# ignore axis helper arguments
|
||||
keywords = self.as_keywords(ignore=("axis_forward",
|
||||
@ -113,20 +117,32 @@ class ImportGDS(bpy.types.Operator, ImportHelper, IOOBJOrientationHelper):
|
||||
if bpy.data.is_saved and context.user_preferences.filepaths.use_relative_paths:
|
||||
import os
|
||||
keywords["relpath"] = os.path.dirname(bpy.data.filepath)
|
||||
|
||||
# do the file import
|
||||
progressCounter = import_gds.Progressor(context.window_manager)
|
||||
|
||||
result= import_gds.load(context, **keywords)
|
||||
try:
|
||||
with open(keywords["filepath"], "rb") as file:
|
||||
lib = gds.parse_file(file, progressCounter)
|
||||
except gds.ParserError as e:
|
||||
self.report({"ERROR_INVALID_INPUT"}, "cannot parse given gds file: {}".format(e))
|
||||
|
||||
progressCounter.end()
|
||||
sceneInserter = import_gds.SceneInserter(context, lib, top_cell=keywords["top_cell_name"])
|
||||
|
||||
# properly report errors to user in ui
|
||||
if len(result) != 0 and "CANCELLED" in result:
|
||||
if not sceneInserter(progressCounter):
|
||||
self.report({"ERROR_INVALID_INPUT"}, "Could not find structure with name {}".format(keywords["top_cell_name"]))
|
||||
return {"CANCELLED"}
|
||||
|
||||
return {"FINISHED"}
|
||||
|
||||
return result
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
row = layout.row()
|
||||
row.prop(self, "top_cell_name")
|
||||
|
||||
|
||||
# row = layout.row(align=True)
|
||||
# row.prop(self, "use_smooth_groups")
|
||||
# row.prop(self, "use_edges")
|
||||
|
Loading…
Reference in New Issue
Block a user