I'm looking for a way to access a linked Autocad File using the Revit API. I have SnoopDB already installed which is a huge help.
I found this which was also another step forward however I'm not able to get the points or lines of the file.
I've explored a bit and have found that I am able to access the filename and then get the hashcode of the cadlink but after that, idk how to get the goemetry within.
Any and all help is appreciated.
here is what I have so far:
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;
Selection sel = uidoc.Selection;
using (Transaction tx = new Transaction(doc))
{
try
{
tx.Start("Tracing Cad");
Reference refer = sel.PickObject(ObjectType.Element, "Select a CAD Link");
Element elem = doc.GetElement(refer);
GeometryElement geoElem = elem.get_Geometry(new Options());
Debug.WriteLine("elem.Category.Name: " + elem.Category.Name); // can grab title of CAD
foreach (GeometryObject geoObj in geoElem)
{
GeometryInstance instance = geoObj as GeometryInstance;
foreach (GeometryObject instObj in instance.SymbolGeometry)
{
Debug.WriteLine("geoObj.GraphicsStyleId: " + geoObj.GraphicsStyleId);
Debug.WriteLine("geoObj.GetHashCode(): " + geoObj.GetHashCode()); // gets hashcode of selected cad link
if (instObj.GetType().Name == "PolyLine")
// if (instObj.GetType().Name == "GeometryInstance")
{
}
else
{
Debug.WriteLine("there are no blocks found in this CAD File");
}
}
}
tx.Commit();
} catch (Exception e )
{
Debug.WriteLine(e.StackTrace);
}
The Revit API does not provide any access to the internals of a linked CAD file.
All you can do is implement some AutoCAD.NET code to read the DWG file itself, provided you have access to the DWG and AutoCAD is installed.
The Building Coder shares some samples showing how to launch AutoCAD within a Revit add-in.