public override void Execute(ScriptState state) { var filepath = state.ResolvePath(File); state.Log.Status($"Importing from {filepath}"); FileTypeInfo effectiveType = null; if (ForceType != null) { effectiveType = ForceType; } else { var ext = System.IO.Path.GetExtension(filepath); if (!FileTypeInfo.TryParseName(ext, out effectiveType)) { throw new Exception($"Unrecognised file extension \"{ext}\". Use a conventional extension or specify the type explicitly."); } } if (!effectiveType.CanImport) { throw new Exception($"No import support for {effectiveType}"); } var parentObjects = new Dictionary <string, S.Object3D>(); foreach (var kv in Parents) { var parent = state.Data.SectionsOfType <S.Object3D>().FirstOrDefault(i => i.Name == kv.Value); if (parent == null) { throw new Exception($"Cannot find rootpoint element {kv.Value}"); } parentObjects.Add(kv.Key, parent); } S.Object3D defaultRootObject; if (DefaultRootPoint != null) { defaultRootObject = state.Data.SectionsOfType <S.Object3D>().FirstOrDefault(i => i.Name == DefaultRootPoint); } else { defaultRootObject = state.DefaultRootPoint; } var throwOnNoParent = effectiveType == FileTypeInfo.Obj; S.Object3D ParentFinder(string name) { if (parentObjects.ContainsKey(name)) { return(parentObjects[name]); } if (defaultRootObject == null && throwOnNoParent) { throw new Exception($"No default- nor object-rootpoint set for {name}"); } return(defaultRootObject); } Importers.IOptionReceiver opts = effectiveType.CreateOptionReceiver(); foreach (var kv in ImporterOptions) { opts.AddOption(kv.Key, kv.Value); } bool createObjects = CreateNewObjects ?? state.CreateNewObjects; effectiveType.Import(state.Data, filepath, createObjects, ParentFinder, opts); }