Issue with Views Misalignment in MicroStation After Using Design Automation for Revit (DA4R) for DWG Export

Issue with Views Misalignment in MicroStation After Using Design Automation for Revit (DA4R) for DWG Export

h_celikJASY7
Participant Participant
535 Views
4 Replies
Message 1 of 5

Issue with Views Misalignment in MicroStation After Using Design Automation for Revit (DA4R) for DWG Export

h_celikJASY7
Participant
Participant

Hello everyone,

 

I am currently working on a project that uses the Design Automation for Revit (DA4R) API to convert Revit files (RVT) into DWG files. The project is based on this example https://github.com/yiskang/DA4R-DwgExporter from GitHub.

 

The issue I am encountering is that when I open the generated DWG files in MicroStation, the views are not aligned as they were in the original Revit file. It appears that the positioning of views in the exported DWG file is not interpreted by MicroStation the same way it is in Autodesk products.

 

Here is the core part of the code I'm using:

 

 

using (var transGroup = new TransactionGroup(doc, "Starts exporting DWG"))
{
    try
    {
        transGroup.Start();

        ViewSheet newViewSheet;

        using (var transaction = new Transaction(doc, "Create a new ViewSheet"))
        {
            transaction.Start();
            
            LogTrace("Creating a new ViewSheet...");
            newViewSheet = ViewSheet.Create(doc, ElementId.InvalidElementId);

            LogTrace("Iterate over each view and create a new viewport on the new ViewSheet ...");
            foreach (var viewId in viewIds)
            {
                try
                {
                    LogTrace("Create viewport for view: {0}", doc.GetElement(viewId).Name);
                    Viewport.Create(doc, newViewSheet.Id, viewId, XYZ.Zero);
                }
                catch (Exception e)
                {
                    LogError(new Exception(
                        "Viewport creation failed for view: " + doc.GetElement(viewId).Name, e));
                }
            }

            doc.Regenerate();

            transaction.Commit();
        }

        if (newViewSheet == null)
        {
            throw new Exception("Failed to create a new ViewSheet");
        }

        using (var transaction = new Transaction(doc, "Starting the export task"))
        {
            transaction.Start();

            LogTrace("Starting the export task...");
            var newViewSheetIds = new List<ElementId> { newViewSheet.Id };
            
            doc.Export(exportPath, inputParams.ExportFilename, newViewSheetIds, dwgExportOptions);

            LogAllFiles(exportPath);

            transaction.Commit();
        }

        transGroup.Assimilate();
    }
    catch (Exception ex)
    {
        LogError(ex);
        transGroup.RollBack();
        return false;
    }
}

 

 

This code successfully combines all views into a single sheet and exports them into a DWG file. However, when the output DWG is opened in MicroStation, the views are not lined up as expected.

 

Has anyone else encountered this issue and can provide any insight or solutions? Your help would be greatly appreciated!

 

In order to better illustrate the issue, I have attached two images. The first image showcases a simple cube model with two views in Revit, demonstrating the intended layout. The second image shows the resulting layout when the exported DWG file is opened in MicroStation, highlighting the misalignment of the views.

 

Thank you in advance!

 

Best,
Hasan

0 Likes
536 Views
4 Replies
Replies (4)
Message 2 of 5

jeremy_tammik
Alumni
Alumni

What does the resulting DWG look like in AutoCAD? That would be the real test.

  

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

h_celikJASY7
Participant
Participant

I appreciate your assistance and response. I tested it by opening it in true view, and it appears that I have lost all the 3D information. I believe this might be due to the solid settings in the export options (please correct me if I'm mistaken). However, the problem persists as the object will be placed multiple times. In this post, I have shared both the original file and the converted file.

 

h_celikJASY7_0-1683806576171.png

 

0 Likes
Message 4 of 5

ricaun
Advisor
Advisor

What are you expecting to happen in the dwg?

 

I never worked with exporting dwg and I guess the ViewSheet is 2d is that what you want?

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

0 Likes
Message 5 of 5

h_celikJASY7
Participant
Participant

I'm working on a project where my aim is to combine all the views into a single DWG file. I came across a helpful tutorial that gave me the idea: https://thebuildingcoder.typepad.com/blog/2018/02/mergedviews-and-exporting-to-a-single-dwg.html

Since I'm not sure which views will be important beforehand, I want to gather all of them in one file and organize them later. I prefer the DWG format for my files.

I'm still learning about the Revit API, so I'm uncertain if utilizing the view sheet was the best approach for achieving this. I'm open to suggestions and advice.

 

Edit: Additionally, my expectation for this example is that the cubes will not be scattered randomly, but rather arranged either on top of each other or in a layered manner

0 Likes