Export dwg without Layout

Export dwg without Layout

r_ihm
Explorer Explorer
341 Views
3 Replies
Message 1 of 4

Export dwg without Layout

r_ihm
Explorer
Explorer

I like to export dwg from with c#.

 

How can i export with a Layout in the paperspace dwg. 

 

The following code export only things in the modelspace.

 

// setting up the dwg export options
DWGExportOptions o = new DWGExportOptions();
ExportDWGSettings dwgSettings = ExportDWGSettings.Create(doc, "RevitExportSettings");
o = dwgSettings.GetDWGExportOptions();
o.ACAPreference = ACAObjectPreference.Geometry;
o.Colors = ExportColorMode.TrueColorPerView;
o.ExportOfSolids = SolidGeometry.ACIS;
o.ExportingAreas = false;
o.FileVersion = ACADVersion.R2013;
o.MergedViews = true;
o.LineScaling = LineScaling.ViewScale;
o.HideReferencePlane = true;
o.HideScopeBox = true;
o.HideUnreferenceViewTags = true;
o.TargetUnit = ExportUnit.Millimeter;

 

....

doc.Export(ExportFolder, plannumber, icollection, o);

 

 

 

When i use the Revit export button there is an layout in the paperspace.

 

thx for help. 

0 Likes
Accepted solutions (2)
342 Views
3 Replies
Replies (3)
Message 2 of 4

jeremy_tammik
Alumni
Alumni
Accepted solution

Does this answer by Gemini LLM help? 

  

  

It looks pretty useful to me...

    

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 4

Sleepingfish_Kuo
Advocate
Advocate

I guess No (with editing the export settings only).

 

DWGExportOptions.MergedViews

is to throw the references to other files or not. The views in one sheet always sort as a line in the drawing.

 

The best way for me is exporting the DWG from the layout to a new drawing again.

And maybe it can be done automatic by lisp or CAD.NET in CAD.

 

0 Likes
Message 4 of 4

admin
Explorer
Explorer
Accepted solution

I modify the Gemini code a litte bit and it works fine:

 

UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;

using (Transaction tr = new Transaction(doc, "Dwg Export"))
{
tr.Start();
// 1. Create DWGExportOptions

ExportDWGSettings dwgSettings;
if (ExportDWGSettings.ListNames(doc).Contains("RevitExportSettings"))
dwgSettings = ExportDWGSettings.FindByName(doc, "RevitExportSettings");
else
dwgSettings = ExportDWGSettings.Create(doc, "RevitExportSettings");

DWGExportOptions dwgOptions = new DWGExportOptions();
dwgOptions = dwgSettings.GetDWGExportOptions();
dwgOptions.ACAPreference = ACAObjectPreference.Geometry;
dwgOptions.Colors = ExportColorMode.TrueColorPerView;
dwgOptions.ExportOfSolids = SolidGeometry.ACIS;
dwgOptions.ExportingAreas = false;
dwgOptions.FileVersion = ACADVersion.R2013;
dwgOptions.MergedViews = true;
dwgOptions.LineScaling = LineScaling.ViewScale;
dwgOptions.HideReferencePlane = true;
dwgOptions.HideScopeBox = true;
dwgOptions.HideUnreferenceViewTags = true;
dwgOptions.TargetUnit = ExportUnit.Millimeter;

// 2. Collect all sheets in the document
FilteredElementCollector collector = new FilteredElementCollector(doc);
ICollection<ElementId> sheetIds = collector.OfClass(typeof(ViewSheet)).ToElementIds();

// 3. Iterate through sheets and export
foreach (ElementId sheetId in sheetIds)
{
ViewSheet sheet = doc.GetElement(sheetId) as ViewSheet;
if (sheet != null)
{
// 4. Create a ViewSheetSet with the current sheet
var ids = new List<ElementId> { sheetId };

// 5. Generate the DWG file name
var exportFolder = @"C:\Data";

// 6. Export the sheet
//doc.Export(fileName, sheetSet, dwgOptions);
doc.Export(exportFolder, sheet.Name, ids, dwgOptions);
}
}
tr.Commit();
}

 

thanks

0 Likes