Beispiel #1
0
        private string ChooseFile(string format)
        {
            FileOpenDialog openFileDialog = new FileOpenDialog(format);

            openFileDialog.Show();
            ModelPath userPath = openFileDialog.GetSelectedModelPath();

            ModelPathUtils.ConvertModelPathToUserVisiblePath(userPath);
            return(ModelPathUtils.ConvertModelPathToUserVisiblePath(userPath));
        }
Beispiel #2
0
        /// <summary>Shows the open translation dialog and possibly opens a file.</summary>
        /// <remarks>If there's a translation currently open with unsaved changes, a warning dialog
        /// is shown before opening the new file.</remarks>
        public void TranslationOpen()
        {
            FileOpenDialog dialog = Base.Dialogs.Get(typeof(FileTranslationOpenDialog)) as FileOpenDialog;

            dialog.Show();
            bool toOpen = dialog.WaitForResponse();

            if (toOpen && ToOpenTranslationAfterWarning())
            {
                string filename = dialog.Filename;
                int    codePage = (dialog.Encoding.Equals(EncodingDescription.Empty) ? -1 : dialog.Encoding.CodePage);
                OpenTranslation(filename, codePage);
            }
        }
Beispiel #3
0
        /// <summary>Shows the open dialog and possibly opens a subtitle.</summary>
        /// <remarks>If there's a document currently open with unsaved changes, a warning dialog
        /// is shown before opening the new file.</remarks>
        public void Open()
        {
            FileOpenDialog dialog = Base.Dialogs.Get(typeof(FileOpenDialog)) as FileOpenDialog;

            dialog.Show();
            bool gotOpenResponse = dialog.WaitForResponse();

            if (gotOpenResponse && ToOpenAfterWarning())
            {
                string filename = dialog.Filename;
                int    codePage = (dialog.Encoding.Equals(EncodingDescription.Empty) ? -1 : dialog.Encoding.CodePage);
                Uri    videoUri = dialog.VideoUri;
                Open(filename, codePage, videoUri);
            }
        }
        private bool ShowDialog(IntPtr owner)
        {
            IFileOpenDialog fod = null;

            try
            {
                fod = new FileOpenDialog() as IFileOpenDialog;
                fod.SetOptions(FOS.FOS_PICKFOLDERS | FOS.FOS_FORCEFILESYSTEM);

                if (!string.IsNullOrEmpty(InitialPath))
                {
                    uint attribute = 0U;
                    if ((SHILCreateFromPath(InitialPath, out IntPtr idl, ref attribute) == S_OK) &&
                        (SHCreateShellItem(IntPtr.Zero, IntPtr.Zero, idl, out IShellItem item) == S_OK))
                    {
                        fod.SetFolder(item);
                    }
                }

                if (!string.IsNullOrEmpty(Title))
                {
                    fod.SetTitle(Title);
                }

                if (fod.Show(owner) != S_OK)
                {
                    return(false);
                }

                SelectedPath = fod.GetResult().GetDisplayName(SIGDN.SIGDN_FILESYSPATH);
                return(true);
            }
            catch (COMException ce)
            {
                Debug.WriteLine($"Failed to manage open folder dialog.\r\n{ce}");
                return(false);
            }
            finally
            {
                if (fod is not null)
                {
                    Marshal.FinalReleaseComObject(fod);
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// カスタムファイル選択ダイアログを表示します。
        /// </summary>
        /// <returns></returns>
        public ShellFile ShowCustomFileOpenDialog()
        {
            using (var dialog = new FileOpenDialog())
            {
                // Custom Controls
                var button1 = new FileDialogButton("button", "Button1");
                button1.Click += (_, args) => MessageBox.Show("Button1", "Message");
                dialog.Controls.Add(button1);

                var combo1 = new FileDialogComboBox("combo1",
                                                    new FileDialogComboBoxItem("Item1"),
                                                    new FileDialogComboBoxItem("Item2"),
                                                    new FileDialogComboBoxItem("Item3"));
                dialog.Controls.Add(combo1);

                if (dialog.Show() == FileDialogResult.Ok)
                {
                    return(dialog.GetShellFiles().FirstOrDefault());
                }
                return(null);
            }
        }
        public void Execute(UIApplication app)
        {
            Transaction transaction = null;

            try
            {
                this.calculator = new SimpleCalculator();

                this.App = app;
                this.Doc = app.ActiveUIDocument.Document;
                using (transaction = new Transaction(Doc))
                {
                    transaction.Start("auto arrangement");
                    this.symbol = GetFamilySymbol();
                    var ids = app.ActiveUIDocument.Selection.GetElementIds().ToList();
                    if (ids == null || ids.Count == 0)
                    {
                        TaskDialog.Show("Ошибка", "Помещения не выбраны");
                        return;
                    }
                    if (symbol == null)
                    {
                        var dr = TaskDialog.Show("Ошибка загрузки", "Семейство не найдено. Выберите путь...", TaskDialogCommonButtons.Ok | TaskDialogCommonButtons.Cancel, TaskDialogResult.Ok);
                        if (dr == TaskDialogResult.Ok)
                        {
                            FileOpenDialog fileOpenDialog = new FileOpenDialog("revit files (*.rfa)|*.rfa|All files (*.*)|*.*");
                            var            fodr           = fileOpenDialog.Show();
                            if (fodr == ItemSelectionDialogResult.Confirmed)
                            {
                                var model  = fileOpenDialog.GetSelectedModelPath();
                                var path   = ModelPathUtils.ConvertModelPathToUserVisiblePath(model);
                                var loaded = Doc.LoadFamilySymbol(path, this.FamilySymbolName, out FamilySymbol loadedFS);
                                if (!loaded)
                                {
                                    TaskDialog.Show("Ошибка загрузки семейства", "Не найдено семейство с названием \"ИП 212-64 прот. R3 ПАСН.425232.038\"");
                                    return;
                                }
                                else
                                {
                                    this.symbol = loadedFS;
                                }
                            }
                        }
                    }
                    if (!this.symbol.IsActive)
                    {
                        this.symbol.Activate();
                    }
                    ids.ForEach(CreateDevices);
                    transaction.Commit();
                }
            }
            catch (Exception ex)
            {
                var s = ex.Message;
                if (transaction != null && transaction.GetStatus() != TransactionStatus.Uninitialized)
                {
                    transaction.RollBack();
                }
            }
        }
Beispiel #7
0
        public async Task <string[]> HandleAsync(string request)
        {
            string[] result;

            Task <string[]> task;

            if (request == "FILEDIALOG")
            {
                task = _revitTask
                       .Run((app) =>
                {
                    //// var document = app.Document;

                    var dialog = new FileOpenDialog("Revit Files (*.rvt)|*.rvt");

                    var dialogResult = dialog.Show();

                    var modelPath = dialog.GetSelectedModelPath();

                    var path = ModelPathUtils
                               .ConvertModelPathToUserVisiblePath(modelPath);

                    return(new[] { path });
                });
            }
            else if (request == "VIEWLIST")
            {
                task = _revitTask
                       .Run((uiapp) =>
                {
                    if (uiapp.ActiveUIDocument?.Document == null)
                    {
                        return(new[] { "No opened documents" });
                    }

                    var document = uiapp.ActiveUIDocument.Document;

                    var plans = new FilteredElementCollector(document)
                                .WhereElementIsNotElementType()
                                .OfClass(typeof(View))
                                .Select(x => x.Name)
                                .ToArray();

                    return(plans);
                });
            }
            else
            {
                task = _revitTask
                       .Run(uiapp =>
                {
                    //// TaskDialog.Show("Deb", $"Requested: {request}");

                    var command = (PostableCommand)Enum.Parse(
                        typeof(PostableCommand),
                        request,
                        true);

                    var id = RevitCommandId
                             .LookupPostableCommandId(command);

                    uiapp.PostCommand(id);

                    return(new[] { $"Successfully posted command {command}" });
                });
            }


            try
            {
                result = await task;
            }
            catch (Exception e)
            {
                result = new[] { $"{e.Message} in {e.StackTrace}" };
            }

            return(result);
        }
Beispiel #8
0
        public bool ShowDialog(IntPtr ownerWindow)
        {
            //	オーナーウィンドウを正規化する
            ownerWindow = GetSafeOwnerWindow(ownerWindow);

            //	ダイアログインターフェースを構築
            IFileOpenDialog dlg = new FileOpenDialog() as IFileOpenDialog;              //	IUnknown::QueryInterfaceを使ってインターフェースを特定する

            try
            {
                //	フォルダ選択モードに切り替え
                dlg.SetOptions(FOS.FORCEFILESYSTEM | FOS.PICKFOLDERS);
                //	以前選択されていたフォルダを指定
                bool       setFolder = false;
                IShellItem item      = CreateItem(SelectedPath);
                if (item != null)
                {
                    dlg.SetFolder(item);
                    Marshal.ReleaseComObject(item);
                    setFolder = true;
                }
                //	まだフォルダを設定していない場合は初期フォルダを設定する
                if (!setFolder)
                {
                    item = CreateItem(InitialFolder);
                    if (item != null)
                    {
                        dlg.SetFolder(item);
                        Marshal.ReleaseComObject(item);
                    }
                }
                //	タイトル
                if (!string.IsNullOrWhiteSpace(Title))
                {
                    dlg.SetTitle(Title);
                }
                //	ショートカット追加
                foreach (var place in m_places)
                {
                    item = CreateItem(place.folder);
                    if (item != null)
                    {
                        dlg.AddPlace(item, place.fdap);
                        Marshal.ReleaseComObject(item);
                    }
                }
                //	ダイアログを表示
                var hRes = dlg.Show(ownerWindow);
                if (NativeMethods.SUCCEEDED(hRes))
                {
                    item         = dlg.GetResult();
                    SelectedPath = item.GetName(SIGDN.FILESYSPATH);
                    Marshal.ReleaseComObject(item);
                    return(true);
                }
            }
            finally
            {
                Marshal.ReleaseComObject(dlg);
            }
            return(false);
        }
Beispiel #9
0
 private void GetExcelData()
 {
     var dlg    = new FileOpenDialog("xlsx");
     var result = dlg.Show();
 }
Beispiel #10
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document   doc   = uidoc.Document;

            //Create folder dialog path
            FileOpenDialog file_dia = new FileOpenDialog("SAT file (*.sat)|*.sat");

            file_dia.Title = "Select SAT file to import";
            file_dia.Show();
            ModelPath path = file_dia.GetSelectedModelPath();

            file_dia.Dispose();

            //Convert file path to a string
            string path_str = ModelPathUtils.ConvertModelPathToUserVisiblePath(path);

            SATImportOptions satOpt = new SATImportOptions();

            FilteredElementCollector filEle = new FilteredElementCollector(doc);

            IList <Element> views = filEle.OfClass(typeof(View)).ToElements();

            View import_view = views[0] as View;

            try
            {
                using (Transaction trans = new Transaction(doc, "Import SAT"))
                {   // Start transaction, import SAT file and get the element
                    trans.Start();
                    ElementId importedElementId = doc.Import(path_str, satOpt, import_view);
                    Element   importedElement   = doc.GetElement(importedElementId);

                    //Extract geometry element from the imported element
                    Options         geoOptions       = new Options();
                    GeometryElement importedGeometry = importedElement.get_Geometry(geoOptions);


                    //Iterate through the geometry elements extracting the geometry as individual elements
                    foreach (GeometryObject geoObj in importedGeometry)
                    {
                        GeometryInstance instance = geoObj as GeometryInstance;
                        foreach (GeometryObject instObj in instance.SymbolGeometry)
                        {
                            Solid solid = instObj as Solid;
                            FreeFormElement.Create(doc, solid);
                        }
                    }

                    //Delete SAT file

                    doc.Delete(importedElementId);
                    trans.Commit();
                }

                return(Result.Succeeded);
            }

            catch
            {
                TaskDialog.Show("Error Importing", "Something went wrong");
                return(Result.Failed);
            }
        }
Beispiel #11
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            // Determine source document and its unit settings

            TaskDialogResult result = TaskDialog.Show(_taskTitle,
                                                      "Select source file for units copy...",
                                                      TaskDialogCommonButtons.Ok
                                                      | TaskDialogCommonButtons.Cancel);

            if (result == TaskDialogResult.Cancel)
            {
                return(Result.Cancelled);
            }

            FileOpenDialog fileOpen = new FileOpenDialog(
                _fileFilter);

            if (fileOpen.Show() == ItemSelectionDialogResult.Canceled)
            {
                return(Result.Cancelled);
            }

            ModelPath modelPath = fileOpen.GetSelectedModelPath();

            if (modelPath == null)
            {
                return(Result.Failed);
            }

            Document originalDoc = commandData.Application
                                   .OpenAndActivateDocument(modelPath,
                                                            new OpenOptions(), false)?.Document;

            if (originalDoc == null)
            {
                return(Result.Failed);
            }

            DisplayUnit originalDisplayUnits = originalDoc.DisplayUnitSystem;
            Units       originalUnits        = originalDoc.GetUnits();

            if (originalUnits == null)
            {
                return(Result.Failed);
            }

            // Target

            result = TaskDialog.Show(_taskTitle
                                     , string.Format(
                                         "You have selected a document in {0} format.\n"
                                         + "Select target folder to copy units to - "
                                         + "all files will be upgraded & overwritten!",
                                         originalDisplayUnits.ToString())
                                     , TaskDialogCommonButtons.Ok
                                     | TaskDialogCommonButtons.Cancel);

            if (result == TaskDialogResult.Cancel)
            {
                return(Result.Cancelled);
            }

            FolderBrowserDialog folderBrowserDialog
                = new FolderBrowserDialog()
                {
                ShowNewFolderButton = false,
                };
            DialogResult dialogResult = folderBrowserDialog.ShowDialog();

            if (dialogResult == DialogResult.Cancel)
            {
                return(Result.Cancelled);
            }

            DirectoryInfo directoryInfo = new DirectoryInfo(
                folderBrowserDialog.SelectedPath);

            if (!directoryInfo.Exists)
            {
                return(Result.Failed);
            }

            IEnumerable <FileInfo> files = directoryInfo
                                           .EnumerateFiles("*", SearchOption.AllDirectories);

            foreach (FileInfo file in files)
            {
                Document doc = commandData.Application
                               .OpenAndActivateDocument(file.FullName)
                               ?.Document;

                if (doc == null)
                {
                    return(Result.Failed);
                }

                if (originalDoc != null)
                {
                    originalDoc.Close();
                    originalDoc = null;
                }

                using (Transaction t = new Transaction(doc))
                {
                    t.Start("Copy units to target");
                    doc.SetUnits(originalUnits);
                    t.Commit();

                    doc.Save();
                    originalDoc = doc;
                }
            }
            return(Result.Succeeded);
        }