I am trying to export a ViewSheet as a DWG or DXF. Looking through examples on the forums and help files it seems simple, but is not working for me. Exporting as DWG or DXF manually from the Export menu works fine but I cannot get it working through the API. One problem I'm having is that my document has no predefined setup options. When I use the following code:
IList<string> setupNames = BaseExportOptions.GetPredefinedSetupNames(document);
setupNames has no strings in it, so there are no predefined options in my document as far as I know. So I have to create my own DWGExportOptions or DXFExportOptions. I tried doing this by exporting the sheet manually and opening up the "Modify DWG/DXF Export Setup" dialog box to see the settings and then use those to create my own export options object. This is not working however. The AutoCAD file I get has just a small white square where the sheet should be. Here is my code:
List<ElementId> viewIds = new List<ElementId>(); viewIds.Add(viewSheet.Id); DWGExportOptions options = new DWGExportOptions(); options.Colors = ExportColorMode.IndexColors; options.ExportOfSolids = SolidGeometry.Polymesh; options.FileVersion = ACADVersion.R2013; options.HatchPatternsFileName = @"C:\Program Files\Autodesk\Revit 2016\ACADInterop\acdb.pat"; options.HideScopeBox = true; options.HideUnreferenceViewTags = true; options.HideReferencePlane = true; options.LayerMapping = "AIA"; options.LineScaling = LineScaling.PaperSpace; options.LinetypesFileName = @"C:\Program Files\Autodesk\Revit 2016\ACADInterop\acdb.lin"; options.MergedViews = false; options.PropOverrides = PropOverrideMode.ByEntity; options.TextTreatment = TextTreatment.Exact; document.Export(filePath, fileName, viewIds, options);
Any help is appreciated. Thank you.
Solved! Go to Solution.
Solved by FAIR59. Go to Solution.
Have you tried just using
new DWGExportOptions()
with no modified settings at all?
Thank you for your response. I should have stated that in my initial post. Yes I did try that first, hoping the default constructor would give me the correct object. When it didn't work I started going into the properties to try to find something that would work.
Thank you for clarifying.
Have you seen these?
http://forums.autodesk.com/t5/revit-api-forum/dwg-export-using-vb-net/td-p/5847119
http://adndevblog.typepad.com/aec/2014/12/revitapi-how-to-get-dwgexportoptions.html
Cheers,
Jeremy
Thank you for the response.
Yes I've seen both of those. In both cases my document returns nothing.
Dim setupNames As IList(Of String) = BaseExportOptions.GetPredefinedSetupNames(document)
returns no strings. setupNames is empty.
var dwgSettingsFilter = new ElementClassFilter(typeof(ExportDWGSettings)); FilteredElementCollector settings = new FilteredElementCollector(document); settings = settings.WherePasses(dwgSettingsFilter); foreach(ExportDWGSettings element in settings) { var options = element.GetDWGExportOptions(); .... }
settings has no ExportDWGSettings in it and so the code doesn't enter the foreach loop.
It seems my document has no export settings associated with it.
I did a test export (Revit 2016) from a new project without a template, and it works fine, even with the default options.
a few suggestions:
Hi @Anonymous,
Have you tried the static ExportDwgSettings.Create method? (When GetPredefinedSetupNames returns nothing.)
http://www.revitapidocs.com/2017/e54ac7dc-0b2c-a1ae-a5d8-5bd794d2cb8d.htm
The created ExportDwgSettings object has a GetDwgExportOptions method.
(I've not tested it.)
Cheers,
-Matt
Thank you for the reply.
I tried your suggestions and still couldn't get a good export. I tried exporting just the View as well as just the ViewSection and the resulting .dwg is an outline of the object in my drawing without dimension lines and other items contained in the View.
Thank you for the reply.
I tried your suggestion and it didn't work, but did give me an interesting result. I created my own ExportDWGSettings as you wrote and got the following code:
List<ElementId> viewIds = new List<ElementId>(); viewIds.Add(viewSheet.Id); DWGExportOptions options = new DWGExportOptions(); ExportDWGSettings dwgSettings = ExportDWGSettings.Create(document, "test"); options = dwgSettings.GetDWGExportOptions(); document.Export(filePath, fileName, viewIds, options);
I called the new export option "test" as shown in the code. The resulting drawing from this code was a bad drawing as I've exported before. However when I used the menu to Export as DWG and selected "test" as my export setup the exported drawing was good.
This leads me to believe the export options object being sent to the export of the document is fine, but there is something else going on here.
Hi @Anonymous,
Some ideas.
Pass your views as an icollection(of db.elementid). It may be forcing it to use an old overload internally or something ridiculous. I doubt this is it.
icollection<db.elementid> coll = new list<db.elementid>();
Change your target units. Check the units on the output. Select 'all'. Are things there, just too small to see?
Strip the code down to essential code only. Check the obvious!
If none of that helps, attach a stripped down model, an example export, and the stripped down code.
Cheers,
-Matt
Based on your latest "Failure Report", I now think it's a Transaction / Regeneration problem.
I would guess that your making a view and exporting it in the same transaction.
Try using a new Transaction for the dwg export.
Dear Fair59,
That sounds like a very fair 🙂 and convincing (!) assessment to me!
Cf. the list of numerous situations with a 'need to regenerate' causing similar confusion:
http://thebuildingcoder.typepad.com/blog/about-the-author.html#5.33
Thank you very much for the promising suggestion!.
Cheers,
Jeremy
That was exactly the problem. I was creating the view and exporting it in the same transaction. I separated them into separate transactions and now it works great.
Thank you for the help!
This post is good, I guess what problem I'm facing with the ExportToDWG has to do something with the transaction. I tried the solution, but an exception of type system.accessviolationexception occurred. Appreciate if someone takes a look at this post [ While Exporting Views to DWG an Exception System.AccessViolationException occur ] too. @jeremytammik and @FAIR59 need your expert advice. Thank you
I try to apply it with different options. However, these two conflicts and do not apply. Do you know a workaround or why?
options.LineScaling = LineScaling.ViewScale;
options.PropOverrides = PropOverrideMode.ByLayer;
Nope, I have no idea. How does it behave in the manual end user interface? Do you see the conflict there as well, or can you apply both desired options simultaneously? The Revit API generally just reflects the UI functionality, you know.
Can't find what you're looking for? Ask the community or share your knowledge.