//****************************************************************************************** /// <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(); }
//****************************************************************************************** /// <summary> /// this function export View from the list /// </summary> public List <ViewPath> Export(List <View> argListView, DWGExportOptions setDwg, IREXProgress argProgress) { IREXProgress Progress = argProgress; Progress.Steps = 2 * argListView.Count; Progress.Position = 0; Progress.Header = Resources.Strings.Texts.FreezeInProgress + " - " + Resources.Strings.Texts.Export; List <ViewPath> nameStr = new List <ViewPath>(); m_path = getTempPath(); //reading files from temp directory setDwg.LayerMapping = GetLayMap(setDwg.LayerMapping); foreach (View v in argListView) { List <ElementId> vSet = new List <ElementId>(); if (v != null) { View3D tmp3D = null; Autodesk.Revit.DB.ViewSheet viewSheet = null; bool proceed = false; if (v is Autodesk.Revit.DB.View3D) { try { FilteredElementCollector filteredElementCollector = new FilteredElementCollector(ThisExtension.Revit.ActiveDocument); filteredElementCollector.OfClass(typeof(FamilySymbol)); filteredElementCollector.OfCategory(BuiltInCategory.OST_TitleBlocks); IList <RevitElement> titleBlocks = filteredElementCollector.ToElements(); List <FamilySymbol> familySymbols = new List <FamilySymbol>(); foreach (Element element in titleBlocks) { FamilySymbol f = element as FamilySymbol; if (f != null) { familySymbols.Add(f); } } if (titleBlocks.Count != 0) { Autodesk.Revit.DB.FamilySymbol fs = null; foreach (Autodesk.Revit.DB.FamilySymbol f in familySymbols) { if (null != f) { fs = f; break; } } viewSheet = Autodesk.Revit.DB.ViewSheet.Create(ThisExtension.Revit.ActiveDocument, fs.Id); if (null != viewSheet) { UV location = new UV((viewSheet.Outline.Max.U - viewSheet.Outline.Min.U) / 2, (viewSheet.Outline.Max.V - viewSheet.Outline.Min.V) / 2); try { Viewport.Create(ThisExtension.Revit.ActiveDocument, viewSheet.Id, v.Id, new XYZ(location.U, location.V, 0.0)); } catch { try { XYZ tmpXYZ = new XYZ(-v.ViewDirection.X, -v.ViewDirection.Y, -v.ViewDirection.Z); BoundingBoxXYZ tmpBoundingBox = v.CropBox; bool tmpCropBoxActive = v.CropBoxActive; IList <Element> viewTypes = REXGeometryRvt.FilterElements(ThisExtension.Revit.ActiveDocument, typeof(ViewFamilyType)); ElementId viewTypeid = null; foreach (Element viewType in viewTypes) { ViewFamilyType famType = viewType as ViewFamilyType; if (famType != null && famType.ViewFamily == ViewFamily.ThreeDimensional) { viewTypeid = famType.Id; break; } } if (viewTypeid != null) { tmp3D = View3D.CreateIsometric(ThisExtension.Revit.ActiveDocument, viewTypeid); tmp3D.ApplyViewTemplateParameters(v); tmp3D.CropBox = tmpBoundingBox; Viewport.Create(ThisExtension.Revit.ActiveDocument, viewSheet.Id, tmp3D.Id, new XYZ(location.U, location.V, 0.0)); } } catch { } } vSet.Add(viewSheet.Id); proceed = true; } } } catch { } } else { vSet.Add(v.Id); proceed = true; } if (proceed) { string fam = v.get_Parameter(BuiltInParameter.VIEW_FAMILY).AsString(); Progress.Step(fam + "-" + v.Name); string vName = ValidateFileName(v.Name); m_CommandData.Application.ActiveUIDocument.Document.Export(m_path, fam + "-" + vName, vSet, setDwg); nameStr.Add(new ViewPath(m_path + "\\" + fam + "-" + vName + ".dwg", v, fam + "-" + v.Name)); Progress.Step(fam + "-" + v.Name); if (viewSheet != null) { ElementId elementId = viewSheet.Id; ThisExtension.Revit.ActiveDocument.Delete(elementId); } if (tmp3D != null) { ElementId elementId = tmp3D.Id; ThisExtension.Revit.ActiveDocument.Delete(elementId); } } } } return(nameStr); }
//****************************************************************************************** /// <summary> /// Run process calculations and etc. /// </summary> public override void OnRun() { base.OnRun(); List <ViewPath> fileNames = new List <ViewPath>(); Autodesk.Revit.DB.DWGExportOptions dwgOpt = dlgExportOptions.GetExportOptions(dlgOptions.Copy); dwgOpt.FileVersion = dlgOptions.GetVersion(); Autodesk.Revit.DB.DWGImportOptions dwgImpOpt = dlgOptions.GetImportOptions(); dwgImpOpt.Unit = dlgExportOptions.GetExportUnits(dlgOptions.Copy); m_ExpImpMng.Clean(); try //for demo mode { List <Autodesk.Revit.DB.View> viewList; if (FreezeControl.CurrentView) { Autodesk.Revit.DB.View v = Revit.CommandData().Application.ActiveUIDocument.Document.ActiveView; if (!(v.ViewType == Autodesk.Revit.DB.ViewType.Internal || v.ViewType == Autodesk.Revit.DB.ViewType.DrawingSheet || !v.CanBePrinted)) { viewList = new List <Autodesk.Revit.DB.View>(); viewList.Add(Revit.CommandData().Application.ActiveUIDocument.Document.ActiveView); } else { viewList = new List <Autodesk.Revit.DB.View>(); } } else { viewList = dlgViewSel.GetSelectedViews(); } if (viewList.Count > 0) { IREXProgress Progress = System.SystemBase.Tools.Prograss; Progress.Steps = 2 * viewList.Count; Progress.Show(GetForm()); GetForm().Hide(); fileNames = m_ExpImpMng.Export(viewList, dwgOpt, Progress); m_ExpImpMng.Import(dlgOptions.Copy, dlgOptions.Browse, dlgOptions.BaseName, dwgImpOpt, fileNames, Progress); if (dlgOptions.DeleteView) { m_ExpImpMng.DeleteViews(viewList); } Progress.Hide(); global::System.Windows.Forms.MessageBox.Show(GetForm(), Resources.Strings.Texts.FreezingFinSuccesfull, Resources.Strings.Texts.REX_ModuleDescription); } } catch { } m_ExpImpMng.Clean(); DataRef.OptionPath = dlgOptions.Browse; System.SaveToFile(false, false); }