Last active
April 10, 2025 17:49
RevitServerExport
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using Autodesk.Revit.DB; | |
using System.IO; | |
using Autodesk.Revit.ApplicationServices; | |
using Autodesk.Revit.UI.Events; | |
namespace EEPRevitPlagin.EEPRPCommandModules.RevitServerExport | |
{ | |
internal class ExportModels | |
{ | |
public static void ExportrvtModelFromServer(string path, string outFolder, Application app) | |
{ | |
try | |
{ | |
//app. DialogBoxShowing += UiAppOnDialogBoxShowing; | |
ModelPath modelPath = ModelPathUtils.ConvertUserVisiblePathToModelPath(path); | |
string modelName = Path.GetFileName(path); | |
string destModelPath = outFolder + @"\" + modelName; | |
Directory.CreateDirectory(outFolder+@"\temp"); | |
string destModelPathTemp = outFolder + @"\temp\a_" + modelName; | |
ModelPath modelPathtemp = ModelPathUtils.ConvertUserVisiblePathToModelPath(destModelPathTemp); | |
app.CopyModel(modelPath, destModelPathTemp, true); | |
UnloadRevitLinks(destModelPathTemp); | |
OpenOptions openOptions = new OpenOptions(); | |
openOptions.Audit = true; | |
openOptions.DetachFromCentralOption = DetachFromCentralOption.DetachAndPreserveWorksets; | |
openOptions.AllowOpeningLocalByWrongUser = true; | |
//Document doc = app.OpenDocumentFile(destModelPathTemp); | |
Document doc = app.OpenDocumentFile(modelPathtemp, openOptions); | |
SaveAsOptions saveAsOptions = new SaveAsOptions(); | |
WorksharingSaveAsOptions worksharingSaveAsOptions = new WorksharingSaveAsOptions(); | |
worksharingSaveAsOptions.SaveAsCentral = true; | |
worksharingSaveAsOptions.OpenWorksetsDefault = SimpleWorksetConfiguration.AllWorksets; | |
saveAsOptions.OverwriteExistingFile = true; | |
saveAsOptions.SetWorksharingOptions(worksharingSaveAsOptions); | |
doc.SaveAs(destModelPath, saveAsOptions); | |
doc.Close(false); | |
File.Delete(destModelPathTemp); | |
} | |
catch(Exception ex) | |
{ | |
System.Windows.MessageBox.Show(ex.Message); | |
} | |
} | |
private static void UiAppOnDialogBoxShowing(object sender, DialogBoxShowingEventArgs args) | |
{ | |
args.OverrideResult(1001); | |
args.Cancel(); | |
} | |
public static ElementId GetNavisView(Document document, string navisString) | |
{ | |
ICollection<Element> view3Ds = new FilteredElementCollector(document).OfClass(typeof(View3D)).ToElements(); | |
StringComparison comparer = StringComparison.OrdinalIgnoreCase; | |
foreach (View3D view3D in view3Ds) | |
{ | |
if (!(view3D.Name.ToString().IndexOf(navisString, comparer) == -1) && view3D.IsTemplate == false) | |
{ | |
return view3D.Id; | |
//break; | |
} | |
} | |
return null; | |
} | |
public static ElementId GetIFCView(Document document, string ifcString) | |
{ | |
// Get the first view | |
ICollection<Element> view3Ds = new FilteredElementCollector(document).OfClass(typeof(View3D)).ToElements(); | |
StringComparison comparer = StringComparison.OrdinalIgnoreCase; | |
foreach (View3D view3D in view3Ds) | |
{ | |
if (!(view3D.Name.ToString().IndexOf(ifcString, comparer) == -1) && view3D.IsTemplate == false) | |
{ | |
return view3D.Id; | |
//break; | |
} | |
} | |
return null; | |
} | |
public static void UnloadRevitLinks(string path) | |
{ | |
ModelPath location = ModelPathUtils.ConvertUserVisiblePathToModelPath(path); | |
TransmissionData transData = TransmissionData.ReadTransmissionData(location); | |
if (transData != null) | |
{ | |
ICollection<ElementId> externalReferences = transData.GetAllExternalFileReferenceIds(); | |
foreach (ElementId refId in externalReferences) | |
{ | |
ExternalFileReference extRef = transData.GetLastSavedReferenceData(refId); | |
if (extRef.ExternalFileReferenceType == ExternalFileReferenceType.RevitLink) | |
{ | |
transData.SetDesiredReferenceData(refId, extRef.GetPath(), extRef.PathType, false); | |
} | |
} | |
transData.IsTransmitted = true; | |
TransmissionData.WriteTransmissionData(location, transData); | |
} | |
} | |
public static Document OpenModel(string path, Application app) | |
{ | |
ModelPath modelPath = ModelPathUtils.ConvertUserVisiblePathToModelPath(path); | |
OpenOptions openOptions = new OpenOptions(); | |
openOptions.Audit = true; | |
openOptions.DetachFromCentralOption = DetachFromCentralOption.DetachAndPreserveWorksets; | |
return app.OpenDocumentFile(modelPath, openOptions); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Autodesk.Revit.UI; | |
using Autodesk.Revit.DB; | |
using Autodesk.Revit.Attributes; | |
using Autodesk.Revit.UI.Events; | |
namespace EEPRevitPlagin.EEPRPCommandModules.RevitServerExport | |
{ | |
[Transaction(TransactionMode.Manual)] | |
internal class RevitServerExportCommand : IExternalCommand | |
{ | |
public static UIApplication uiapp; | |
//public static UIDocument uidoc; | |
//public static Document doc; | |
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) | |
{ | |
uiapp = commandData.Application; | |
//uidoc = uiapp.ActiveUIDocument; | |
Autodesk.Revit.ApplicationServices.Application app = uiapp.Application; | |
//doc = uidoc.Document; | |
//something | |
//uiapp.DialogBoxShowing += UiAppOnDialogBoxShowing; | |
RevitServerExportWPF exportWPF = new RevitServerExportWPF(); | |
exportWPF.ShowDialog(); | |
return Result.Succeeded; | |
} | |
private static void UiAppOnDialogBoxShowing(object sender, DialogBoxShowingEventArgs args) | |
{ | |
var dialogId = args.DialogId; | |
var dialogType = args.GetType(); | |
bool isCanceled = args.Cancellable; | |
if (dialogId == "Dialog_Revit_DocWarnDialog") | |
{ | |
args.OverrideResult((int)TaskDialogResult.Ok); | |
} | |
else | |
{ | |
if (args.IsCancelled()) | |
{ | |
args.Cancel(); | |
} | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Window x:Class="EEPRevitPlagin.EEPRPCommandModules.RevitServerExport.RevitServerExportWPF" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |
xmlns:local="clr-namespace:EEPRevitPlagin.EEPRPCommandModules.RevitServerExport" | |
xmlns:re="clr-namespace:EEPRevitPlagin.SecondaryCommand.LangResources" | |
mc:Ignorable="d" WindowStyle="None" ResizeMode="CanResize" Width="761" Height="435" MouseDown="Window_MouseDown" MinWidth="900" MinHeight="500" WindowStartupLocation="CenterScreen"> | |
<Grid > | |
<Grid.ColumnDefinitions> | |
<ColumnDefinition> | |
</ColumnDefinition> | |
</Grid.ColumnDefinitions> | |
<Grid.RowDefinitions> | |
<RowDefinition Height="50"> | |
</RowDefinition> | |
<RowDefinition Height="150 | |
"> | |
</RowDefinition> | |
<RowDefinition/> | |
<RowDefinition Height="70"> | |
</RowDefinition> | |
</Grid.RowDefinitions> | |
<TextBlock x:Name="title" Text="{x:Static re:Language.Revit_Server_Export_Models}" FontSize="20" FontFamily="Calibri" FontWeight="Black" Margin="10" /> | |
<Label x:Name="serIP" Content="{x:Static re:Language.Server_IP}" HorizontalAlignment="Left" Margin="17,10,0,0" Grid.Row="1" VerticalAlignment="Top" Width="69" Height="26" /> | |
<Label x:Name="revVer" Content="{x:Static re:Language.Revit_Version}" HorizontalAlignment="Left" Margin="17,49,0,0" Grid.Row="1" VerticalAlignment="Top" /> | |
<TextBox x:Name="server" Text="192.168.1.10" HorizontalAlignment="Left" Margin="110,15,0,0" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Top" Width="199"/> | |
<TextBox x:Name="revision" Text="2021" HorizontalAlignment="Left" Margin="110,53,0,0" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Top" Width="199"/> | |
<DataGrid x:Name="ModelTable" Grid.Row="2" Margin="15,0,15,0" ItemsSource="{Binding}" SelectionMode="Single" /> | |
<Button x:Name="exB1" Content="{x:Static re:Language.Exit}" HorizontalAlignment="Left" Margin="674,45,0,0" Grid.Row="3" VerticalAlignment="Top" Width="83" Click="Button_Click" Background="#FFFF5050"/> | |
<Button x:Name="B1" Content="{x:Static re:Language.Сonnect_to_server}" HorizontalAlignment="Left" Margin="320,9,0,0" Grid.Row="1" VerticalAlignment="Top" Width="175" Click="Button_Click_1" Height="28"/> | |
<Label x:Name="proj" Content="{x:Static re:Language.Project}" HorizontalAlignment="Left" Margin="17,90,0,0" Grid.Row="1" VerticalAlignment="Top" Width="78"/> | |
<ComboBox x:Name="combo1" HorizontalAlignment="Left" Margin="110,92,0,0" Grid.Row="1" VerticalAlignment="Top" Width="199" SelectionChanged="combo1_SelectionChanged"/> | |
<Button x:Name="exB" Content="Export Selected Models" HorizontalAlignment="Left" Margin="400,45,0,0" Grid.Row="3" VerticalAlignment="Top" Width="201" Click="Export_Button" BorderBrush="#FF707070" Background="#FF9CFF50"/> | |
<Label x:Name="saveTo" Content="{x:Static re:Language.Save_as}" HorizontalAlignment="Left" Margin="17,12,0,0" Grid.Row="3" VerticalAlignment="Top" Width="88" Height="27" /> | |
<TextBox x:Name="folderTB" Text="C:\Navisworks models" HorizontalAlignment="Left" Margin="110,17,0,0" Grid.Row="3" TextWrapping="Wrap" VerticalAlignment="Top" Width="519" IsReadOnly="True"/> | |
<Label x:Name="navisView" Content="{x:Static re:Language.Navisworks_view_contains}" HorizontalAlignment="Left" Margin="500,10,0,0" Grid.Row="1" VerticalAlignment="Top" Width="216" Height="27" /> | |
<Label x:Name="ifcView" Content="{x:Static re:Language.IFC_view_contains}" HorizontalAlignment="Left" Margin="500,49,0,0" Grid.Row="1" VerticalAlignment="Top" Width="216" Height="27" /> | |
<TextBox x:Name="nwcTB" Text="Navisworks" HorizontalAlignment="Left" Margin="737,15,0,0" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Top" Width="148"/> | |
<TextBox x:Name="ifcTB" Text="ifc" HorizontalAlignment="Left" Margin="737,54,0,0" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Top" Width="148"/> | |
<CheckBox x:Name="checkBox1" Content="{x:Static re:Language.Combine_all_nwc_to_one_nwd_file}" HorizontalAlignment="Left" Margin="79,45,0,0" Grid.Row="3" VerticalAlignment="Top" Width="290"/> | |
<Button x:Name="B1_Copy" Content="{x:Static re:Language.Add_models_manually}" HorizontalAlignment="Left" Margin="320,48,0,0" Grid.Row="1" VerticalAlignment="Top" Width="175" Height="28" Click="B1_Copy_Click"/> | |
<Button x:Name="FolderB" Content="{x:Static re:Language.Choose_folder}" HorizontalAlignment="Left" Margin="634,16,0,0" Grid.Row="3" VerticalAlignment="Top" Width="123" Click="FolderB_Click"/> | |
</Grid> | |
</Window> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Windows; | |
using System.Windows.Controls; | |
using System.Windows.Input; | |
using System.Windows.Forms; | |
using System.Data; | |
using System.IO; | |
using Autodesk.Revit.DB; | |
using Autodesk.Navisworks.Api.Automation; | |
namespace EEPRevitPlagin.EEPRPCommandModules.RevitServerExport | |
{ | |
/// <summary> | |
/// Interaction logic for UserControl1.xaml | |
/// </summary> | |
public partial class RevitServerExportWPF : Window | |
{ | |
DataTable dt = new DataTable(); | |
public RevitServerExportWPF() | |
{ | |
InitializeComponent(); | |
ModelTable.CanUserAddRows = false; | |
} | |
private void Button_Click(object sender, RoutedEventArgs e) | |
{ | |
Close(); | |
} | |
private void Button_Click_1(object sender, RoutedEventArgs e) | |
{ | |
try | |
{ | |
if (IsValidRevision(revision.Text) && IsValidServer(server.Text)) | |
{ | |
TreeNode treeNode1 = new TreeNode(); | |
if (dt.Columns.Count == 0) | |
{ | |
dt.Columns.Add(new DataColumn("Model Name", typeof(string))); | |
dt.Columns.Add(new DataColumn("Model Path", typeof(string))); | |
dt.Columns.Add(new DataColumn("Export Revit files", typeof(bool))); | |
dt.Columns.Add(new DataColumn("Export to Navisworks", typeof(bool))); | |
dt.Columns.Add(new DataColumn("Export IFC files", typeof(bool))); | |
ModelTable.DataContext = dt; | |
} | |
RevitServerTools.GetSpecificFolder(treeNode1, "/|", server.Text, revision.Text); | |
ModelTable.CanUserAddRows = false; | |
ModelTable.CanUserDeleteRows = false; | |
System.Windows.Forms.TreeView treeView1 = new System.Windows.Forms.TreeView(); | |
treeView1.Nodes.Add(treeNode1); | |
foreach (TreeNode node in treeNode1.Nodes) | |
{ | |
if (node.Tag.ToString() == "Folder") | |
{ | |
combo1.Items.Add(node.Text); | |
addModelRow(dt, node, server.Text); | |
} | |
} | |
DataTable data = dt.Copy(); | |
ModelTable.DataContext = dt; | |
B1.Visibility = System.Windows.Visibility.Hidden; | |
} | |
else | |
{ | |
System.Windows.MessageBox.Show("The Server or the Revit revision are not true.\nPlease correct them and try again"); | |
} | |
} | |
catch (Exception ex) | |
{ | |
System.Windows.MessageBox.Show(ex.Message); | |
} | |
} | |
private void addModelRow(DataTable dt, TreeNode tNode, string server) | |
{ | |
foreach (TreeNode node in tNode.Nodes) | |
{ | |
if (node.Tag.ToString() == "Model") | |
{ | |
var row = dt.NewRow(); | |
row["Model Name"] = node.Text; | |
row["Model Path"] = GetModelPath(node.FullPath, server); | |
row["Export Revit files"] = false; | |
row["Export to Navisworks"] = false; | |
row["Export IFC files"] = false; | |
dt.Rows.Add(row); | |
} | |
else if (node.Tag.ToString() == "Folder") | |
{ | |
addModelRow(dt, node, server); | |
} | |
} | |
} | |
private void combo1_SelectionChanged(object sender, SelectionChangedEventArgs e) | |
{ | |
DataTable newData = dt.Copy(); | |
ModelTable.DataContext = newData; | |
for (int i = ModelTable.Items.Count - 1; i >= 0; i--) | |
{ | |
DataRowView dataRow = (DataRowView)ModelTable.Items[i]; | |
string item = (string)dataRow.Row.ItemArray[1]; | |
if (!item.Contains(e.AddedItems[0].ToString())) | |
{ | |
dataRow.Delete(); | |
} | |
} | |
} | |
private bool IsValidRevision(string str) | |
{ | |
string[] validRevisions = { "2018", "2019", "2020", "2021", "2022", "2023", "2024" }; | |
if (validRevisions.Contains(str)) | |
{ | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
private bool IsValidServer(string str) | |
{ | |
System.Net.IPAddress ipAddress = null; | |
return System.Net.IPAddress.TryParse(str, out ipAddress); | |
} | |
private string GetModelPath(string str, string server) | |
{ | |
string res = str.Replace('\\', '/'); | |
return res.Replace("Server", string.Format("RSN://{0}", server)); | |
} | |
private void Export_Button(object sender, RoutedEventArgs e) | |
{ | |
List<string> navisFiles = new List<string>(); | |
string nwcString = nwcTB.Text; | |
string ifcString = ifcTB.Text; | |
foreach (DataRowView row in ModelTable.Items) | |
{ | |
if ((bool)row[2] || (bool)row[3] || (bool)row[4]) | |
{ | |
ExportModels.ExportrvtModelFromServer(row[1].ToString(), folderTB.Text, RevitServerExportCommand.uiapp.Application); | |
string modelPath = folderTB.Text + @"\" + row[0].ToString(); | |
if ((bool)row[3] || (bool)row[4]) | |
{ | |
Document doc = ExportModels.OpenModel(modelPath, RevitServerExportCommand.uiapp.Application); | |
if ((bool)row[3]) | |
{ | |
//export to navis | |
NavisworksExportOptions navisworksExportOptions = new NavisworksExportOptions(); | |
navisworksExportOptions.ConvertElementProperties = true; | |
navisworksExportOptions.ConvertLinkedCADFormats = false; | |
navisworksExportOptions.Coordinates = NavisworksCoordinates.Shared; | |
navisworksExportOptions.DivideFileIntoLevels = false; | |
navisworksExportOptions.ExportElementIds = true; | |
navisworksExportOptions.ExportLinks = false; | |
// the host element export | |
navisworksExportOptions.ExportParts = false; | |
navisworksExportOptions.ExportRoomAsAttribute = false; | |
navisworksExportOptions.ExportRoomGeometry = false; | |
navisworksExportOptions.ExportScope = NavisworksExportScope.View; | |
if (ExportModels.GetNavisView(doc, nwcString) == null) | |
{ | |
System.Windows.MessageBox.Show("No Navisworks view in " + (string)row[0]); | |
continue; | |
} | |
navisworksExportOptions.ViewId = ExportModels.GetNavisView(doc, nwcString); | |
navisworksExportOptions.ExportUrls = false; | |
navisworksExportOptions.FacetingFactor = 1; | |
navisworksExportOptions.FindMissingMaterials = false; | |
navisworksExportOptions.Parameters = NavisworksParameters.All; | |
doc.Export(folderTB.Text, row[0].ToString().Replace(".rvt", ".nwc"), navisworksExportOptions); | |
navisFiles.Add(folderTB.Text + @"\" + row[0].ToString().Replace(".rvt", ".nwc")); | |
} | |
if ((bool)row[4]) | |
{ | |
using (Transaction transaction = new Transaction(doc)) | |
{ | |
transaction.Start("IFC Export"); | |
IFCExportOptions ifcExportOptions = new IFCExportOptions(); | |
if (ExportModels.GetIFCView(doc, ifcString) == null) | |
{ | |
System.Windows.MessageBox.Show("No IFC view in " + (string)row[0]); | |
continue; | |
} | |
ifcExportOptions.FilterViewId = ExportModels.GetIFCView(doc, ifcString); | |
ifcExportOptions.FileVersion = IFCVersion.IFC2x3; | |
ifcExportOptions.ExportBaseQuantities = true; | |
ifcExportOptions.WallAndColumnSplitting = true; | |
ifcExportOptions.SpaceBoundaryLevel = 0; | |
ifcExportOptions.AddOption("ExportAnnotations ", "false"); | |
ifcExportOptions.AddOption("Export2DElements", "false"); | |
ifcExportOptions.AddOption("ExportSpecificSchedules", "false"); | |
ifcExportOptions.AddOption("TessellationLevelOfDetail", "0,5"); | |
/* | |
ifcExportOptions.AddOption("ExportInternalRevitPropertySets", revitInternalPset); | |
ifcExportOptions.AddOption("ExportIFCCommonPropertySets", "true"); | |
ifcExportOptions.AddOption("ExportAnnotations ", "true"); | |
ifcExportOptions.AddOption("SpaceBoundaries ", "0"); | |
ifcExportOptions.AddOption("ExportRoomsInView", "false"); | |
ifcExportOptions.AddOption("Use2DRoomBoundaryForVolume ", "true"); | |
ifcExportOptions.AddOption("UseFamilyAndTypeNameForReference ", "true"); | |
ifcExportOptions.AddOption("Export2DElements", "false"); | |
ifcExportOptions.AddOption("ExportPartsAsBuildingElements", "false"); | |
ifcExportOptions.AddOption("ExportBoundingBox", "false"); | |
ifcExportOptions.AddOption("ExportSolidModelRep", "true"); | |
ifcExportOptions.AddOption("ExportSchedulesAsPsets", "false"); | |
ifcExportOptions.AddOption("ExportSpecificSchedules", "false"); | |
ifcExportOptions.AddOption("ExportLinkedFiles", "false"); | |
ifcExportOptions.AddOption("IncludeSiteElevation", "true"); | |
ifcExportOptions.AddOption("StoreIFCGUID", "true"); | |
ifcExportOptions.AddOption("VisibleElementsOfCurrentView ", "true"); | |
ifcExportOptions.AddOption("UseActiveViewGeometry", "true"); | |
ifcExportOptions.AddOption("TessellationLevelOfDetail", "0,5"); | |
ifcExportOptions.AddOption("ExportUserDefinedPsets", userDefPsetBool); | |
ifcExportOptions.AddOption("ExportUserDefinedPsetsFileName", userDefinedPset); | |
ifcExportOptions.AddOption("ActivePhase", phaseString); | |
ifcExportOptions.AddOption("SitePlacement", IN[4]); | |
ifcExportOptions.AddOption("ClassificationName","x"); | |
*/ | |
doc.Export(folderTB.Text, row[0].ToString().Replace(".rvt", ".ifc"), ifcExportOptions); | |
transaction.Commit(); | |
} | |
} | |
doc.Close(false); | |
} | |
if (!(bool)row[2]) | |
{ | |
File.Delete(modelPath); | |
} | |
} | |
} | |
if (checkBox1.IsChecked == true && navisFiles != null) | |
{ | |
NavisworksApplication navisworks = new NavisworksApplication(); | |
navisworks.DisableProgress(); | |
navisworks.Visible = false; | |
navisworks.OpenFile(navisFiles[0]); | |
for (int i = 1; i < navisFiles.Count; i++) | |
{ | |
navisworks.AppendFile(navisFiles[i]); | |
} | |
navisworks.SaveFile(folderTB.Text + @"\All.nwd"); | |
navisworks.Dispose(); | |
} | |
} | |
private void Window_MouseDown(object sender, MouseButtonEventArgs e) | |
{ | |
if (e.ChangedButton == MouseButton.Left) | |
this.DragMove(); | |
} | |
private void B1_Copy_Click(object sender, RoutedEventArgs e) | |
{ | |
string models = null; | |
using (OpenFileDialog dlg = new OpenFileDialog()) | |
{ | |
dlg.Filter = "Project Models List (*.lpm)|*.lpm"; | |
dlg.Title = "Choose the text files with the models"; | |
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) | |
{ | |
string filePath = dlg.FileName; | |
combo1.Items.Add(Path.GetFileNameWithoutExtension( filePath)); | |
Stream fileStream = dlg.OpenFile(); | |
StreamReader streamReader = new StreamReader(fileStream); | |
models = streamReader.ReadToEnd(); | |
} | |
} | |
string[] modelsPaths = models.Split('\n'); | |
foreach (string modelPath in modelsPaths) | |
{ | |
if (dt.Columns.Count == 0) | |
{ | |
dt.Columns.Add(new DataColumn("Model Name", typeof(string))); | |
dt.Columns.Add(new DataColumn("Model Path", typeof(string))); | |
dt.Columns.Add(new DataColumn("Export Revit files", typeof(bool))); | |
dt.Columns.Add(new DataColumn("Export to Navisworks", typeof(bool))); | |
dt.Columns.Add(new DataColumn("Export IFC files", typeof(bool))); | |
DataTable data = dt.Copy(); | |
ModelTable.DataContext = dt; | |
} | |
var row = dt.NewRow(); | |
row["Model Name"] = System.IO.Path.GetFileName(modelPath.Trim()); | |
row["Model Path"] = modelPath.Trim(); | |
row["Export Revit files"] = false; | |
row["Export to Navisworks"] = false; | |
row["Export IFC files"] = false; | |
dt.Rows.Add(row); | |
} | |
} | |
private void ModelTable_AddingNewItem(object sender, AddingNewItemEventArgs e) | |
{ | |
} | |
private void Button_Click_2(object sender, RoutedEventArgs e) | |
{ | |
string modelPath = @"C:\navis models\temp\a_2125_VARSHAVA_RD_AR.rvt"; | |
Document doc = ExportModels.OpenModel(modelPath, RevitServerExportCommand.uiapp.Application); | |
} | |
private void FolderB_Click(object sender, RoutedEventArgs e) | |
{ | |
using (var fbd = new FolderBrowserDialog()) | |
{ | |
fbd.Description = "Select a folder to export the models to:"; | |
DialogResult result = fbd.ShowDialog(); | |
if (result == System.Windows.Forms.DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath)) | |
{ | |
folderTB.Text = fbd.SelectedPath; | |
} | |
} | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Net; | |
using System.Runtime.Serialization.Json; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Xml; | |
using System.Windows.Forms; | |
namespace EEPRevitPlagin.EEPRPCommandModules.RevitServerExport | |
{ | |
public class RevitServerTools | |
{ | |
public static TreeView GetFoldersAndFiles(string sreverNameOrIP, string revitVersion) | |
{ | |
//Example: | |
//TreeNode treeNode = EEPRevitPlagin.SecondaryСommand.RevitServerTools.GetFoldersAndFiles("192.168.1.10", "2021").Nodes[0]; | |
//treeView1.Nodes.Add((TreeNode)treeNode.Clone()); | |
try | |
{ | |
TreeView treeView = new TreeView(); | |
TreeNode root = treeView.Nodes.Add("Server"); | |
AddContents(root, "/|", sreverNameOrIP, revitVersion); | |
return treeView; | |
} | |
catch | |
{ | |
return null; | |
} | |
} | |
private static void AddContents(TreeNode parentNode, string path, string sreverNameOrIP, string revitVersion) | |
{ | |
XmlDictionaryReader reader = GetResponse(path + "/contents", sreverNameOrIP, revitVersion); | |
while (reader.Read()) | |
{ | |
if (reader.NodeType == XmlNodeType.Element && reader.Name == "Folders") | |
{ | |
while (reader.Read()) | |
{ | |
if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "Folders") | |
break; | |
if (reader.NodeType == XmlNodeType.Element && reader.Name == "Name") | |
{ | |
reader.Read(); | |
string content = reader.ReadContentAsString(); | |
TreeNode node = parentNode.Nodes.Add(content); | |
node.Tag = "Folder"; | |
AddContents(node, path + "|" + content, sreverNameOrIP, revitVersion); | |
} | |
} | |
} | |
else if (reader.NodeType == XmlNodeType.Element && reader.Name == "Models") | |
{ | |
while (reader.Read()) | |
{ | |
if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "Models") | |
break; | |
if (reader.NodeType == XmlNodeType.Element && reader.Name == "Name") | |
{ | |
reader.Read(); | |
TreeNode node = parentNode.Nodes.Add(reader.Value); | |
node.Tag = "Model"; | |
} | |
} | |
} | |
} | |
reader.Close(); | |
} | |
private static XmlDictionaryReader GetResponse(string info, string sreverNameOrIP, string revitVersion) | |
{ | |
WebRequest request = WebRequest.Create("http://" + sreverNameOrIP + string.Format("/RevitServerAdminRESTService{0}/AdminRESTService.svc", revitVersion) + info); | |
request.Method = "GET"; | |
request.Headers.Add("User-Name", Environment.UserName); | |
request.Headers.Add("User-Machine-Name", Environment.MachineName); | |
request.Headers.Add("Operation-GUID", Guid.NewGuid().ToString()); | |
XmlDictionaryReaderQuotas quotas = new XmlDictionaryReaderQuotas(); | |
XmlDictionaryReader jsonReader = JsonReaderWriterFactory.CreateJsonReader(request.GetResponse().GetResponseStream(), quotas); | |
return jsonReader; | |
} | |
public static void GetSpecificFolder(TreeNode parentNode, string path, string sreverNameOrIP, string revitVersion) | |
{ | |
//Example: | |
//TreeNode treeNode1 = new TreeNode(); | |
//EEPRevitPlagin.SecondaryСommand.RevitServerTools.GetSpecificFolder(treeNode1, "/|21.16 НДЦ|", "192.168.1.10", "2021"); | |
//treeView1.Nodes.Add((TreeNode)treeNode1.Clone()); | |
if (path == "/|") | |
{ | |
parentNode.Text = "Server"; | |
} | |
else | |
{ | |
parentNode.Text = path.Replace('|', '/'); | |
} | |
XmlDictionaryReader reader = GetResponse(path + "/contents", sreverNameOrIP, revitVersion); | |
while (reader.Read()) | |
{ | |
if (reader.NodeType == XmlNodeType.Element && reader.Name == "Folders") | |
{ | |
while (reader.Read()) | |
{ | |
if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "Folders") | |
break; | |
if (reader.NodeType == XmlNodeType.Element && reader.Name == "Name") | |
{ | |
reader.Read(); | |
string content = reader.ReadContentAsString(); | |
TreeNode node = parentNode.Nodes.Add(content); | |
node.Tag = "Folder"; | |
AddContents(node, path + "|" + content, sreverNameOrIP, revitVersion); | |
} | |
} | |
} | |
else if (reader.NodeType == XmlNodeType.Element && reader.Name == "Models") | |
{ | |
while (reader.Read()) | |
{ | |
if (reader.NodeType == XmlNodeType.EndElement && reader.Name == "Models") | |
break; | |
if (reader.NodeType == XmlNodeType.Element && reader.Name == "Name") | |
{ | |
reader.Read(); | |
TreeNode node = parentNode.Nodes.Add(reader.Value); | |
node.Tag = "Model"; | |
} | |
} | |
} | |
} | |
reader.Close(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment