/// <summary>
 /// Constructor
 /// </summary>
 /// <param name="exportData">Data class object</param>
 public ExportIMGOptionsForm(ExportDataWithViews exportData)
 {
     m_exportOptions = new ImageExportOptions();
     InitializeComponent();
     this.m_exportData = exportData;
     InitializeFormats();
 }
예제 #2
0
        private List <string> ExportDraftingView(Document recipientDoc, List <ElementId> viewIds)
        {
            List <string> fileNames = new List <string>();

            try
            {
                string tempFileName  = System.IO.Path.ChangeExtension(System.IO.Path.GetRandomFileName(), "png");
                string tempImageFile = System.IO.Path.Combine(System.IO.Path.GetTempPath(), tempFileName);

                ImageExportOptions option = new ImageExportOptions();
                option.FilePath = tempImageFile;
                option.HLRandWFViewsFileType = ImageFileType.PNG;
                option.ImageResolution       = ImageResolution.DPI_300;
                option.ShouldCreateWebSite   = false;
                option.SetViewsAndSheets(viewIds);
                option.ExportRange = ExportRange.SetOfViews;

                if (ImageExportOptions.IsValidFileName(tempImageFile))
                {
                    recipientDoc.ExportImage(option);
                }

                fileNames = Directory.GetFiles(System.IO.Path.GetTempPath(), string.Format("{0}*.*", System.IO.Path.GetFileNameWithoutExtension(tempFileName))).ToList();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to export draftingView to image.\n" + ex.Message, "ExportDraftingView", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(fileNames);
        }
예제 #3
0
        private void updateImage()
        {
            try
            {
                SnapshotImg.Source = null;
                ImageExportOptions options = new ImageExportOptions();
                options.FilePath = snapshot;
                //   options.
                options.HLRandWFViewsFileType = ImageFileType.PNG;
                options.ShadowViewsFileType = ImageFileType.PNG;
                options.ExportRange = ExportRange.VisibleRegionOfCurrentView;
                options.ZoomType = ZoomFitType.FitToPage;
                options.ImageResolution = ImageResolution.DPI_72;
                options.PixelSize = 1000;
                doc.ExportImage(options);
                BitmapImage source = new BitmapImage();
                source.BeginInit();
                source.UriSource = new Uri(snapshot);
                source.CacheOption = BitmapCacheOption.OnLoad;
                source.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
                source.EndInit();
                SnapshotImg.Source = source;

                PathLabel.Content = "none";
            }
            catch (System.Exception ex1)
            {
                TaskDialog.Show("Error!", "exception: " + ex1);
            }

        }
예제 #4
0
    private void GetRevitSnapshot()
    {
      try
      {
        string tempImg = Path.Combine(Path.GetTempPath(), "BCFier", Path.GetTempFileName() + ".png");
        var options = new ImageExportOptions
        {
          FilePath = tempImg,
          HLRandWFViewsFileType = ImageFileType.PNG,
          ShadowViewsFileType = ImageFileType.PNG,
          ExportRange = ExportRange.VisibleRegionOfCurrentView,
          ZoomType = ZoomFitType.FitToPage,
          ImageResolution = ImageResolution.DPI_72,
          PixelSize = 1000
        };
        doc.ExportImage(options);

        AddViewControl.AddViewpoint(tempImg);
        File.Delete(tempImg);
      }
      catch (System.Exception ex1)
      {
        TaskDialog.Show("Error!", "exception: " + ex1);
      }
    }
예제 #5
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="exportData">Data class object</param>
 public ExportIMGOptionsForm(ExportDataWithViews exportData)
 {
     m_exportOptions = new ImageExportOptions();
     InitializeComponent();
     this.m_exportData = exportData;
     InitializeFormats();
 }
예제 #6
0
        private string SaveRevitSnapshot(Document doc, string path)
        {
            try
            {
                //string tempImg = Path.Combine(Path.GetTempPath(), "BCFier", Path.GetTempFileName() + ".png");
                string tempImg = path;
                var    options = new ImageExportOptions
                {
                    FilePath = tempImg,
                    HLRandWFViewsFileType = ImageFileType.PNG,
                    ShadowViewsFileType   = ImageFileType.PNG,
                    ExportRange           = ExportRange.VisibleRegionOfCurrentView,
                    ZoomType        = ZoomFitType.FitToPage,
                    ImageResolution = ImageResolution.DPI_72,
                    PixelSize       = 1000
                };
                doc.ExportImage(options);

                //File.Delete(tempImg);

                return(tempImg);
            }
            catch (System.Exception ex1)
            {
                TaskDialog.Show("Error!", "exception: " + ex1);
                return(null);
            }
        }
예제 #7
0
        public static void ExportView(Document doc, View view,
                                      string view_export_loc, string ext)
        {
            try
            {
                //var sb = new StringBuilder();
                //sb.AppendLine();
                //sb.AppendLine(view_export_loc +
                //    " cbMIN " + view.CropBox.Min.ToString() +
                //" cbMax " + view.CropBox.Min.ToString() +
                //" bbxMIN " + view.get_BoundingBox(view).Min.ToString() +
                //    " bbxMAX " + view.get_BoundingBox(view).Max.ToString());

                //File.AppendAllText("C:\\data\\misc.txt", sb.ToString() + "\n");

                IList <ElementId> ImageExportList = new List <ElementId>();
                ImageExportList.Clear();
                ImageExportList.Add(view.Id);
                var BilledeExportOptions_3D_PNG = new ImageExportOptions
                {
                    ZoomType              = ZoomFitType.FitToPage,
                    PixelSize             = 4098,
                    FilePath              = view_export_loc,
                    FitDirection          = FitDirectionType.Horizontal,
                    HLRandWFViewsFileType = ImageFileType.PNG,
                    ImageResolution       = ImageResolution.DPI_600,
                    ExportRange           = ExportRange.SetOfViews,
                };

                BilledeExportOptions_3D_PNG.SetViewsAndSheets(ImageExportList);
                doc.ExportImage(BilledeExportOptions_3D_PNG);
            }
            catch (Exception)  {  }
        }
예제 #8
0
        private void ExportImage()
        {
            using (var trans = new Transaction(ActiveDoc))
            {
                trans.Start("Export Image");
                try
                {
                    var imgFileName = Path.Combine(Path.GetTempPath(), "SmartBCF", Path.GetTempFileName() + ".png");
                    if (File.Exists(imgFileName))
                    {
                        File.Delete(imgFileName);
                    }

                    var options = new ImageExportOptions
                    {
                        FilePath = imgFileName,
                        HLRandWFViewsFileType = ImageFileType.PNG,
                        ShadowViewsFileType   = ImageFileType.PNG,
                        ExportRange           = ExportRange.VisibleRegionOfCurrentView,
                        ZoomType        = ZoomFitType.FitToPage,
                        ImageResolution = ImageResolution.DPI_72,
                        PixelSize       = 1000
                    };

                    ActiveDoc.ExportImage(options);
                    trans.Commit();

                    SetViewPoint(imgFileName);
                }
                catch (Exception)
                {
                    trans.RollBack();
                }
            }
        }
예제 #9
0
        private void GetRevitSnapshot()
        {
            try
            {
                string tempImg = Path.Combine(Path.GetTempPath(), "BCFier", Path.GetTempFileName() + ".png");
                var    options = new ImageExportOptions
                {
                    FilePath = tempImg,
                    HLRandWFViewsFileType = ImageFileType.PNG,
                    ShadowViewsFileType   = ImageFileType.PNG,
                    ExportRange           = ExportRange.VisibleRegionOfCurrentView,
                    ZoomType        = ZoomFitType.FitToPage,
                    ImageResolution = ImageResolution.DPI_72,
                    PixelSize       = 1000
                };
                doc.ExportImage(options);

                AddViewControl.AddViewpoint(tempImg);
                File.Delete(tempImg);
            }
            catch (System.Exception ex1)
            {
                TaskDialog.Show("Error!", "exception: " + ex1);
            }
        }
예제 #10
0
        private void updateImage()
        {
            try
            {
                SnapshotImg.Source = null;
                ImageExportOptions options = new ImageExportOptions();
                options.FilePath = snapshot;
                //   options.
                options.HLRandWFViewsFileType = ImageFileType.PNG;
                options.ShadowViewsFileType   = ImageFileType.PNG;
                options.ExportRange           = ExportRange.VisibleRegionOfCurrentView;
                options.ZoomType        = ZoomFitType.FitToPage;
                options.ImageResolution = ImageResolution.DPI_72;
                options.PixelSize       = 1000;
                doc.ExportImage(options);
                BitmapImage source = new BitmapImage();
                source.BeginInit();
                source.UriSource     = new Uri(snapshot);
                source.CacheOption   = BitmapCacheOption.OnLoad;
                source.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
                source.EndInit();
                SnapshotImg.Source = source;

                PathLabel.Content = "";
            }
            catch (System.Exception ex1)
            {
                TaskDialog.Show("Error!", "exception: " + ex1);
            }
        }
예제 #11
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            View   view = (View)((Value.Container)args[0]).Item;
            string path = ((Value.String)args[1]).Item;

            string name     = view.ViewName;
            string pathName = path + "\\" + name;

            System.Drawing.Image image;


            ImageExportOptions options = new ImageExportOptions();

            options.ExportRange           = ExportRange.VisibleRegionOfCurrentView;
            options.FilePath              = pathName;
            options.HLRandWFViewsFileType = ImageFileType.PNG; //hack - make sure to change the read image below if other file types are supported
            options.ImageResolution       = ImageResolution.DPI_72;
            options.ZoomType              = ZoomFitType.Zoom;
            options.ShadowViewsFileType   = ImageFileType.PNG;


            try
            {
                dynRevitSettings.Doc.Document.ExportImage(options); //revit only has a method to save image to disk.
                //hack - make sure to change the read image below if other file types are supported
                image = Image.FromFile(pathName + ".png");          //read the saved image so we can pass it downstream
            }
            catch (Exception e)
            {
                DynamoLogger.Instance.Log(e);
                return(Value.NewContainer(0));
            }

            return(Value.NewContainer(image));
        }
예제 #12
0
        public override Value Evaluate(FSharpList <Value> args)
        {
            var    view     = (View)((Value.Container)args[0]).Item;
            string pathName = ((Value.String)args[1]).Item;

            //string name = view.ViewName;
            //string pathName = path; +"\\" + name;

            var options = new ImageExportOptions
            {
                ExportRange           = ExportRange.SetOfViews,
                FilePath              = pathName,
                HLRandWFViewsFileType = ImageFileType.PNG,
                ImageResolution       = ImageResolution.DPI_72,
                ZoomType              = ZoomFitType.Zoom,
                ShadowViewsFileType   = ImageFileType.PNG
            };

            options.SetViewsAndSheets(new List <ElementId> {
                view.Id
            });

            dynRevitSettings.Doc.Document.ExportImage(options);//revit only has a method to save image to disk.
            //hack - make sure to change the read image below if other file types are supported
            Image image = Image.FromFile(pathName + ".png");

            return(Value.NewContainer(image));
        }
예제 #13
0
    void GenerateThumbnailCore(Item item)
    {
        IPrintable component = DocumentService.CreatePrintableComponent(item);

        if (component == null)
        {
            return;
        }

        PrintableComponentLinkBase pcl = new PrintableComponentLinkBase(new PrintingSystemBase());

        pcl.Component = component;
        pcl.CreateDocument();
        ImageExportOptions imgOptions = new ImageExportOptions();

        imgOptions.ExportMode      = ImageExportMode.SingleFilePageByPage;
        imgOptions.Format          = System.Drawing.Imaging.ImageFormat.Png;
        imgOptions.PageRange       = "1";
        imgOptions.PageBorderWidth = 0;
        MemoryStream stream = new MemoryStream();

        pcl.ExportToImage(stream, imgOptions);

        stream.Position = 0;
        string thumbPath = GetThumbnailPath(item);

        GenerateThumbnailInternal(stream, thumbPath, ThumbnailWidth, ThumbnailHeight);

        IDisposable disposableComponent = component as IDisposable;

        if (disposableComponent != null)
        {
            disposableComponent.Dispose();
        }
    }
예제 #14
0
        public static View SaveToProject(ImageExportOptions options)
        {
            var o    = options.InternalImageExportOptions;
            var view = new ImageViews(o);

            return(view);
        }
예제 #15
0
        /// <summary>
        /// Animate the transparency of an element. This will export images of the element, then revert the element back to where it was.
        /// Inspired by the Bad Monkeys team.
        /// </summary>
        /// <param name="element">The element to set transparency to.</param>
        /// <param name="startPercentage">The transparency start percent.</param>
        /// <param name="endPercentage">The transparency end percent.</param>
        /// <param name="iterations">Numnber of images.</param>
        /// <param name="directoryPath">Where to save the images.</param>
        /// <param name="view">View to export from.</param>
        /// <returns name="element">The element.</returns>
        /// <search>
        ///  rhythm
        /// </search>
        public static object AnimateTransparency(List <global::Revit.Elements.Element> element, int startPercentage, int endPercentage, int iterations, string directoryPath, global::Revit.Elements.Element view)
        {
            Autodesk.Revit.DB.Document doc = DocumentManager.Instance.CurrentDBDocument;
            UIDocument uiDocument          = new UIDocument(doc);

            Autodesk.Revit.DB.View internalView = (Autodesk.Revit.DB.View)view.InternalElement;
            //create a new form!
            DefaultProgressForm statusBar = new DefaultProgressForm("Exporting Images", "Exporting image {0} of " + iterations.ToString(), "Animate Element Transparency", iterations + 1);
            double d           = (endPercentage - startPercentage) / (iterations - 1.0);
            int    incrementor = Convert.ToInt32(d);


            //starts a transaction group so we can roolback the changes after
            using (TransactionGroup transactionGroup = new TransactionGroup(doc, "group"))
            {
                TransactionManager.Instance.ForceCloseTransaction();
                transactionGroup.Start();
                using (Transaction t2 = new Transaction(doc, "Modify parameter"))
                {
                    int num2 = 0;
                    while (startPercentage <= endPercentage)
                    {
                        statusBar.Activate();
                        t2.Start();
                        //declare the graphic settings overrides
                        OverrideGraphicSettings ogs = new OverrideGraphicSettings();
                        //solid fill id
                        ElementId pattId = new ElementId(20);
                        //set the overrides to the graphic settings
                        ogs.SetSurfaceTransparency(startPercentage);
                        foreach (var e in element)
                        {
                            //apply the changes to view
                            internalView.SetElementOverrides(e.InternalElement.Id, ogs);
                        }
                        t2.Commit();

                        uiDocument.RefreshActiveView();
                        var exportOpts = new ImageExportOptions
                        {
                            FilePath              = directoryPath + num2.ToString(),
                            FitDirection          = FitDirectionType.Horizontal,
                            HLRandWFViewsFileType = ImageFileType.PNG,
                            ImageResolution       = ImageResolution.DPI_300,
                            ShouldCreateWebSite   = false
                        };
                        doc.ExportImage(exportOpts);
                        ++num2;
                        startPercentage = startPercentage + incrementor;
                        statusBar.Increment();
                    }
                }
                transactionGroup.RollBack();
            }
            statusBar.Close();

            return(element);
        }
        //
        public string GetImageFromView(UIDocument uidoc, Autodesk.Revit.DB.View view, bool isReload)
        {
            if (!isReload)
            {
                Selection choices = uidoc.Selection;
                try
                {
                    Reference hasPickOne = choices.PickObject(ObjectType.Element);
                    Import.selElement = uidoc.Document.GetElement(hasPickOne.ElementId);
                }
                catch (Exception)
                {
                    MessageBox.Show("Необходимо выбрать графический вид!!!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    return "";
                }

            }
            IList<ElementId> ImageExportList = new List<ElementId>();
            ImageExportList.Add(view.Id);
            var BilledeExportOptions = new ImageExportOptions
            {
                PixelSize = 512,
                ExportRange = ExportRange.SetOfViews,
                HLRandWFViewsFileType = ImageFileType.PNG,
                ImageResolution = ImageResolution.DPI_300,
                ZoomType = ZoomFitType.Zoom,
                ShadowViewsFileType = ImageFileType.PNG

            };

            BilledeExportOptions.ViewName = "";

            BilledeExportOptions.FilePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\Temp\" + view.Id.IntegerValue.ToString() + ".png";
            BilledeExportOptions.SetViewsAndSheets(ImageExportList);
            try
            {
                uidoc.Document.ExportImage(BilledeExportOptions);
            }
            catch { return ""; }
            DirectoryInfo imagesDir = new DirectoryInfo(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\Temp\");
            string nameFile = "";

            nameFile = RenameFile(view, imagesDir, nameFile);
            //Image im = Image.FromFile(nameFile);
            //im = resizeImage(im, new Size(256, 256));
            //string newName = Path.GetFileNameWithoutExtension(nameFile);
            //newName += "f.png";
            //im.Save(newName);
            //using (var image = Image.FromFile(nameFile))
            //using (var newImage = ScaleImage(image, 300, 400))
            //{
            //    newImage.Save(@"c:\test.png", ImageFormat.Png);
            //}

            return nameFile;
        }
예제 #17
0
        public static byte[] ThumbnailFromView(Autodesk.Revit.DB.Document doc, string viewName)
        {
            string   guid = Guid.NewGuid().ToString();
            FileInfo info = new FileInfo(Environment.CurrentDirectory + "\\" + guid + ".png");

            if (doc != null)
            {
                byte[] returnbytes             = null;
                FilteredElementCollector views = new FilteredElementCollector(doc).OfClass(typeof(View));
                foreach (View view in views)
                {
                    if (view.IsTemplate)
                    {
                        continue;
                    }
                    IList <ElementId> ImageExportList = new List <ElementId>();
                    if (view.Name == viewName)
                    {
                        ImageExportList.Clear();
                        ImageExportList.Add(view.Id);

                        var BilledeExportOptions_3D_PNG = new ImageExportOptions
                        {
                            ZoomType              = ZoomFitType.FitToPage,
                            PixelSize             = 1024,
                            FilePath              = info.FullName,
                            FitDirection          = FitDirectionType.Horizontal,
                            HLRandWFViewsFileType = ImageFileType.JPEGLossless,
                            ShadowViewsFileType   = ImageFileType.JPEGLossless,
                            ImageResolution       = ImageResolution.DPI_600,
                            ExportRange           = ExportRange.SetOfViews
                        };
                        BilledeExportOptions_3D_PNG.SetViewsAndSheets(ImageExportList);
                        doc.ExportImage(BilledeExportOptions_3D_PNG);

                        DirectoryInfo dinfo = new DirectoryInfo(info.DirectoryName);
                        foreach (FileInfo file in dinfo.GetFiles())
                        {
                            if (file.Name.Contains(guid))
                            {
                                returnbytes = FileToByteArray(file.FullName);
                                File.Delete(file.FullName);
                                break;
                            }
                        }
                        break;
                    }
                }
                return(returnbytes);
            }
            return
                (new byte[0]);
        }
        public void ConvertWithOptionsFromStorage()
        {
            ExportFormat format = ExportFormat.Png;

            TestUtils.Upload(c_fileName, c_folderName + "/" + c_fileName);
            Stream        converted = TestUtils.SlidesApi.DownloadPresentation(c_fileName, format, password: c_password, folder: c_folderName);
            ExportOptions options   = new ImageExportOptions {
                Width = 480, Height = 360
            };
            Stream convertedWithOptions = TestUtils.SlidesApi.DownloadPresentation(c_fileName, format, options, c_password, c_folderName);

            Assert.Greater(converted.Length, convertedWithOptions.Length);
        }
예제 #19
0
        private void buttonRefresh_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //export image
                ImageExportOptions option = new ImageExportOptions();
                option.HLRandWFViewsFileType = ImageFileType.PNG;
                option.ImageResolution       = ImageResolution.DPI_300;
                option.ShouldCreateWebSite   = false;
                option.ExportRange           = ExportRange.SetOfViews;

                List <ElementId> viewIds = new List <ElementId>();
                int        index         = pageNum - 1;
                PreviewMap preview       = previewMapList[index];
                if (null != preview.RecipientViewProperties)
                {
                    if (preview.RecipientViewProperties.ViewId > 0)
                    {
                        string tempFileName  = System.IO.Path.ChangeExtension(System.IO.Path.GetRandomFileName(), "png");
                        string tempImageFile = System.IO.Path.Combine(tempFolder, tempFileName);

                        viewIds.Add(new ElementId(preview.RecipientViewProperties.ViewId));
                        option.FilePath = tempImageFile;
                        option.SetViewsAndSheets(viewIds);
                        if (ImageExportOptions.IsValidFileName(tempImageFile))
                        {
                            string imageFileName = ExportDraftingView(preview.RecipientModelInfo.Doc, option);
                            if (!string.IsNullOrEmpty(preview.ViewLinkInfo.DestImagePath1))
                            {
                                if (File.Exists(preview.ViewLinkInfo.DestImagePath1))
                                {
                                    File.Delete(preview.ViewLinkInfo.DestImagePath1);
                                }
                            }
                            if (!string.IsNullOrEmpty(preview.ViewLinkInfo.DestImagePath2))
                            {
                                preview.ViewLinkInfo.DestImagePath1 = preview.ViewLinkInfo.DestImagePath2;
                            }
                            preview.ViewLinkInfo.DestImagePath2 = imageFileName;
                            imageRecipient.Source = new BitmapImage(new Uri(preview.ViewLinkInfo.DestImagePath2));
                        }
                    }
                    previewMapList.RemoveAt(index);
                    previewMapList.Insert(index, preview);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to refresh the preview image.\n" + ex.Message, "Refresh Preview Image", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
예제 #20
0
파일: View.cs 프로젝트: whztt07/Dynamo
        /// <summary>
        /// Export the view as an image to the given path - defaults to png, but you can override
        /// the file type but supplying a path with the appropriate extension
        /// </summary>
        /// <param name="fullPath">A valid path for the image</param>
        /// <returns>The image</returns>
        public Bitmap ExportAsImage(string fullPath)
        {
            var fileType = ImageFileType.PNG;

            if (Path.HasExtension(fullPath))
            {
                string extension = Path.GetExtension(fullPath) ?? ".png";
                switch (extension.ToLower())
                {
                case ".jpg":
                    fileType = ImageFileType.JPEGLossless;
                    break;

                case ".png":
                    fileType = ImageFileType.PNG;
                    break;

                case ".bmp":
                    fileType = ImageFileType.BMP;
                    break;

                case ".tga":
                    fileType = ImageFileType.TARGA;
                    break;

                case ".tif":
                    fileType = ImageFileType.TIFF;
                    break;
                }
            }

            var options = new ImageExportOptions
            {
                ExportRange           = ExportRange.VisibleRegionOfCurrentView,
                FilePath              = fullPath,
                FitDirection          = FitDirectionType.Horizontal,
                HLRandWFViewsFileType = fileType,
                ImageResolution       = ImageResolution.DPI_150,
                ShadowViewsFileType   = fileType,
                ShouldCreateWebSite   = false,
                ViewName              = Guid.NewGuid().ToString(),
                Zoom     = 100,
                ZoomType = ZoomFitType.Zoom
            };

            Document.ExportImage(options);

            using (var fs = new FileStream(fullPath, FileMode.Open))
                return(new Bitmap(Image.FromStream(fs)));
        }
예제 #21
0
        public void Export_Images(UIApplication uiapp, UIDocument uidoc, Document doc)
        {
            try
            {
                string name           = doc_link.PathName.Split('\\').Last().Split('.')[0];
                string path_directory = Path.GetDirectoryName(doc_link.PathName) + "\\" + "Images";

                if (!Directory.Exists(path_directory))
                {
                    Directory.CreateDirectory(path_directory);
                }

                foreach (Element_Change item in my_element_change)
                {
                    var ieo = new ImageExportOptions
                    {
                        PixelSize             = 1920,
                        FilePath              = path_directory + "\\" + item.element_id,
                        FitDirection          = FitDirectionType.Horizontal,
                        HLRandWFViewsFileType = ImageFileType.PNG,
                        ImageResolution       = ImageResolution.DPI_600,
                        ExportRange           = ExportRange.VisibleRegionOfCurrentView,
                    };

                    try
                    {
                        Transaction transaction1 = new Transaction(doc);
                        transaction1.Start("BoundingBox");
                        Focus(uiapp, doc, item);
                        transaction1.Commit();

                        Thread.Sleep(2);

                        Transaction transaction2 = new Transaction(doc);
                        transaction2.Start("BoundingBox");
                        doc.ExportImage(ieo);
                        transaction2.Commit();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 private void barButtonItem1_ItemClick(object sender, DevExpress.Xpf.Bars.ItemClickEventArgs e)
 {
     this.Cursor = System.Windows.Input.Cursors.Wait;
     #region #saveasimage
     PrintableComponentLinkBase pcl = new PrintableComponentLinkBase(new PrintingSystemBase());
     pcl.Component = ((IRichEditControl)richEditControl1).InnerControl;
     pcl.CreateDocument(false);
     ImageExportOptions imgOptions = new ImageExportOptions();
     imgOptions.ExportMode = ImageExportMode.DifferentFiles;
     imgOptions.Format     = System.Drawing.Imaging.ImageFormat.Png;
     imgOptions.Resolution = 150;
     imgOptions.PageRange  = "1,3-5";
     pcl.ExportToImage("export.png", imgOptions);
     #endregion #saveasimage
     this.Cursor = System.Windows.Input.Cursors.Arrow;
 }
예제 #23
0
파일: View.cs 프로젝트: whztt07/Dynamo
        /// <summary>
        /// Export the view as an image to the given path - defaults to png, but you can override 
        /// the file type but supplying a path with the appropriate extension
        /// </summary>
        /// <param name="fullPath">A valid path for the image</param>
        /// <returns>The image</returns>
        public Bitmap ExportAsImage(string fullPath)
        {
            var fileType = ImageFileType.PNG;
            if (Path.HasExtension(fullPath))
            {
                string extension = Path.GetExtension(fullPath) ?? ".png";
                switch (extension.ToLower())
                {
                    case ".jpg":
                        fileType = ImageFileType.JPEGLossless;
                        break;
                    case ".png":
                        fileType = ImageFileType.PNG;
                        break;
                    case ".bmp":
                        fileType = ImageFileType.BMP;
                        break;
                    case ".tga":
                        fileType = ImageFileType.TARGA;
                        break;
                    case ".tif":
                        fileType = ImageFileType.TIFF;
                        break;
                }
            }
            
            var options = new ImageExportOptions
            {
                ExportRange = ExportRange.VisibleRegionOfCurrentView,
                FilePath = fullPath,
                FitDirection = FitDirectionType.Horizontal,
                HLRandWFViewsFileType = fileType,
                ImageResolution = ImageResolution.DPI_150,
                ShadowViewsFileType = fileType,
                ShouldCreateWebSite = false,
                ViewName = Guid.NewGuid().ToString(),
                Zoom = 100,
                ZoomType = ZoomFitType.Zoom
            };

            Document.ExportImage(options);

            using (var fs = new FileStream(fullPath, FileMode.Open))
                return new Bitmap(Image.FromStream(fs));
        }
예제 #24
0
    MemoryStream InitializeThumbnail(IBasePrintable component)
    {
        PrintableComponentLinkBase pcl = new PrintableComponentLinkBase(new PrintingSystemBase());

        pcl.Component = component;
        pcl.CreateDocument();
        ImageExportOptions imgOptions = new ImageExportOptions();

        imgOptions.ExportMode      = ImageExportMode.SingleFilePageByPage;
        imgOptions.Format          = System.Drawing.Imaging.ImageFormat.Png;
        imgOptions.PageRange       = "1";
        imgOptions.PageBorderWidth = 0;
        MemoryStream stream = new MemoryStream();

        pcl.ExportToImage(stream, imgOptions);
        stream.Position = 0;
        return(stream);
    }
예제 #25
0
        public override Tuple <string, string> getSnapshotAndViewpoint(int elemCheck)
        {
            if (!(uidoc.ActiveView is View3D || uidoc.ActiveView is ViewSheet || uidoc.ActiveView is ViewPlan || uidoc.ActiveView is ViewSection || uidoc.ActiveView is ViewDrafting))
            {
                MessageBox.Show("I'm sorry,\nonly 3D and 2D views are supported.", "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                return(null);
            }

            string tempPath    = Path.Combine(Path.GetTempPath(), "BCFtemp", Path.GetRandomFileName());
            string issueFolder = Path.Combine(tempPath, Guid.NewGuid().ToString());

            if (!Directory.Exists(issueFolder))
            {
                Directory.CreateDirectory(issueFolder);
            }

            Guid   viewpointGuid     = Guid.NewGuid();
            string snapshotFilePath  = Path.Combine(issueFolder, string.Format("{0}.png", viewpointGuid.ToString()));
            string viewpointFilePath = Path.Combine(issueFolder, string.Format("{0}.bcfv", viewpointGuid.ToString()));

            // save snapshot
            ImageExportOptions options = new ImageExportOptions();

            options.FilePath = snapshotFilePath;
            options.HLRandWFViewsFileType = ImageFileType.PNG;
            options.ShadowViewsFileType   = ImageFileType.PNG;
            options.ExportRange           = ExportRange.VisibleRegionOfCurrentView;
            options.ZoomType        = ZoomFitType.FitToPage;
            options.ImageResolution = ImageResolution.DPI_72;
            options.PixelSize       = 1000;
            doc.ExportImage(options);

            // save viewpoint
            VisualizationInfo vi          = window.generateViewpoint(elemCheck);
            XmlSerializer     serializerV = new XmlSerializer(typeof(VisualizationInfo));
            Stream            writerV     = new FileStream(viewpointFilePath, FileMode.Create);

            serializerV.Serialize(writerV, vi);
            writerV.Close();

            return(new Tuple <string, string>(snapshotFilePath, viewpointFilePath));
        }
예제 #26
0
        public TradelaneFile ShipmentBagLabel(int BagId, int userId)
        {
            TradelaneFile result = new TradelaneFile();

            List <ExpressReportBagLabel> model = new ExpressReportRepository().GetBagLabelReportObj(BagId, userId);

            // List<TradelaneBookingReportMAWB> model = new TradelaneReportsRepository().GetMAWBObj(tradelaneShipmentId);
            ReportTemplate.Express.EXSBagLabel report = new ReportTemplate.Express.EXSBagLabel();
            report.DataSource = model;
            ImageExportOptions options = new ImageExportOptions();

            options.Resolution = 150;
            string fileName = "EXS-BGL-" + model[0].Hub + "-" + model[0].Ref + ".jpeg";
            //int tradelaneShipmentId = model[0].TradelaneShipmentId;

            string filePath         = AppSettings.WebApiPath + "/UploadFiles/ExpressBag/" + BagId + "/" + fileName;
            string filePhysicalPath = HttpContext.Current.Server.MapPath("~/UploadFiles/ExpressBag/" + BagId + "/" + fileName);

            if (!System.IO.Directory.Exists(HttpContext.Current.Server.MapPath("~/UploadFiles/ExpressBag/" + BagId + "/")))
            {
                System.IO.Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/UploadFiles/ExpressBag/" + BagId + "/"));
            }

            if (File.Exists(filePhysicalPath))
            {
                File.Delete(filePhysicalPath);
            }
            report.ExportToImage(filePhysicalPath, options);

            string resultPath = @"" + filePhysicalPath + "";

            using (System.Drawing.Image img = System.Drawing.Image.FromFile(resultPath))
            {
                img.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
                resultPath = @"" + filePhysicalPath + "";
                img.Save(resultPath, System.Drawing.Imaging.ImageFormat.Jpeg);
            }

            result.FileName = fileName;
            result.FilePath = filePath;
            return(result);
        }
예제 #27
0
        private void button1_Click(object sender, EventArgs e)
        {
            // A path to export a report.
            string reportPath = "c:\\Test.png";

            // Create a report instance.
            XtraReport1 report = new XtraReport1();

            // Get its Image export options.
            ImageExportOptions imageOptions = report.ExportOptions.Image;

            // Set Image-specific export options.
            imageOptions.Format = ImageFormat.Png;

            // Export the report to Image.
            report.ExportToImage(reportPath);

            // Show the result.
            StartProcess(reportPath);
        }
예제 #28
0
        private void generateThumbnails()
        {
            var doc = commandData.Application.ActiveUIDocument.Document;
            var ieo = new ImageExportOptions();

            foreach (var sheet in SheetInfo)
            {
                ieo.ExportRange = ExportRange.SetOfViews;
                ieo.SetViewsAndSheets(new List <ElementId> {
                    sheet.ElementID
                });
                ieo.HLRandWFViewsFileType = ImageFileType.PNG;
                string tempFilePath = Path.GetTempFileName();
                ieo.FilePath = tempFilePath;
                doc.ExportImage(ieo);
                var    files     = Directory.GetFiles(Path.GetTempPath(), string.Format("{0}*.*", Path.GetFileNameWithoutExtension(tempFilePath)));
                string imagePath = files[0] ?? "";
                sheet.ImagePath = imagePath;
            }
        }
예제 #29
0
        private static Bitmap ExportToImage(IBasePrintable component)
        {
            PrintableComponentLinkBase pLink = new PrintableComponentLinkBase(new PrintingSystemBase());

            pLink.Component = component;
            pLink.CreateDocument(true);

            MemoryStream       mStream = new MemoryStream();
            ImageExportOptions options = new ImageExportOptions();

            options.ExportMode = ImageExportMode.SingleFilePageByPage;
            options.PageRange  = "1";
            pLink.ExportToImage(mStream, options);
            mStream.Position = 0;
            Bitmap bm = new Bitmap(mStream);

            mStream.Close();

            return(bm);
        }
예제 #30
0
        private string ExportDraftingView(Document recipientDoc, ImageExportOptions option)
        {
            string fileName = "";

            try
            {
                recipientDoc.ExportImage(option);

                string[] fileNames = Directory.GetFiles(tempFolder, string.Format("{0}*.*", System.IO.Path.GetFileNameWithoutExtension(option.FilePath)));
                if (fileNames.Length > 0)
                {
                    fileName = fileNames[0];
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to export draftingView to image.\n" + ex.Message, "ExportDraftingView", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(fileName);
        }
예제 #31
0
        public TradelaneFile ShipmentCartonLabel(int tradelaneShipmentId, int CartonCount, int TradelaneShipmentDetailId, string Hawb)
        {
            TradelaneFile result = new TradelaneFile();

            var model = new TradelaneReportsRepository().GetCartonLabelObj(tradelaneShipmentId, Hawb);

            ReportTemplate.Tradelane.PackageLabel shipmentDetailReport = new Report.Generator.ReportTemplate.Tradelane.PackageLabel();
            model.FirstOrDefault().ScannedPieces = int.Parse(model.FirstOrDefault().TotalPieces);
            model.FirstOrDefault().TotalPieces   = model.FirstOrDefault().HawbScannedCarton + "/" + model.FirstOrDefault().HAWBTotalPieces;
            shipmentDetailReport.DataSource = model;
            ImageExportOptions options = new ImageExportOptions();

            options.Resolution = 150;
            var    Name             = new TradelaneBookingRepository().GetLastScannedCarton(tradelaneShipmentId);
            string fileName         = Name + ".jpeg";
            string filePath         = AppSettings.WebApiPath + "/UploadFiles/Tradelane/" + tradelaneShipmentId + "/" + fileName;
            string filePhysicalPath = HttpContext.Current.Server.MapPath("~/UploadFiles/Tradelane/" + tradelaneShipmentId + "/" + fileName);

            if (!System.IO.Directory.Exists(HttpContext.Current.Server.MapPath("~/UploadFiles/Tradelane/" + tradelaneShipmentId + "/")))
            {
                System.IO.Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/UploadFiles/Tradelane/" + tradelaneShipmentId + "/"));
            }
            if (File.Exists(filePhysicalPath))
            {
                File.Delete(filePhysicalPath);
            }

            shipmentDetailReport.ExportToImage(filePhysicalPath, options);

            string resultPath = @"" + filePhysicalPath + "";

            using (System.Drawing.Image img = System.Drawing.Image.FromFile(resultPath))
            {
                img.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
                resultPath = @"" + filePhysicalPath + "";
                img.Save(resultPath, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            result.FileName = fileName;
            result.FilePath = filePath;
            return(result);
        }
        byte[] ExportToPowerPoint(PrintingSystemBase printingSystem, string documentId)
        {
            // To the temp folder (for demo purposes)
            var tempFolder = System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/PowerPoint/");

            if (!Directory.Exists(tempFolder))
            {
                Directory.CreateDirectory(tempFolder);
            }
            // image export options
            ImageExportOptions exportOptions = new ImageExportOptions {
                ExportMode      = ImageExportMode.SingleFilePageByPage,
                Format          = ImageFormat.Png,
                PageBorderColor = Color.White,
                Resolution      = 600
            };
            // PowerPoint Presentation
            Size         size = CalculateSize(printingSystem);
            Presentation p    = new Presentation(size);

            // go through each page
            for (int i = 0; i < printingSystem.Pages.Count; i++)
            {
                // export image
                var file = string.Format(@"{0}\{1}_{2}.png", tempFolder, documentId, i);
                exportOptions.PageRange = (i + 1).ToString();
                printingSystem.ExportToImage(file, exportOptions);
                // add the image to the presentation
                p.AddPage(file);
                // clean up!
                File.Delete(file);
            }
            // save presentation
            string resultFile = string.Format(@"{0}\{1}.ppt", tempFolder, documentId);

            p.SaveAs(resultFile);
            byte[] document = File.ReadAllBytes(resultFile);
            File.Delete(resultFile);
            return(document);
        }
예제 #33
0
        /// <summary>
        /// New code as described in Revit API discussion
        /// forum thread on how to export an image from a
        /// specific view using Revit API C#,
        /// http://forums.autodesk.com/t5/revit-api/how-to-export-an-image-from-a-specific-view-using-revit-api-c/m-p/6424418
        /// </summary>
        static Result ExportToImage3(Document doc)
        {
            Result r = Result.Failed;

            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Export Image");

                string desktop_path = Environment.GetFolderPath(
                    Environment.SpecialFolder.Desktop);

                View view = doc.ActiveView;

                string filepath = Path.Combine(desktop_path,
                                               view.Name);

                ImageExportOptions img = new ImageExportOptions();

                img.ZoomType              = ZoomFitType.FitToPage;
                img.PixelSize             = 32;
                img.ImageResolution       = ImageResolution.DPI_600;
                img.FitDirection          = FitDirectionType.Horizontal;
                img.ExportRange           = ExportRange.CurrentView;
                img.HLRandWFViewsFileType = ImageFileType.PNG;
                img.FilePath              = filepath;
                img.ShadowViewsFileType   = ImageFileType.PNG;

                doc.ExportImage(img);

                tx.RollBack();

                filepath = Path.ChangeExtension(
                    filepath, "png");

                Process.Start(filepath);

                r = Result.Succeeded;
            }
            return(r);
        }
예제 #34
0
        public BatchPrintViewModel(ExternalCommandData commandData)
        {
            this.commandData = commandData;

            var                      doc      = commandData.Application.ActiveUIDocument.Document;
            List <Element>           mySheets = new List <Element>();
            FilteredElementCollector sheets   = new FilteredElementCollector(doc);

            mySheets.AddRange(sheets.OfClass(typeof(ViewSheet)).ToElements());
            string output = "Sheets printed: " + Environment.NewLine;

            SheetInfo = new ObservableCollection <sheetVM>();
            var ieo = new ImageExportOptions();


            foreach (var sheet in mySheets)
            {
                string sheetName          = sheet.get_Parameter(BuiltInParameter.SHEET_NAME).AsString();
                string sheetNumber        = sheet.get_Parameter(BuiltInParameter.SHEET_NUMBER).AsString();
                string currentRev         = sheet.get_Parameter(BuiltInParameter.SHEET_CURRENT_REVISION).AsString();
                string currentRevDate     = sheet.get_Parameter(BuiltInParameter.SHEET_CURRENT_REVISION_DATE).AsString();
                string currentRevDescript = sheet.get_Parameter(BuiltInParameter.SHEET_CURRENT_REVISION_DESCRIPTION).AsString();

                SheetInfo.Add(
                    new sheetVM(this)
                {
                    Name        = sheetName,
                    Number      = sheetNumber,
                    Rev         = currentRev,
                    RevDate     = currentRevDate,
                    RevDescript = currentRevDescript,
                    Sheet       = sheet as ViewSheet,
                    IncludeName = false,
                    IncludeRev  = false,
                    ElementID   = sheet.Id,
                });
            }
        }
        private void exportFileImage(XtraReport report)
        {
            ImageExportOptions imageOptions = report.ExportOptions.Image;

            imageOptions.Format = ImageFormat.Png;
            string         reportPath = "";
            SaveFileDialog sf         = new SaveFileDialog();

            sf.FileName = "Save Here.png";
            if (sf.ShowDialog() == DialogResult.OK)
            {
                reportPath = Path.GetDirectoryName(sf.FileName) + sf.FileName;
                try
                {
                    report.ExportToImage(sf.FileName);
                    MessageBox.Show("Lưu thành công!");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
예제 #36
0
        public Result Execute(ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            try
            {
                UIApplication uiApp = commandData.Application;
                UIDocument uiDoc = uiApp.ActiveUIDocument;
                Document doc = uiDoc.Document;

                SaveFileDialog saveFileDialog = new SaveFileDialog();
                saveFileDialog.Title = "Save view as file";
                saveFileDialog.Filter = "Png files (*.png)|*.png";

                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    ImageExportOptions imageExportOptions = new ImageExportOptions();
                    imageExportOptions.ExportRange = ExportRange.VisibleRegionOfCurrentView;
                    imageExportOptions.FilePath = saveFileDialog.FileName;
                    imageExportOptions.HLRandWFViewsFileType = ImageFileType.PNG;
                    imageExportOptions.ImageResolution = ImageResolution.DPI_72;
                    imageExportOptions.ShadowViewsFileType = ImageFileType.PNG;
                    imageExportOptions.ZoomType = ZoomFitType.Zoom;
                    imageExportOptions.Zoom = 100;

                    doc.ExportImage(imageExportOptions);
                }
            }
            catch (Exception e)
            {
                TaskDialog.Show("Revit Quick Tools", e.Message);
                return Result.Failed;
            }

            return Result.Succeeded;
        }
    static string ExportToImage( Document doc )
    {
      var tempFileName = Path.ChangeExtension(
        Path.GetRandomFileName(), "png" );

      string tempImageFile;

      try
      {
        tempImageFile = Path.Combine(
          Path.GetTempPath(), tempFileName );
      }
      catch( IOException )
      {
        return null;
      }

      IList<ElementId> views = new List<ElementId>();

      try
      {

#if !VERSION2014
    var direction = new XYZ(-1, 1, -1);
    var view3D = doc.IsFamilyDocument
      ? doc.FamilyCreate.NewView3D(direction)
      : doc.Create.NewView3D(direction);
#else
        var collector = new FilteredElementCollector(
          doc );

        var viewFamilyType = collector
          .OfClass( typeof( ViewFamilyType ) )
          .OfType<ViewFamilyType>()
          .FirstOrDefault( x =>
            x.ViewFamily == ViewFamily.ThreeDimensional );

        var view3D = ( viewFamilyType != null )
        ? View3D.CreateIsometric( doc, viewFamilyType.Id )
        : null;

#endif // VERSION2014

        if( view3D != null )
        {
          // Ensure white background.

          Color white = new Color( 255, 255, 255 );

          view3D.SetBackground(
            ViewDisplayBackground.CreateGradient(
              white, white, white ) );

          views.Add( view3D.Id );

          var graphicDisplayOptions
            = view3D.get_Parameter(
              BuiltInParameter.MODEL_GRAPHICS_STYLE );

          // Settings for best quality

          graphicDisplayOptions.Set( 6 );
        }
      }
      catch( Autodesk.Revit.Exceptions
        .InvalidOperationException )
      {
      }

      var ieo = new ImageExportOptions
      {
        FilePath = tempImageFile,
        FitDirection = FitDirectionType.Horizontal,
        HLRandWFViewsFileType = ImageFileType.PNG,
        ImageResolution = ImageResolution.DPI_150,
        ShouldCreateWebSite = false
      };

      if( views.Count > 0 )
      {
        ieo.SetViewsAndSheets( views );
        ieo.ExportRange = ExportRange.SetOfViews;
      }
      else
      {
        ieo.ExportRange = ExportRange
          .VisibleRegionOfCurrentView;
      }

      ieo.ZoomType = ZoomFitType.FitToPage;
      ieo.ViewName = "tmp";

      if( ImageExportOptions.IsValidFileName(
        tempImageFile ) )
      {
        // If ExportRange = ExportRange.SetOfViews 
        // and document is not active, then image 
        // exports successfully, but throws
        // Autodesk.Revit.Exceptions.InternalException

        try
        {
          doc.ExportImage( ieo );
        }
        catch
        {
          return string.Empty;
        }
      }
      else
      {
        return string.Empty;
      }

      // File name has format like 
      // "tempFileName - view type - view name", e.g.
      // "luccwjkz - 3D View - {3D}.png".
      // Get the first image (we only listed one view
      // in views).

      var files = Directory.GetFiles(
        Path.GetTempPath(),
        string.Format( "{0}*.*", Path
          .GetFileNameWithoutExtension(
            tempFileName ) ) );

      return files.Length > 0
        ? files[0]
        : string.Empty;
    }
    /// <summary>
    /// New code as described in Revit API discussion 
    /// forum thread on how to export an image from a 
    /// specific view using Revit API C#,
    /// http://forums.autodesk.com/t5/revit-api/how-to-export-an-image-from-a-specific-view-using-revit-api-c/m-p/6424418
    /// </summary>
    static Result ExportToImage3( Document doc )
    {
      Result r = Result.Failed;

      using( Transaction tx = new Transaction( doc ) )
      {
        tx.Start( "Export Image" );

        string desktop_path = Environment.GetFolderPath( 
          Environment.SpecialFolder.Desktop );

        View view = doc.ActiveView;

        string filepath = Path.Combine( desktop_path, 
          view.Name );

        ImageExportOptions img = new ImageExportOptions();

        img.ZoomType = ZoomFitType.FitToPage;
        img.PixelSize = 32;
        img.ImageResolution = ImageResolution.DPI_600;
        img.FitDirection = FitDirectionType.Horizontal;
        img.ExportRange = ExportRange.CurrentView;
        img.HLRandWFViewsFileType = ImageFileType.PNG;
        img.FilePath = filepath;
        img.ShadowViewsFileType = ImageFileType.PNG;

        doc.ExportImage( img );

        tx.RollBack();

        filepath = Path.ChangeExtension( 
          filepath, "png" );

        Process.Start( filepath );

        r = Result.Succeeded;
      }
      return r;
    }
예제 #39
0
파일: View.cs 프로젝트: RobertiF/Dynamo
        /// <summary>
        /// Export the view as an image to the given path - defaults to png, but you can override 
        /// the file type but supplying a path with the appropriate extension
        /// </summary>
        /// <param name="fullPath">A valid path for the image</param>
        /// <returns>The image</returns>
        public System.Drawing.Image ExportAsImage(string fullPath)
        {
            string pathName = fullPath;
            string extension = null;

            var fileType = ImageFileType.PNG;
            if (Path.HasExtension(fullPath))
            {
                extension = Path.GetExtension(fullPath).ToLower();
                switch (extension)
                {
                    case ".jpg":
                        fileType = ImageFileType.JPEGLossless;
                        break;
                    case ".png":
                        fileType = ImageFileType.PNG;
                        break;
                    case ".bmp":
                        fileType = ImageFileType.BMP;
                        break;
                    case ".tga":
                        fileType = ImageFileType.TARGA;
                        break;
                    case ".tif":
                        fileType = ImageFileType.TIFF;
                        break;
                }
                pathName = Path.Combine(
                    Path.GetDirectoryName(fullPath),
                    Path.GetFileNameWithoutExtension(fullPath));
            }

            extension = (extension ?? ".png");

            var options = new ImageExportOptions
            {
                ExportRange = ExportRange.SetOfViews,
                FilePath = pathName,
                HLRandWFViewsFileType = fileType,
                ImageResolution = ImageResolution.DPI_72,
                ZoomType = ZoomFitType.Zoom,
                ShadowViewsFileType = fileType
            };

            options.SetViewsAndSheets(new List<ElementId> { InternalView.Id });

            Document.ExportImage(options);

            // Revit outputs file with a bunch of crap in the file name, let's construct that
            var actualFn = string.Format("{0} - {1} - {2}{3}", pathName, ViewTypeString(InternalView.ViewType),
                InternalView.ViewName, extension);

            // and the intended destination
            var destFn = pathName + extension;

            // rename the file
            if (File.Exists(destFn)) File.Delete(destFn);
            File.Move(actualFn, destFn);

            return Image.FromFile(destFn);
        }
예제 #40
0
        public override Value Evaluate(FSharpList<Value> args)
        {
            var view = (View)((Value.Container)args[0]).Item;

            var fullPath = ((Value.String)args[1]).Item;

            string pathName = fullPath;
            string extension = null;

            var fileType = ImageFileType.PNG;
            if (Path.HasExtension(fullPath))
            {
                extension = Path.GetExtension(fullPath).ToLower();
                switch (extension)
                {
                    case ".jpg":
                        fileType = ImageFileType.JPEGLossless;
                        break;
                    case ".png":
                        fileType = ImageFileType.PNG;
                        break;
                    case ".bmp":
                        fileType = ImageFileType.BMP;
                        break;
                    case ".tga":
                        fileType = ImageFileType.TARGA;
                        break;
                    case ".tif":
                        fileType = ImageFileType.TIFF;
                        break;
                }
                pathName = Path.Combine(
                    Path.GetDirectoryName(fullPath),
                    Path.GetFileNameWithoutExtension(fullPath));
            }

            var options = new ImageExportOptions
            {
                ExportRange = ExportRange.SetOfViews,
                FilePath = pathName,
                HLRandWFViewsFileType = fileType,
                ImageResolution = ImageResolution.DPI_72,
                ZoomType = ZoomFitType.Zoom,
                ShadowViewsFileType = fileType
            };

            options.SetViewsAndSheets(new List<ElementId> { view.Id });

            dynRevitSettings.Doc.Document.ExportImage(options);
                //revit only has a method to save image to disk.

            //hack - rename saved file to match specified file name
            //File.Move(string.Format("{0} - {1} - {2}.png", pathName, view.ViewType, view.ViewName), pathName + ".png");

            //hack - make sure to change the read image below if other file types are supported
            //Image image = Image.FromFile(pathName + (extension ?? ".png"));

            return Value.NewDummy("wrote image file"); //NewContainer(image);
        }
예제 #41
0
 public void ExportToImage(Stream stream, ImageExportOptions options)
 {
     report.ExportToImage(stream, options);
 }
예제 #42
0
        void GenerateThumbnailCore(Item item)
        {
            IPrintable component = DocumentService.CreatePrintableComponent(item);
                if (component == null)
                     return;

                PrintableComponentLinkBase pcl = new PrintableComponentLinkBase(new PrintingSystemBase());
                pcl.Component = component;
                pcl.CreateDocument();
                ImageExportOptions imgOptions = new ImageExportOptions();
                imgOptions.ExportMode = ImageExportMode.SingleFilePageByPage;
                imgOptions.Format = System.Drawing.Imaging.ImageFormat.Png;
                imgOptions.PageRange = "1";
                imgOptions.PageBorderWidth = 0;
                MemoryStream stream = new MemoryStream();
                pcl.ExportToImage(stream, imgOptions);

                stream.Position = 0;
                string thumbPath = GetThumbnailPath(item);
                GenerateThumbnailInternal(stream, thumbPath, ThumbnailWidth, ThumbnailHeight);

                IDisposable disposableComponent = component as IDisposable;
                if (disposableComponent != null)
                     disposableComponent.Dispose();
        }
예제 #43
0
파일: dynViews.cs 프로젝트: kyoisi/Dynamo
        public override Value Evaluate(FSharpList<Value> args)
        {
            View view = (View)((Value.Container)args[0]).Item;
            string path = ((Value.String)args[1]).Item;

            string name = view.ViewName;
            string pathName = path + "\\" + name;
            System.Drawing.Image image;

            ImageExportOptions options = new ImageExportOptions();
            options.ExportRange = ExportRange.VisibleRegionOfCurrentView;
            options.FilePath = pathName;
            options.HLRandWFViewsFileType = ImageFileType.PNG; //hack - make sure to change the read image below if other file types are supported
            options.ImageResolution = ImageResolution.DPI_72;
            options.ZoomType = ZoomFitType.Zoom;
            options.ShadowViewsFileType = ImageFileType.PNG;

            try
            {
                dynRevitSettings.Doc.Document.ExportImage(options);//revit only has a method to save image to disk.
                //hack - make sure to change the read image below if other file types are supported
                image = Image.FromFile(pathName + ".png");//read the saved image so we can pass it downstream

            }
            catch (Exception e)
            {
                dynSettings.Controller.DynamoViewModel.Log(e);
                return Value.NewContainer(0);
            }

            return Value.NewContainer(image);
        }