Esempio n. 1
0
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            Debug.Listeners.Clear();
            Debug.Listeners.Add(new RbsLogger.Logger("CopyTemplates"));

            Application app     = commandData.Application.Application;
            Document    mainDoc = commandData.Application.ActiveUIDocument.Document;

            DocumentSet       docSet  = app.Documents;
            List <MyDocument> allDocs = new List <MyDocument>();

            foreach (Document doc in app.Documents)
            {
                if (doc.Title == mainDoc.Title)
                {
                    continue;
                }
                if (doc.IsValidObject)
                {
                    MyDocument myDoc = new MyDocument(doc);
                    allDocs.Add(myDoc);
                }
            }
            Debug.Write("Docs count: " + allDocs.Count);
            if (allDocs.Count == 0)
            {
                message = "Нет открытых документов для копирования!";
                return(Result.Failed);
            }

            FormSelectDocument form1 = new FormSelectDocument(allDocs);

            form1.ShowDialog();
            if (form1.DialogResult != System.Windows.Forms.DialogResult.OK)
            {
                Debug.WriteLine("Cancelled by user");
                return(Result.Cancelled);
            }

            Document selectedDoc = form1.selectedDocument.doc;

            Debug.WriteLine("Selected doc: " + selectedDoc.Title);

            List <View> templates = new FilteredElementCollector(selectedDoc)
                                    .OfClass(typeof(View))
                                    .Cast <View>()
                                    .Where(v => v.IsTemplate == true)
                                    .ToList();

            Debug.WriteLine("Templates found: " + templates.Count);
            List <MyView> myViews = templates
                                    .OrderBy(i => i.Name)
                                    .Select(i => new MyView(i))
                                    .ToList();

            FormSelectTemplates form2 = new FormSelectTemplates(myViews);

            form2.ShowDialog();
            if (form2.DialogResult != System.Windows.Forms.DialogResult.OK)
            {
                Debug.WriteLine("Cancelled by user");
                return(Result.Cancelled);
            }

            List <ElementId> templateIds = form2.selectedTemplates.Select(i => i.view.Id).ToList();

            Debug.WriteLine("Selected templates: " + templateIds.Count);
            CopyPasteOptions cpo = new CopyPasteOptions();

            cpo.SetDuplicateTypeNamesHandler(new DuplicateNamesHandler());

            using (Transaction t = new Transaction(mainDoc))
            {
                t.Start("Копирование шаблонов видов");

                ElementTransformUtils.CopyElements(selectedDoc, templateIds, mainDoc, Transform.Identity, cpo);

                t.Commit();
            }

            string msg = "Успешно скопировано шаблонов: " + templateIds.Count.ToString();

            if (DuplicateTypes.types.Count > 0)
            {
                msg += "\nПродублированы: " + DuplicateTypes.ReturnAsString();
            }

            Debug.WriteLine(msg);
            TaskDialog.Show("Отчет", msg);

            return(Result.Succeeded);
        }
Esempio n. 2
0
 private void buttonNext_Click(object sender, EventArgs e)
 {
     selectedDocument  = comboBox1.SelectedItem as MyDocument;
     this.DialogResult = DialogResult.OK;
     this.Close();
 }