Esempio n. 1
0
        /// <summary>
        /// The main (and only :-) command 
        /// of our export sample
        /// </summary>
        public Result Execute(
            ExternalCommandData data,
            ref string msg,
            ElementSet elements)
        {
            // This command requires an active document

               UIDocument uidoc = data.Application
             .ActiveUIDocument;

               if (uidoc == null)
               {
               msg = "Please run this command in an active project document.";
               return Result.Failed;
               }

               Document doc = uidoc.Document;

               // Collect all 3D views in the document
               // (there must be at least one). The collection
               // will be listed in the option dialog for the
               // user to choose the ones to include in the
               // export.
               List<View3D> views = new List<View3D>(
            new FilteredElementCollector(doc)
              .OfClass(typeof(View3D))
              .Cast<View3D>()
              .Where<View3D>(v =>
            v.CanBePrinted && !v.IsTemplate));

               int n = views.Count;

               if (0 == n)
               {
               msg = "There are no 3D views in the document!";
               return Result.Failed;
               }

               // Initiate output with default path to
               // MyDocuments and the current document name

               string defaultName = Path.ChangeExtension(
             doc.Title, ".xml");

               string defaultFolder = System.Environment
             .GetFolderPath(
               Environment.SpecialFolder.MyDocuments);

               // Instantiate our custom context

               ExportContext context = new ExportContext(doc);

               // Instantiate a custom exporter with output
               // context given as the argument

               using (CustomExporter exporter
             = new CustomExporter(doc, context))
               {

               List<ElementId> viewsToExport = new List<ElementId>();

               foreach (View3D v in views)
               {
                   viewsToExport.Add(v.Id);
               }
               try
               {
                   exporter.Export(viewsToExport);
               }
               catch (System.Exception ex)
               {
                   msg = "Exception: " + ex.Message;
                   return Result.Failed;
               }
               }
               return Result.Succeeded;
        }
Esempio n. 2
0
        /// <summary>
        /// The main (and only :-) command
        /// of our export sample
        /// </summary>
        public Result Execute(
            ExternalCommandData data,
            ref string msg,
            ElementSet elements)
        {
            // This command requires an active document

            UIDocument uidoc = data.Application
                               .ActiveUIDocument;

            if (uidoc == null)
            {
                msg = "Please run this command in an active project document.";
                return(Result.Failed);
            }

            Document doc = uidoc.Document;

            // Collect all 3D views in the document
            // (there must be at least one). The collection
            // will be listed in the option dialog for the
            // user to choose the ones to include in the
            // export.
            List <View3D> views = new List <View3D>(
                new FilteredElementCollector(doc)
                .OfClass(typeof(View3D))
                .Cast <View3D>()
                .Where <View3D>(v =>
                                v.CanBePrinted && !v.IsTemplate));

            int n = views.Count;

            if (0 == n)
            {
                msg = "There are no 3D views in the document!";
                return(Result.Failed);
            }

            // Initiate output with default path to
            // MyDocuments and the current document name

            string defaultName = Path.ChangeExtension(
                doc.Title, ".xml");

            string defaultFolder = System.Environment
                                   .GetFolderPath(
                Environment.SpecialFolder.MyDocuments);



            // Instantiate our custom context

            ExportContext context = new ExportContext(doc);

            // Instantiate a custom exporter with output
            // context given as the argument

            using (CustomExporter exporter
                       = new CustomExporter(doc, context))
            {
                List <ElementId> viewsToExport = new List <ElementId>();

                foreach (View3D v in views)
                {
                    viewsToExport.Add(v.Id);
                }
                try
                {
                    exporter.Export(viewsToExport);
                }
                catch (System.Exception ex)
                {
                    msg = "Exception: " + ex.Message;
                    return(Result.Failed);
                }
            }
            return(Result.Succeeded);
        }