添加项目文件。
This commit is contained in:
173
CDMUtil/CmdCDMToRevit.cs
Normal file
173
CDMUtil/CmdCDMToRevit.cs
Normal file
@@ -0,0 +1,173 @@
|
||||
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.Utility;
|
||||
using CDM.Interop.Revit.RevitCompoent;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace CDM.Interop.Revit
|
||||
{
|
||||
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
|
||||
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
|
||||
class CmdCDMToRevit : Autodesk.Revit.UI.IExternalCommand
|
||||
{
|
||||
static string AddInPath = typeof(CmdCDMToRevit).Assembly.Location;
|
||||
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
|
||||
{
|
||||
Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application;
|
||||
Document doc = commandData.Application.ActiveUIDocument.Document;
|
||||
Level level = null;
|
||||
Family family = null;
|
||||
IList<Element> levels = new FilteredElementCollector(doc).OfClass(typeof(Level)).ToElements();
|
||||
foreach (Level l in levels)
|
||||
{
|
||||
//if (l.get_Parameter(BuiltInParameter.LEVEL_ELEV).AsDouble() == 0)
|
||||
if (l.ProjectElevation == 0)
|
||||
{
|
||||
level = l;
|
||||
break;
|
||||
}
|
||||
}
|
||||
List<RevitColumn> columns = new List<RevitColumn>();
|
||||
List<RevitBeam> beams = new List<RevitBeam>();
|
||||
List<RevitWall> walls = new List<RevitWall>();
|
||||
List<RevitFloor> floors = new List<RevitFloor>();
|
||||
List<RevitStairs> stairs = new List<RevitStairs>();
|
||||
|
||||
string filter = "读取CDM集(*.xlsx)|*.xlsx";
|
||||
OpenFileDialog openDialog = new OpenFileDialog();
|
||||
openDialog.Multiselect = true;
|
||||
openDialog.Filter = filter;
|
||||
openDialog.Title = "选择CDM文件";
|
||||
openDialog.ShowDialog();
|
||||
|
||||
string[] paths = openDialog.FileNames;
|
||||
if (paths.Count() == 0)
|
||||
{
|
||||
return Result.Cancelled;
|
||||
}
|
||||
|
||||
#region 备用
|
||||
//List<FilePathInfo> list = new List<FilePathInfo>();
|
||||
//for (int i = 0; i < paths.Count(); i++)
|
||||
//{
|
||||
// string filename = System.IO.Path.GetFileNameWithoutExtension(paths[i]);
|
||||
// FilePathInfo fpi = new FilePathInfo()
|
||||
// {
|
||||
// FileName = filename,
|
||||
// Path = paths[i],
|
||||
// };
|
||||
// if (filename.Contains("A21005"))
|
||||
// {
|
||||
// fpi.Category = "墙";
|
||||
// }
|
||||
// else if (filename.Contains("A21002"))
|
||||
// {
|
||||
// fpi.Category = "梁";
|
||||
// }
|
||||
// else if (filename.Contains("A21003"))
|
||||
// {
|
||||
// fpi.Category = "板";
|
||||
// }
|
||||
// else if (filename.Contains("A21001"))
|
||||
// {
|
||||
// fpi.Category = "柱";
|
||||
// }
|
||||
// else if (filename.Contains("A21008"))
|
||||
// {
|
||||
// fpi.Category = "楼梯";
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// fpi.Category = "未知";
|
||||
// }
|
||||
// list.Add(fpi);
|
||||
//}
|
||||
|
||||
#endregion
|
||||
|
||||
foreach (var path in paths)
|
||||
{
|
||||
if (path.Contains("A21003"))
|
||||
{
|
||||
RevitFloor floor = new RevitFloor(path);
|
||||
floors.Add(floor);
|
||||
}
|
||||
else if (path.Contains("A21005"))
|
||||
{
|
||||
RevitWall wall = new RevitWall();
|
||||
|
||||
walls.Add(wall);
|
||||
}
|
||||
else if (path.Contains("A21002"))
|
||||
{
|
||||
RevitBeam beam = new RevitBeam(path);
|
||||
beams.Add(beam);
|
||||
}
|
||||
else if (path.Contains("A21001"))
|
||||
{
|
||||
RevitColumn column = new RevitColumn(path);
|
||||
columns.Add(column);
|
||||
}
|
||||
if (path.Contains("A21004"))
|
||||
{
|
||||
RevitStairs stair = new RevitStairs(path);
|
||||
stairs.Add(stair);
|
||||
}
|
||||
}
|
||||
if (columns.Count > 0)
|
||||
{
|
||||
string columnPath = Path.GetDirectoryName(AddInPath)+ "\\CDM\\rfa\\矩形柱.rfa";
|
||||
using (Document famdoc = app.OpenDocumentFile(columnPath))
|
||||
{
|
||||
family = famdoc.LoadFamily(doc, new FamilyLoadOptions());
|
||||
}
|
||||
ColumnUtil.PlaceColumns(doc, family, columns, level);
|
||||
}
|
||||
if (beams.Count > 0)
|
||||
{
|
||||
string beamPath = Path.GetDirectoryName(AddInPath) + "\\CDM\\rfa\\矩形梁.rfa";
|
||||
using (Document famdoc = app.OpenDocumentFile(beamPath))
|
||||
{
|
||||
family = famdoc.LoadFamily(doc, new FamilyLoadOptions());
|
||||
}
|
||||
BeamUtil.PlaceBeams(doc, family, beams, level);
|
||||
}
|
||||
if (floors.Count > 0)
|
||||
{
|
||||
FloorUtil.PlaceFloors(doc, floors, level);
|
||||
}
|
||||
if (stairs.Count > 0)
|
||||
{
|
||||
StairsUtil.PlaceStairs(doc, stairs, level);
|
||||
}
|
||||
//RevitWallUtil.PlaceWalls(doc,walls, level);
|
||||
|
||||
|
||||
|
||||
return Result.Succeeded;
|
||||
}
|
||||
}
|
||||
class FamilyLoadOptions : IFamilyLoadOptions
|
||||
{
|
||||
public bool OnFamilyFound(bool familyInUse, out bool overwriteParameterValues)
|
||||
{
|
||||
|
||||
overwriteParameterValues = true;
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public bool OnSharedFamilyFound(Family sharedFamily, bool familyInUse, out FamilySource source, out bool overwriteParameterValues)
|
||||
{
|
||||
source = FamilySource.Project;
|
||||
overwriteParameterValues = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user