Exemple #1
0
        //******************************************************************************************
        /// <summary>
        /// this function gets view nam based on file name
        /// </summary>
        private bool CopyToUserDirViewPath(ViewPath argView, string argBaseName, string argBrowse, DialogMessageExists dlgMsg)
        {
            string newFileName;

            if (argBaseName != "")
            {
                newFileName = argBrowse + "\\" + argBaseName + "-" + argView.DraftingName + ".dwg";
            }
            else
            {
                newFileName = argBrowse + "\\" + argView.DraftingName + ".dwg";
            }

            string dirref         = Directory.GetParent(argView.path).FullName;
            string dwgreffile     = argView.fullViewName.Replace(" ", "");
            string dwgref         = Path.GetFileNameWithoutExtension(dwgreffile) + "-*.dwg";
            string dwggrefpath    = GetRefDWGFilePath(dwgref, dirref);
            string dd             = Path.GetFileName(dwggrefpath);
            string dwgrefdestpath = Path.Combine(argBrowse, dd);

            if (File.Exists(newFileName))
            {
                if (dlgMsg.Context == ReplaceContext.Leave || dlgMsg.Context == ReplaceContext.Replace)
                {
                    dlgMsg.ShowMessageDialog(newFileName, ThisExtension.GetForm());

                    if (dlgMsg.Context == ReplaceContext.Replace || dlgMsg.Context == ReplaceContext.ReplaceAll)
                    {
                        try
                        {
                            File.Copy(argView.path, newFileName, true);
                            if (dwggrefpath != "")
                            {
                                File.Copy(dwggrefpath, dwgrefdestpath, true);
                            }
                            return(true);
                        }
                        catch
                        {
                            System.Windows.Forms.MessageBox.Show(ThisExtension.GetForm(), Resources.Strings.Texts.ErrorAccessDenied + newFileName, Resources.Strings.Texts.REX_ModuleDescription);
                            return(false);
                        }
                    }

                    return(true);
                }
                else if (dlgMsg.Context == ReplaceContext.ReplaceAll)
                {
                    try
                    {
                        File.Copy(argView.path, newFileName, true);
                        if (dwggrefpath != "")
                        {
                            File.Copy(dwggrefpath, dwgrefdestpath, true);
                        }
                        return(true);
                    }
                    catch
                    {
                        System.Windows.Forms.MessageBox.Show(ThisExtension.GetForm(), Resources.Strings.Texts.ErrorAccessDenied + newFileName, Resources.Strings.Texts.REX_ModuleDescription);
                        return(false);
                    }
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                global::System.IO.File.Copy(argView.path, newFileName);
                if (dwggrefpath != "")
                {
                    System.IO.File.Copy(dwggrefpath, dwgrefdestpath, true);
                }
                return(true);
            }
        }
Exemple #2
0
        //******************************************************************************************
        /// <summary>
        /// this function imports all views from the list and create new draft views for them based on m_path
        /// </summary>
        public void Import(bool argCopy, string argBrowse, string argBaseName, Autodesk.Revit.DB.DWGImportOptions argOpt, List <ViewPath> argViewList, IREXProgress argProgress)
        {
            ViewDrafting     draftView;
            DWGImportOptions setDwgImp;
            IREXProgress     Progress = argProgress;

            DialogMessageExists dlgMsg = new DialogMessageExists(ThisExtension);

            dlgMsg.Text = Resources.Strings.Texts.REX_ModuleDescription;

            //getting file list from the directory
            string[] FileList = Directory.GetFiles(m_path, "*.dwg");

            List <string> SelectFileList = new List <string>();

            string newname;
            string strPost = " (" + Resources.Strings.Texts.Freezed + ")";

            Progress.Position = 0;
            Progress.Steps    = 2 * argViewList.Count;
            Progress.Header   = Resources.Strings.Texts.FreezeInProgress + " - " + Resources.Strings.Texts.Import;

            ViewFamilyType           viewFamilyType = null;
            FilteredElementCollector collector      = new FilteredElementCollector(m_CommandData.Application.ActiveUIDocument.Document);
            var viewFamilyTypes = collector.OfClass(typeof(ViewFamilyType)).ToElements();

            foreach (Element e in viewFamilyTypes)
            {
                ViewFamilyType v = e as ViewFamilyType;
                if (v.ViewFamily == ViewFamily.Drafting)
                {
                    viewFamilyType = v;
                    break;
                }
            }

            //importing files to Revit
            foreach (ViewPath v in argViewList)
            {
                draftView = ViewDrafting.Create(m_CommandData.Application.ActiveUIDocument.Document, viewFamilyType.Id);

                newname = ReplaceForbiddenSigns(v.fullViewName);

                string tempName = newname;
                int    i        = 1;
                for (;;)
                {
                    try
                    {
                        draftView.Name = newname + strPost;
                        break;
                    }
                    catch
                    {
                        if (i > 10)
                        {
                            try
                            {
                                draftView.Name = draftView.Name + strPost;
                            }
                            catch
                            {
                            }
                            break;
                        }
                        newname = tempName + "-" + i.ToString();
                        i++;
                    }
                }

                draftView.Scale = v.ViewRevit.Scale;

                Progress.Step(draftView.Name);

                //properties
                setDwgImp              = new DWGImportOptions();
                setDwgImp.ColorMode    = argOpt.ColorMode;
                setDwgImp.OrientToView = argOpt.OrientToView;
                setDwgImp.Unit         = argOpt.Unit;
                setDwgImp.CustomScale  = argOpt.CustomScale;

                //import
                RevitElement el = (RevitElement)draftView;
                if (File.Exists(v.path))
                {
                    ElementId id;
                    m_CommandData.Application.ActiveUIDocument.Document.Import(v.path, setDwgImp, draftView, out id);
                    v.DraftingName = draftView.Name;

                    //copying to user directory
                    if (argCopy)
                    {
                        CopyToUserDirViewPath(v, argBaseName, argBrowse, dlgMsg);
                    }
                }
                Progress.Step(draftView.Name);
            }
            dlgMsg.Dispose();
        }