- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I have a CAD Drawing in DGN format that I have imported into a Revit Project. The drawing consists of columns, walls, beams, slabs, etc. My end goal is to create an API using C# to automatically create those elements in Revit from the CAD Drawing but i would like to start with columns. The following picture shows my Imported DGN drawing in Revit that I imported using the Insert > Import > Import CAD tools:
As with any other imported CAD drawing, all the geometrical objects in the imported CAD drawing is still joined together as one as shown below:
After doing some study, I would like to do the following workflow in order to achieve my goal:
1. Filter for the columns by its specific Layer.
After using the RevitLookup, I understand that the imported CAD drawing is of the ImportInstance Class and by going deeper, I can look at individual lines along with their GraphicStyleCategory which signify their Layer information. My question is: How to retrieve all of the geometrical objects (e.g. Line) from the imported CAD drawing and then filter based on the layer?
I saw an answer on an old thread: https://forums.autodesk.com/t5/revit-api-forum/how-to-create-beams-by-lines-from-dwg-linked-into-rev... but they were using PickObjects to pick individual elements in the imported CAD drawing. What I want to do is to retrieve all elements simultaneously.
I tried the following code to retrieve individual Line objects along with the layer name (GraphicStyleCategory.Name) but a Null reference was thrown stating that the GeometryElement is Null:
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Document doc = uidoc.Document;
Options geoOptions = uiapp.Application.Create.NewGeometryOptions();
// Filter for all elements
FilteredElementCollector collector = new FilteredElementCollector(doc).WhereElementIsNotElementType();
StringBuilder sb = new StringBuilder();
foreach (Element elem in collector)
{
GeometryElement geomElem = elem.get_Geometry(geoOptions);
foreach (GeometryObject geomObj in geomElem)
{
if (geomObj is Line)
{
Line line = geomObj as Line;
GraphicsStyle gStyle = doc.GetElement(line.GraphicsStyleId) as GraphicsStyle;
sb.AppendLine(line.GraphicsStyleId.ToString() + "\t" + gStyle.GraphicsStyleCategory.Name+"\t"+line.Length.ToString());
}
}
}
Am I doing this correctly by using FilteredElementCollector to filter for all the elements from the imported CAD? Or is there other ways to do it?
2. Get the Column centroid/Location Point.
If I am able to filter for the column lines based on its layer, I would need the centroid of the column to create a new FamilyInstance for the column by using Document.Create.NewFamilyInstance Method (XYZ, FamilySymbol, Level, StructuralType). How to get the centroid information of each column in the imported DGN drawing? Should I get the Vertices of the column elements first? How can I achieve that?
3. Finally, Create the Columns by using Document.Create.NewFamilyInstance Method (XYZ, FamilySymbol, Level, StructuralType) Method.
That is all of what I can think for now. I would also like to receive some advice regarding this workflow because there might be another ways to create columns in Revit from imported CAD drawing that maybe I am not aware of.
Thank you
Solved! Go to Solution.