/// <summary>
        /// Collect the parameters and export
        /// </summary>
        /// <returns></returns>
        public override bool Import()
        {
            bool imported = false;

            //parameter: ImageImportOptions
            ImageImportOptions options = new ImageImportOptions();
            options.Placement = Autodesk.Revit.DB.BoxPlacement.Center;
            //parameter: Element
            Element element = null;

            //Import
            Transaction t = new Transaction(m_activeDoc);
            t.SetName("Import");
            t.Start();
            imported = m_activeDoc.Import(m_importFileFullName, options, CommandData.Application.ActiveUIDocument.Document.ActiveView, out element);
            t.Commit();

            return imported;
        }
Ejemplo n.º 2
0
        ImportImage()
        {
            // get input file of type DWG
            System.Windows.Forms.OpenFileDialog dbox = new System.Windows.Forms.OpenFileDialog();
            dbox.CheckFileExists = true;
            dbox.Multiselect     = false;
            dbox.AddExtension    = true;
            dbox.DefaultExt      = "jpg";
            dbox.Filter          = "Image Files (*.jpg;*.png;*.bmp)|*.jpg;*.png;*.bmp";
            dbox.Title           = "Image file to import";

            if (dbox.ShowDialog() == DialogResult.OK)
            {
                ImageImportOptions opts = new ImageImportOptions();
                opts.Placement = BoxPlacement.BottomLeft;

                Element newElement;
                m_revitApp.ActiveUIDocument.Document.Import(dbox.FileName, opts, m_revitApp.ActiveUIDocument.ActiveView, out newElement);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Collect the parameters and export
        /// </summary>
        /// <returns></returns>
        public override bool Import()
        {
            bool imported = false;

            //parameter: ImageImportOptions
            ImageImportOptions options = new ImageImportOptions();

            options.Placement = Autodesk.Revit.DB.BoxPlacement.Center;
            //parameter: Element
            Element element = null;

            //Import
            Transaction t = new Transaction(m_activeDoc);

            t.SetName("Import");
            t.Start();
            imported = m_activeDoc.Import(m_importFileFullName, options, CommandData.Application.ActiveUIDocument.Document.ActiveView, out element);
            t.Commit();

            return(imported);
        }
Ejemplo n.º 4
0
        public void ImportImage()
        {
            // get input file of type DWG
             System.Windows.Forms.OpenFileDialog dbox = new System.Windows.Forms.OpenFileDialog();
             dbox.CheckFileExists = true;
             dbox.Multiselect = false;
             dbox.AddExtension = true;
             dbox.DefaultExt = "jpg";
             dbox.Filter = "Image Files (*.jpg;*.png;*.bmp)|*.jpg;*.png;*.bmp";
             dbox.Title = "Image file to import";

             if (dbox.ShowDialog() == DialogResult.OK)
             {
            ImageImportOptions opts = new ImageImportOptions();
            opts.Placement = BoxPlacement.BottomLeft;

            Element newElement;
            m_revitApp.ActiveUIDocument.Document.Import(dbox.FileName, opts, m_revitApp.ActiveUIDocument.ActiveView, out newElement);
             }
        }
Ejemplo n.º 5
0
        public void insertImages(Document doc, string path)
        {
            //Parameter p;
            string imagePath = Path.GetDirectoryName(path);

            imagePath = imagePath + @"\Master Schedule (Images)\";
            DirectoryInfo X = new DirectoryInfo(imagePath);

            FileInfo[] someFiles    = X.GetFiles("*.png");
            var        orderedFiles = someFiles.OrderBy(f => f.FullName);

            FileInfo[] listOfFiles = orderedFiles.ToArray();

            string sheetSize = Command.thisCommand.getSheetSize();

            if (sheetSize == "24 x 36")
            {
                formatHeight      = 22.25;
                centerLine        = (12.0 / 12);
                imagePerSheet     = 4;
                initialEdgeOffset = (3.875 / 12);
                finalYLocation    = (23.125 / 12);
            }
            else if (sheetSize == "30 x 42")
            {
                formatHeight      = 28.25;
                centerLine        = (15.0 / 12);
                imagePerSheet     = 5;
                initialEdgeOffset = (3.0 / 12);
                finalYLocation    = (29.125 / 12);
            }
            else if (sheetSize == "36 x 48")
            {
                formatHeight      = 34.25;
                centerLine        = (18.0 / 12);
                imagePerSheet     = 6;
                initialEdgeOffset = (2.125 / 12);
                finalYLocation    = (35.125 / 12);
            }
            else
            {
            }
            int totalImages = listOfFiles.Count();

            int fullSheets             = totalImages / imagePerSheet;
            int lastSheetImageQuantity = totalImages - (imagePerSheet * fullSheets);

            int    sheetEndNumber = 70;
            string sheetBegining;
            string templateCategory = Command.thisCommand.getTemplateCategory();

            if (templateCategory == "ARCHITECTURE")
            {
                sheetBegining = "A0.";
            }
            else
            {
                sheetBegining = "IA0.";
            }
            int imgCount = 0;
            ImageImportOptions iIOptions = new ImageImportOptions();

            iIOptions.Resolution = 150;
            iIOptions.RefPoint   = (new XYZ(0, 0, 0));
            iIOptions.Placement  = BoxPlacement.TopLeft;
            Autodesk.Revit.DB.View currentImageSheet;
            SetupProgress(listOfFiles.Count(), "Task: Placing Master Schedule Images");

            //Start with full sheets
            if (fullSheets > 0)
            {
                bool fullSheetsExist = true;
                while (fullSheetsExist)
                {
                    //search for sheet
                    string searchSheet = sheetBegining + sheetEndNumber.ToString("D2");
                    currentImageSheet = FindSheet(doc, searchSheet);
                    if (currentImageSheet == null)
                    {
                        ElementId tBlockID = Command.thisCommand.getTitleBlockID();
                        using (Transaction tx = new Transaction(doc))
                        {
                            tx.Start("Create Sheet");
                            ViewSheet myViewSheet = ViewSheet.Create(doc, tBlockID);
                            myViewSheet.Name        = "MASTER SCHEDULE";
                            myViewSheet.SheetNumber = searchSheet;
                            tx.Commit();
                        }
                        currentImageSheet = FindSheet(doc, searchSheet);
                        SetSheetParameters(currentImageSheet, doc);
                        double startLocation = initialEdgeOffset;
                        for (int imgOnSheet = 1; imgOnSheet <= imagePerSheet; imgOnSheet++)
                        {
                            if (imgCount < listOfFiles.Count())
                            {
                                iIOptions.RefPoint = (new XYZ(startLocation, finalYLocation, 0));
                                var     imageLocation = listOfFiles[imgCount].Directory.FullName + @"\" + listOfFiles[imgCount].Name;
                                Element e             = null;
                                using (Transaction tx = new Transaction(doc))
                                {
                                    tx.Start("Import Image");
                                    doc.Import(imageLocation, iIOptions, currentImageSheet, out e);
                                    tx.Commit();
                                }
                                IncrementProgress();
                                startLocation = startLocation + (6.875 / 12);

                                imgCount++;
                            }
                        }
                    }
                    else
                    {
                        double startLocation = initialEdgeOffset;
                        for (int imgOnSheet = 1; imgOnSheet <= imagePerSheet; imgOnSheet++)
                        {
                            if (imgCount < listOfFiles.Count())
                            {
                                iIOptions.RefPoint = (new XYZ(startLocation, finalYLocation, 0));
                                var     imageLocation = listOfFiles[imgCount].Directory.FullName + @"\" + listOfFiles[imgCount].Name;
                                Element e             = null;
                                using (Transaction tx = new Transaction(doc))
                                {
                                    tx.Start("Import Image");
                                    doc.Import(imageLocation, iIOptions, currentImageSheet, out e);
                                    tx.Commit();
                                }
                                IncrementProgress();
                                startLocation = startLocation + (6.875 / 12);

                                imgCount++;
                            }
                        }
                    }
                    sheetEndNumber++;
                    fullSheets--;
                    if (fullSheets < 1)
                    {
                        fullSheetsExist = false;
                    }
                }
            }

            if (lastSheetImageQuantity > 0)
            {
                int    imageInitialOffset = imagePerSheet - lastSheetImageQuantity;
                string searchSheet        = sheetBegining + sheetEndNumber.ToString("D2");
                currentImageSheet = FindSheet(doc, searchSheet);
                if (currentImageSheet == null)
                {
                    ElementId tBlockID = Command.thisCommand.getTitleBlockID();
                    using (Transaction tx = new Transaction(doc))
                    {
                        tx.Start("Create Sheet");
                        ViewSheet myViewSheet = ViewSheet.Create(doc, tBlockID);
                        myViewSheet.Name        = "MASTER SCHEDULE";
                        myViewSheet.SheetNumber = searchSheet;
                        tx.Commit();
                    }
                    currentImageSheet = FindSheet(doc, searchSheet);
                    SetSheetParameters(currentImageSheet, doc);
                    double startLocation = initialEdgeOffset + (imageInitialOffset * (6.875 / 12));
                    for (int imgOnSheet = imageInitialOffset; imgOnSheet <= imagePerSheet; imgOnSheet++)
                    {
                        if (imgCount < listOfFiles.Count())
                        {
                            iIOptions.RefPoint = (new XYZ(startLocation, finalYLocation, 0));
                            var     imageLocation = listOfFiles[imgCount].Directory.FullName + @"\" + listOfFiles[imgCount].Name;
                            Element e             = null;
                            using (Transaction tx = new Transaction(doc))
                            {
                                tx.Start("Import Image");
                                doc.Import(imageLocation, iIOptions, currentImageSheet, out e);
                                tx.Commit();
                            }
                            IncrementProgress();
                            startLocation = startLocation + (6.875 / 12);

                            imgCount++;
                        }
                    }
                }
                else
                {
                    double startLocation = initialEdgeOffset + (imageInitialOffset * (6.875 / 12));
                    for (int imgOnSheet = imageInitialOffset; imgOnSheet <= imagePerSheet; imgOnSheet++)
                    {
                        if (imgCount < listOfFiles.Count())
                        {
                            iIOptions.RefPoint = (new XYZ(startLocation, finalYLocation, 0));
                            var     imageLocation = listOfFiles[imgCount].Directory.FullName + @"\" + listOfFiles[imgCount].Name;
                            Element e             = null;
                            using (Transaction tx = new Transaction(doc))
                            {
                                tx.Start("Import Image");
                                doc.Import(imageLocation, iIOptions, currentImageSheet, out e);
                                tx.Commit();
                            }
                            IncrementProgress();
                            startLocation = startLocation + (6.875 / 12);

                            imgCount++;
                        }
                    }
                }
            }
        }
        public void ImportimageToProject(string pathToImage)
        {
            UIDocument uidoc = Import.appRevit.ActiveUIDocument;
            Document doc = uidoc.Document;
            try
            {
                Element element = null;
                using (Transaction transaction = new Transaction(doc, "Импорт изображения"))
                {
                    transaction.Start();
                    ImageImportOptions options = new ImageImportOptions();
                    options.Placement = Autodesk.Revit.DB.BoxPlacement.Center;
                    doc.Import(pathToImage, options, doc.ActiveView, out element);
                    string[] name = Path.GetFileName(pathToImage).Split('.');
                    doc.Delete(element.Id);
                    var rasterImages = new FilteredElementCollector(doc).OfClass(typeof(ImageType)).OfCategory(BuiltInCategory.OST_RasterImages).ToList().Where(x => x.Name.Contains(name[0])).ToList();
                    if (rasterImages.Count == 0) return;
                    ImageType im = rasterImages[0] as ImageType;

                    Element el = doc.GetElement(Import.selElement.Id);
                    Parameter par = el.GetParameters("Изображение")[0];
                    par.Set(im.Id);
                    transaction.Commit();
                }
            }
            catch { }
        }