Cad files are files used by architects to draw buildings sketches. The files are with the extension of dwg.
As always with ESRI I started by copying their examples and trying them for myself. Taken from:
I extracted the code to create IWorkspace to my WorkspaceProvider:
public CadWorkspaceUtils GetCadWorkspaceUtils(string path)
{
var workspaceFactory = new CadWorkspaceFactory();
var workspace = (IFeatureWorkspace)workspaceFactory.OpenFromFile(path, 0);
return new CadWorkspaceUtils(workspace);
}
I have created a new class – CadWorkspaceUtils that inherits from WorkspaceUtils
with a function to get back the geometries in the file:
public List<IGeometry> GetGeometries(string fileName, GeometryType type)
{
var featureClassName = GetFeatureClassName(fileName, type);
var result = new List<IGeometry>();
DoActionOnSelectFeatures(featureClassName, "",
feature =>
{
var shape = feature.Shape.Copy();
shape.SpatialReference = GeometryUtils.CreateWgsSpatialReference();
result.Add(shape);
});
return result;
}
Helper method:
private string GetFeatureClassName(string fileName, GeometryType type)
{
if (type != GeometryType.Polyline)
throw new NotImplementedException("The method is only implemented for polyline geometries");
return String.Concat(fileName, ":Polyline");
}
Thank god I only need polyline type because I haven't seen an example with anything different.
// TODO: Make links user friendly
//TODO: Post about WorkspaceUtils first
Resources:
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//001900000064000000
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00120000001z000000.htm