Very simple DWG import code:
public Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
{
Document curDoc = commandData.Application.ActiveUIDocument.Document;
Transaction transaction = new Transaction(curDoc, “Import DWG”);
transaction.Start();
DWGImportOptions options = new DWGImportOptions();
options.Placement = Autodesk.Revit.DB.ImportPlacement.Origin;
options.OrientToView = true;
options.View = curDoc.ActiveView;
Element element = null;
if (curDoc.Import(@”C:\Temp\Test.dwg”, options, out element))
transaction.Commit();
else
transaction.RollBack();
return Result.Succeeded;
}
This code only shows very simple way to import a dwg file. The DWGImportOptions contains many properties which you can use and test to get what the best you want.
Comments
Leave a comment