Message 1 of 4
Import AutoCAD data to Revit.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I import the AutoCAD Data to Revit. And I store it in different lists for further processing. I am getting the Layer wise lines and Polylines of Doors, Windows, Walls, etc. but I am not able to store the Blocks of particular name from AutoCAD file in Revit.
Here is my code
ElementId mDwgElemId = null;
List<PolyLine> wallPolyLineList = null;
List<PolyLine> windowPolyLineList = null;
List<PolyLine> doorPolyLineList = null;
private void SelectDWGFile(Autodesk.Revit.DB.Document document)
{
bool imported = false;
DWGImportOptions dwgImportOption = new DWGImportOptions();
dwgImportOption.ColorMode = Autodesk.Revit.DB.ImportColorMode.Inverted;
dwgImportOption.CustomScale = 0.0;
dwgImportOption.Unit = Autodesk.Revit.DB.ImportUnit.Millimeter;
dwgImportOption.OrientToView = true;
dwgImportOption.Placement = Autodesk.Revit.DB.ImportPlacement.Origin;
dwgImportOption.ThisViewOnly = false;
Autodesk.Revit.DB.View view = document.ActiveView;
// Prompt the user to select a DWG file using a file dialog
System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog();
openFileDialog.Filter = "AutoCAD DWG Files|*.dwg";
openFileDialog.Title = "Select AutoCAD DWG File";
String m_importFileFullName = null;
if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string selectedFilePath = openFileDialog.FileName;
m_importFileFullName = selectedFilePath;
}
Transaction transaction = new Transaction(document);
transaction.SetName("Import");
transaction.Start();
imported = document.Import(m_importFileFullName, dwgImportOption, view, out mDwgElementId);
document.Regenerate();
mUI_Document.RefreshActiveView();
transaction.Commit();
}
private void ImportAutoCADFileData(Autodesk.Revit.DB.Document document, ElementId m_dwgElementId, ref List<PolyLine> wallPolyLineList, ref List<PolyLine> windowPolyLineList, ref List<PolyLine> doorPolyLineList)
{
Transaction transaction = new Transaction(document);
transaction.SetName("ImportData");
transaction.Start();
ImportInstance dwg = document.GetElement(m_dwgElementId) as ImportInstance;
wallPolyLineList = new List<PolyLine>();
windowPolyLineList = new List<PolyLine>();
doorPolyLineList = new List<PolyLine>();
string drawingInstanceName = dwg.Name;
foreach (GeometryObject geometryObj in dwg.get_Geometry(new Options()))
{
if (geometryObj is GeometryInstance)
{
GeometryInstance dwgInstance = geometryObj as GeometryInstance;
foreach (GeometryObject blockObject in dwgInstance.SymbolGeometry)
{
GraphicsStyle gStyle = document.GetElement(blockObject.GraphicsStyleId) as GraphicsStyle;
string layerName = gStyle.GraphicsStyleCategory.Name;
if (layerName == "Wall_Main")
{
if (blockObject is PolyLine)
{
PolyLine polyLine = blockObject as PolyLine;
wallPolyLineList.Add(polyLine);
//floorPolyLineList.Add(polyLine);
}
}
else if (layerName == "Wall_Shop")
{
if (blockObject is PolyLine)
{
PolyLine polyLine = blockObject as PolyLine;
wallPolyLineList.Add(polyLine);
}
}
else if (layerName == "Stair_FloorCut")
{
if (blockObject is PolyLine)
{
PolyLine polyLine = blockObject as PolyLine;
wallPolyLineList.Add(polyLine);
floorCutPolyLineList.Add(polyLine);
}
}
else if (layerName == "Poarch_Area")
{
if (blockObject is PolyLine)
{
PolyLine polyLine = blockObject as PolyLine;
wallPolyLineList.Add(polyLine);
}
}
else if (layerName == "Window")
{
if (blockObject is PolyLine)
{
PolyLine polyLine = blockObject as PolyLine;
windowPolyLineList.Add(polyLine);
}
}
else if (layerName == "Door_House")
{
if (blockObject is PolyLine)
{
PolyLine polyLine = blockObject as PolyLine;
doorPolyLineList.Add(polyLine);
}
}
else if (blockObject is PolyLine)
{
PolyLine polyLine = blockObject as PolyLine;
wallPolyLineList.Add(polyLine);
}
}
}
}
transaction.Commit();
}