コード例 #1
0
        public void RenameAllExecuted(object param)
        {
            using (TransactionGroup tg = new TransactionGroup(m_doc))
            {
                tg.Start("Rename Families");
                try
                {
                    ProgressManager.InitializeProgress("Renaming.. ", typeProperties.Count);
                    for (int i = 0; i < typeProperties.Count; i++)
                    {
                        ProgressManager.StepForward();
                        FamilyTypeProperties ftp = typeProperties[i];
                        if (ftp.IsLinked)
                        {
                            continue;
                        }

                        ElementType eType = m_doc.GetElement(ftp.FamilyTypeId) as ElementType;
                        if (null != eType)
                        {
                            using (Transaction trans = new Transaction(m_doc))
                            {
                                trans.Start("Rename");
                                try
                                {
                                    if (eType is FamilySymbol)
                                    {
                                        (eType as FamilySymbol).Family.Name = ftp.FamilyName;
                                    }

                                    eType.Name = ftp.TypeName;
                                    trans.Commit();

                                    typeProperties[i].CurrentFamilyName = ftp.FamilyName;
                                    typeProperties[i].CurrentTypeName   = ftp.TypeName;
                                    typeProperties[i].IsLinked          = true;
                                    typeProperties[i].ToolTip           = "Current Family Name: " + ftp.FamilyName + ", Current Tyle Name: " + ftp.TypeName;
                                    typeProperties[i].IsSelected        = false;
                                }
                                catch (Exception ex)
                                {
                                    trans.RollBack();
                                    string message = ex.Message;
                                }
                            }
                        }
                    }
                    ProgressManager.FinalizeProgress();
                    this.StatusText = fileName;
                    tg.Assimilate();
                }
                catch (Exception ex)
                {
                    tg.RollBack();
                    MessageBox.Show("Failed to rename families and types.\n" + ex.Message, "Rename Families and Types", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
        }
コード例 #2
0
        public void RenameSelectedExecuted(object param)
        {
            using (TransactionGroup tg = new TransactionGroup(m_doc))
            {
                tg.Start("Rename Families");
                try
                {
                    if (selectedModelIndex > -1 && selectedCategoryIndex > -1)
                    {
                        string modelName    = modelNames[selectedModelIndex];
                        string categoryName = categoryNames[selectedCategoryIndex];

                        var itemFound = from item in typeProperties where item.ModelName == modelName && item.CategoryName == categoryName && item.IsSelected select item;
                        ProgressManager.InitializeProgress("Renaming.. ", itemFound.Count());
                        if (itemFound.Count() > 0)
                        {
                            foreach (FamilyTypeProperties ftp in itemFound)
                            {
                                ProgressManager.StepForward();
                                if (ftp.IsLinked)
                                {
                                    continue;
                                }
                                int index = typeProperties.IndexOf(ftp);

                                ElementType symbol = m_doc.GetElement(ftp.FamilyTypeId) as ElementType;
                                if (null != symbol)
                                {
                                    using (Transaction trans = new Transaction(m_doc))
                                    {
                                        trans.Start("Rename");
                                        try
                                        {
                                            if (symbol is FamilySymbol)
                                            {
                                                (symbol as FamilySymbol).Family.Name = ftp.FamilyName;
                                            }
                                            symbol.Name = ftp.TypeName;

                                            trans.Commit();

                                            typeProperties[index].CurrentFamilyName = ftp.FamilyName;
                                            typeProperties[index].CurrentTypeName   = ftp.TypeName;
                                            typeProperties[index].IsLinked          = true;
                                            typeProperties[index].ToolTip           = "Current Family Name: " + ftp.FamilyName + ", Current Tyle Name: " + ftp.TypeName;
                                            typeProperties[index].IsSelected        = false;
                                        }
                                        catch (Exception ex)
                                        {
                                            trans.RollBack();
                                            string message = ex.Message;
                                        }
                                    }
                                }
                            }
                        }
                        ProgressManager.FinalizeProgress();
                        this.StatusText = fileName;
                    }
                    tg.Assimilate();
                }
                catch (Exception ex)
                {
                    tg.RollBack();
                    MessageBox.Show("Failed to rename families and types.\n" + ex.Message, "Rename Families and Types", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
        }
コード例 #3
0
        public static bool Write(string bcfPath, BCFZIP bcf)
        {
            bool written = false;

            try
            {
                ProgressManager.InitializeProgress("Writing BCF..", bcf.Markups.Count);

                string tempDirectory = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "SmartBCF", bcf.FileId);
                if (Directory.Exists(tempDirectory))
                {
                    Directory.Delete(tempDirectory, true);
                }

                //Create root directory
                Directory.CreateDirectory(tempDirectory);

                //Project File
                string projectFilePath = System.IO.Path.Combine(tempDirectory, "project.bcfp");
                using (FileStream stream = new FileStream(projectFilePath, FileMode.Create))
                {
                    XmlSerializer projectSerializer = new XmlSerializer(typeof(ProjectExtension));
                    projectSerializer.Serialize(stream, bcf.ProjectFile);
                    stream.Close();
                }

                //Version File
                string versionFilePath = System.IO.Path.Combine(tempDirectory, "bcf.version");
                using (FileStream stream = new FileStream(versionFilePath, FileMode.Create))
                {
                    XmlSerializer versionSerializer = new XmlSerializer(typeof(Version));
                    versionSerializer.Serialize(stream, bcf.VersionFile);
                    stream.Close();
                }

                //Color File
                string colorFilePath = System.IO.Path.Combine(tempDirectory, "extension.color");
                using (FileStream stream = new FileStream(colorFilePath, FileMode.Create))
                {
                    XmlSerializer colorSerializer = new XmlSerializer(typeof(RevitExtensionInfo));
                    colorSerializer.Serialize(stream, bcf.ExtensionColor);
                    stream.Close();
                }

                //Markup and Viewpoint
                XmlSerializer markupSerializer  = new XmlSerializer(typeof(Markup));
                XmlSerializer visInfoSerializer = new XmlSerializer(typeof(VisualizationInfo));
                XmlSerializer extInfoSerializer = new XmlSerializer(typeof(ComponentExtensionInfo));
                foreach (Markup markup in bcf.Markups)
                {
                    ProgressManager.StepForward();

                    string topicDirectory = System.IO.Path.Combine(tempDirectory, markup.Topic.Guid);
                    Directory.CreateDirectory(topicDirectory);

                    string markupFilePath = System.IO.Path.Combine(topicDirectory, "markup.bcf");
                    using (FileStream stream = new FileStream(markupFilePath, FileMode.Create))
                    {
                        markupSerializer.Serialize(stream, markup);
                        stream.Close();
                    }

                    //Viewpoint
                    foreach (ViewPoint vp in markup.Viewpoints)
                    {
                        //Snapshot
                        if (!string.IsNullOrEmpty(vp.Snapshot) && null != vp.SnapshotImage)
                        {
                            string snapshotPath = System.IO.Path.Combine(topicDirectory, vp.Snapshot);
                            using (System.Drawing.Image image = System.Drawing.Image.FromStream(new MemoryStream(vp.SnapshotImage)))
                            {
                                image.Save(snapshotPath, System.Drawing.Imaging.ImageFormat.Png);
                            }
                        }

                        if (!string.IsNullOrEmpty(vp.Viewpoint))
                        {
                            //Visinfo
                            string visInfoPath = System.IO.Path.Combine(topicDirectory, vp.Viewpoint);
                            if (null != vp.VisInfo)
                            {
                                VisualizationInfo visInfo = vp.VisInfo;
                                using (FileStream stream = new FileStream(visInfoPath, FileMode.Create))
                                {
                                    visInfoSerializer.Serialize(stream, visInfo);
                                    stream.Close();
                                }

                                string extensionPath           = visInfoPath.Replace(".bcfv", ".bcfvx");
                                ComponentExtensionInfo extInfo = new ComponentExtensionInfo();
                                extInfo.ViewpointGuid = vp.Guid;
                                var revitComponents = from comp in visInfo.Components
                                                      where (null != comp.Action) && (null != comp.Responsibility)
                                                      select comp;
                                if (revitComponents.Count() > 0)
                                {
                                    var componentsToWrite = from comp in revitComponents
                                                            where (comp.Action.Guid != Guid.Empty.ToString()) || (comp.Responsibility.Guid != Guid.Empty.ToString()) || (!string.IsNullOrEmpty(comp.ElementName))
                                                            select comp;
                                    if (componentsToWrite.Count() > 0)
                                    {
                                        ObservableCollection <ComponentExtension> compExtensions = new ObservableCollection <ComponentExtension>();
                                        List <Component> componentList = revitComponents.ToList();
                                        foreach (Component comp in componentList)
                                        {
                                            compExtensions.Add(new ComponentExtension(comp));
                                        }
                                        extInfo.Extensions = compExtensions;
                                        using (FileStream stream = new FileStream(extensionPath, FileMode.Create))
                                        {
                                            extInfoSerializer.Serialize(stream, extInfo);
                                            stream.Close();
                                        }
                                    }
                                }

                                //Bitmap
                                if (vp.VisInfo.Bitmaps.Count > 0)
                                {
                                    foreach (VisualizationInfoBitmaps bitmap in visInfo.Bitmaps)
                                    {
                                        if (!string.IsNullOrEmpty(bitmap.Reference) && null != bitmap.BitmapImage)
                                        {
                                            string bitmapPath = System.IO.Path.Combine(topicDirectory, bitmap.Reference);
                                            using (System.Drawing.Image image = System.Drawing.Image.FromStream(new MemoryStream(bitmap.BitmapImage)))
                                            {
                                                if (bitmap.Bitmap == BitmapFormat.JPG)
                                                {
                                                    image.Save(bitmapPath, System.Drawing.Imaging.ImageFormat.Jpeg);
                                                }
                                                else if (bitmap.Bitmap == BitmapFormat.PNG)
                                                {
                                                    image.Save(bitmapPath, System.Drawing.Imaging.ImageFormat.Png);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                ZipFile.CreateFromDirectory(tempDirectory, bcfPath, CompressionLevel.Fastest, false);
                if (File.Exists(bcfPath))
                {
                    written = true;
                }
                ProgressManager.FinalizeProgress();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to write the BCF file.\n" + ex.Message, "Write BCF", MessageBoxButton.OK, MessageBoxImage.Warning);
                ProgressManager.FinalizeProgress();
            }
            return(written);
        }
コード例 #4
0
ファイル: BCFReader.cs プロジェクト: ezhangle/SmartBCF
        /// <summary>
        /// Read files and serialize xml files into class structure
        /// </summary>
        /// <param name="bcfPath">the name of bcfzip</param>
        /// <param name="tempVisInfoHolder"></param>
        /// <param name="tempFileContentHoder"></param>
        /// <param name="tempExtInfoHolder"></param>
        /// <returns></returns>
        private static BCFZIP ReadRawData(string bcfPath, out Dictionary <string, Dictionary <string, VisualizationInfo> > tempVisInfoHolder,
                                          out Dictionary <string, Dictionary <string, byte[]> > tempFileContentHoder, out Dictionary <string, Dictionary <string, ComponentExtensionInfo> > tempExtInfoHolder)
        {
            BCFZIP bcfZip = new BCFZIP(bcfPath);

            tempVisInfoHolder    = new Dictionary <string, Dictionary <string, VisualizationInfo> >();
            tempFileContentHoder = new Dictionary <string, Dictionary <string, byte[]> >();
            tempExtInfoHolder    = new Dictionary <string, Dictionary <string, ComponentExtensionInfo> >();
            try
            {
                using (ZipArchive archive = ZipFile.OpenRead(bcfPath))
                {
                    ProgressManager.InitializeProgress("Gathering information from the BCF file...", archive.Entries.Count);
                    double value = 0;

                    foreach (ZipArchiveEntry entry in archive.Entries)
                    {
                        value++;
                        ProgressManager.StepForward();
                        string topicId = entry.ExtractGuidFolderName();

                        if (entry.FullName.EndsWith(".bcfp", StringComparison.OrdinalIgnoreCase))
                        {
                            //serialize project file
                            XmlSerializer serializer = new XmlSerializer(typeof(ProjectExtension));
                            XmlReader     reader     = XmlReader.Create(entry.Open());
                            if (serializer.CanDeserialize(reader))
                            {
                                bcfZip.ProjectFile = (ProjectExtension)serializer.Deserialize(reader);
                                continue;
                            }
                        }
                        else if (entry.FullName.EndsWith(".version", StringComparison.OrdinalIgnoreCase))
                        {
                            //serialize version file
                            XmlSerializer serializer = new XmlSerializer(typeof(Version));
                            XmlReader     reader     = XmlReader.Create(entry.Open());
                            if (serializer.CanDeserialize(reader))
                            {
                                bcfZip.VersionFile = (Version)serializer.Deserialize(reader);
                                continue;
                            }
                        }
                        else if (entry.FullName.EndsWith(".color", StringComparison.OrdinalIgnoreCase))
                        {
                            //serialize color file
                            XmlSerializer serializer = new XmlSerializer(typeof(RevitExtensionInfo));
                            XmlReader     reader     = XmlReader.Create(entry.Open());
                            if (serializer.CanDeserialize(reader))
                            {
                                bcfZip.ExtensionColor = (RevitExtensionInfo)serializer.Deserialize(reader);
                                continue;
                            }
                        }
                        else if (!string.IsNullOrEmpty(topicId) && entry.FullName.EndsWith(".bcf", StringComparison.OrdinalIgnoreCase))
                        {
                            //serialize markup file
                            XmlSerializer serializer = new XmlSerializer(typeof(Markup));
                            XmlReader     reader     = XmlReader.Create(entry.Open());
                            if (serializer.CanDeserialize(reader))
                            {
                                Markup markup = (Markup)serializer.Deserialize(reader);
                                bcfZip.Markups.Add(markup);
                            }
                        }
                        else if (!string.IsNullOrEmpty(topicId) && entry.FullName.EndsWith(".bcfv", StringComparison.OrdinalIgnoreCase))
                        {
                            //serialize viewpoint file
                            XmlSerializer serializer = new XmlSerializer(typeof(VisualizationInfo));
                            XmlReader     reader     = XmlReader.Create(entry.Open());
                            if (serializer.CanDeserialize(reader))
                            {
                                VisualizationInfo visInfo = (VisualizationInfo)serializer.Deserialize(reader);
                                if (tempVisInfoHolder.ContainsKey(topicId))
                                {
                                    if (!tempVisInfoHolder[topicId].ContainsKey(entry.Name))
                                    {
                                        tempVisInfoHolder[topicId].Add(entry.Name, visInfo);
                                    }
                                }
                                else
                                {
                                    Dictionary <string, VisualizationInfo> visInfoDictionary = new Dictionary <string, VisualizationInfo>();
                                    visInfoDictionary.Add(entry.Name, visInfo);
                                    tempVisInfoHolder.Add(topicId, visInfoDictionary);
                                }
                            }
                        }
                        else if (!string.IsNullOrEmpty(topicId) && entry.FullName.EndsWith(".bcfvx", StringComparison.OrdinalIgnoreCase))
                        {
                            //serialize extension file
                            XmlSerializer serializer = new XmlSerializer(typeof(ComponentExtensionInfo));
                            XmlReader     reader     = XmlReader.Create(entry.Open());
                            if (serializer.CanDeserialize(reader))
                            {
                                ComponentExtensionInfo extInfo = (ComponentExtensionInfo)serializer.Deserialize(reader);
                                if (tempExtInfoHolder.ContainsKey(topicId))
                                {
                                    if (!tempExtInfoHolder[topicId].ContainsKey(entry.Name))
                                    {
                                        tempExtInfoHolder[topicId].Add(entry.Name, extInfo);
                                    }
                                }
                                else
                                {
                                    Dictionary <string, ComponentExtensionInfo> extInfoDictionary = new Dictionary <string, ComponentExtensionInfo>();
                                    extInfoDictionary.Add(entry.Name, extInfo);
                                    tempExtInfoHolder.Add(topicId, extInfoDictionary);
                                }
                            }
                        }
                        else
                        {
                            //obtain bytearray of miscellaneous files including images
                            using (MemoryStream ms = new MemoryStream())
                            {
                                entry.Open().CopyTo(ms);
                                byte[] byteArray = ms.ToArray();
                                if (tempFileContentHoder.ContainsKey(topicId))
                                {
                                    if (!tempFileContentHoder[topicId].ContainsKey(entry.Name))
                                    {
                                        tempFileContentHoder[topicId].Add(entry.Name, byteArray);
                                    }
                                }
                                else
                                {
                                    Dictionary <string, byte[]> fileContents = new Dictionary <string, byte[]>();
                                    fileContents.Add(entry.Name, byteArray);
                                    tempFileContentHoder.Add(topicId, fileContents);
                                }
                            }
                        }
                    }
                    ProgressManager.FinalizeProgress();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to read data from BCF.\n" + ex.Message, "Read Raw Data", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(bcfZip);
        }