Export document sheet as DWG or DXF with no predefined options

Anonymous

Export document sheet as DWG or DXF with no predefined options

Anonymous
Not applicable

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.

0 Likes
Reply
Accepted solutions (1)
6,126 Views
16 Replies
Replies (16)

jeremytammik
Autodesk
Autodesk

Have you tried just using

 

new DWGExportOptions()

 

with no modified settings at all?



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes

Anonymous
Not applicable

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.

 

 

0 Likes

jeremytammik
Autodesk
Autodesk
0 Likes

Anonymous
Not applicable

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.

 

 

0 Likes

FAIR59
Advisor
Advisor

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:

  • try   options.MergedViews = true;  all content gets exported into 1 dwg.   with option MergedViews=false the viewports on the sheet get exported as separate dwg's (external references).
  • try exporting a view instead of a sheet, to see if that works.

matthew_taylor
Advisor
Advisor

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


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes

Anonymous
Not applicable

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.

0 Likes

Anonymous
Not applicable

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.

0 Likes

matthew_taylor
Advisor
Advisor

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


Cheers,

-Matt
_______________________________________________________________________________
Marking a post as a 'solution' helps the community. Giving a post 'Kudos' is as good as saying thanks. Why not do both?
0 Likes

FAIR59
Advisor
Advisor
Accepted solution

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.

 

jeremytammik
Autodesk
Autodesk

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



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes

Anonymous
Not applicable

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!

0 Likes

Anonymous
Not applicable

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

0 Likes

HyungJun.K
Participant
Participant

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;

 

 

0 Likes

jeremy_tammik
Autodesk
Autodesk

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.

   

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

HyungJun.K
Participant
Participant
The manual option provided by Revit does not produce the desired result. So, I was approaching a method using the API.

My final goal is to read the .txt file and apply the ByLayer option, and I want the applied option to show a line pattern according to the view scale.

The option I want to pursue is necessary when multiple model views are arranged on one sheet. I hope that the scale specified for each view is different, and the line expression is also output differently. So sometimes the grid is expressed as detail lines. This reduces work efficiency.
0 Likes