158 lines
6.0 KiB
C#
158 lines
6.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Autodesk.Revit.DB;
|
|
using Autodesk.Revit.UI;
|
|
using CDM.Interop.Revit.CDMComponent;
|
|
|
|
namespace CDM.Interop.Revit
|
|
{
|
|
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
|
|
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
|
|
class CmdRevitToCDM : Autodesk.Revit.UI.IExternalCommand
|
|
{
|
|
static string AddInPath = typeof(CmdRevitToCDM).Assembly.Location;
|
|
|
|
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
|
|
{
|
|
Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application;
|
|
UIDocument uidoc = commandData.Application.ActiveUIDocument;
|
|
Document doc = uidoc.Document;
|
|
//string AddInPath = typeof(CmdRevitToCDM).Assembly.Location;
|
|
//string dirAssembly = Path.GetDirectoryName(AddInPath);
|
|
|
|
VistaFolderBrowserDialog dialog = new VistaFolderBrowserDialog
|
|
{
|
|
Multiselect = false
|
|
};
|
|
dialog.ShowDialog();
|
|
if (dialog.SelectedPath == null)
|
|
{
|
|
return Result.Cancelled;
|
|
}
|
|
string path = dialog.SelectedPath;
|
|
//View3D view3d;
|
|
//using (Transaction ts = new Transaction(doc, "3dview"))
|
|
//{
|
|
// ts.Start();
|
|
// ViewFamilyType viewtype = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType))
|
|
// .Cast<ViewFamilyType>()
|
|
// .FirstOrDefault<ViewFamilyType>(
|
|
// x => ViewFamily.ThreeDimensional
|
|
// == x.ViewFamily);
|
|
// view3d = View3D.CreateIsometric(doc, viewtype.Id);
|
|
|
|
// ts.Commit();
|
|
|
|
//}
|
|
//uidoc.ActiveView = view3d;
|
|
View3D v3d = null;
|
|
var v3ds = new FilteredElementCollector(doc).OfClass(typeof(View3D));
|
|
foreach (View3D view in v3ds)
|
|
{
|
|
if ("{三维}".Equals(view.Name))
|
|
{
|
|
v3d = view;
|
|
break;
|
|
}
|
|
}
|
|
|
|
uidoc.ActiveView = v3d;
|
|
|
|
var levels = new FilteredElementCollector(doc).OfClass(typeof(Level)).ToElements();
|
|
|
|
#region 柱
|
|
|
|
List<CDMColumn> cdmColumns = Utility.ColumnUtil.GetColumnCDM(doc, levels);
|
|
|
|
if (cdmColumns.Count > 0)
|
|
{
|
|
string sourceColumnFile = Path.GetDirectoryName(AddInPath) + "\\CDM\\xlsx\\柱.xlsx";
|
|
string destColumnsDirectory = path + "\\结构柱";
|
|
if (!Directory.Exists(destColumnsDirectory))
|
|
{
|
|
DirectoryInfo directoryInfo = new DirectoryInfo(destColumnsDirectory);
|
|
directoryInfo.Create();
|
|
}
|
|
CDMComponent2Excel.CDMColumnsToExcel(cdmColumns, sourceColumnFile, destColumnsDirectory);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 板
|
|
|
|
List<CDMFloor> cdmFloors = Utility.FloorUtil.GetFloorsCDM(doc, levels, v3d);
|
|
if (cdmFloors.Count > 0)
|
|
{
|
|
string sourceFloorFile = Path.GetDirectoryName(AddInPath)+ "\\CDM\\xlsx\\楼板.xlsx";
|
|
//string sourceFloorFile = Path.GetDirectoryName(AddInPath) + "\\xlsx\\楼板.xlsx";
|
|
string destFloorsPath = path + "\\结构板";
|
|
if (!Directory.Exists(destFloorsPath))
|
|
{
|
|
DirectoryInfo directoryInfo = new DirectoryInfo(destFloorsPath);
|
|
directoryInfo.Create();
|
|
}
|
|
CDMComponent2Excel.CDMFloorsToExcel(cdmFloors, sourceFloorFile, destFloorsPath);
|
|
}
|
|
#endregion
|
|
|
|
#region 梁
|
|
|
|
List<CDMBeam> cdmBeams = Utility.BeamUtil.GetBeamsCDM(doc, levels);
|
|
|
|
if (cdmBeams.Count > 0)
|
|
{
|
|
string sourceBeamFile = Path.GetDirectoryName(AddInPath) + "\\CDM\\xlsx\\梁.xlsx";
|
|
string destBeamsDirectory = path + "\\结构梁";
|
|
if (!Directory.Exists(destBeamsDirectory))
|
|
{
|
|
DirectoryInfo directoryInfo = new DirectoryInfo(destBeamsDirectory);
|
|
directoryInfo.Create();
|
|
}
|
|
CDMComponent2Excel.CDMBeamsToExcel(cdmBeams, sourceBeamFile, destBeamsDirectory);
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
#region 墙
|
|
|
|
//List<CDMWall> cdmWalls = new List<CDMWall>();
|
|
//cdmWalls = Utility.WallUtil.GetWallsCDM(uidoc, levels);
|
|
//string sourceWallFile = Path.GetDirectoryName(AddInPath) + "\\xlsx\\现浇剪力墙.xls";
|
|
//destPath = path + "\\现浇剪力墙";
|
|
//if (!Directory.Exists(destPath))
|
|
//{
|
|
// DirectoryInfo directoryInfo = new DirectoryInfo(destPath);
|
|
// directoryInfo.Create();
|
|
//}
|
|
//WriteCDMUtil.WriteCDMWallsToExcel(cdmWalls, sourceWallFile, destPath);
|
|
|
|
#endregion
|
|
|
|
#region 楼梯
|
|
|
|
List<CDMStairs> cdmStairs = Utility.StairsUtil.GetStairsCDM(doc, levels, v3d);
|
|
|
|
if (cdmStairs.Count > 0)
|
|
{
|
|
string sourceStairsFile = Path.GetDirectoryName(AddInPath) + "\\CDM\\xlsx\\楼梯.xlsx";
|
|
string destStairsPath = path + "\\楼梯";
|
|
if (!Directory.Exists(destStairsPath))
|
|
{
|
|
DirectoryInfo directoryInfo = new DirectoryInfo(destStairsPath);
|
|
directoryInfo.Create();
|
|
}
|
|
CDMComponent2Excel.CDMStairsToExcel(cdmStairs, sourceStairsFile, destStairsPath);
|
|
}
|
|
|
|
#endregion
|
|
|
|
return Result.Succeeded;
|
|
}
|
|
}
|
|
}
|