CAD (Computer-Aided Design) drawings are normally used to create architectural plans and models using CAD software programs. Some of the well-known AutoCAD file formats are DWG, DXF, DGN, DWF. We discussed viewing the CAD drawings using Java in a separate article. Today, in this article, we will discuss how to programmatically view CAD files using C# within .NET applications.

The following topics are covered below in brief:

.NET CAD Viewer API – DWG, DXF, DWF, DGN

In this article, I will be using GroupDocs.Viewer for .NET that allows programmatically rendering the CAD files like DWG to PDF, JPG, PNG, and HTML within .NET applications. In addition to DWG, the API supports DWF, DGN, DWT, DXF, IFC, STL, Plotter documents, and many more.

Other than the CAD file formats, API provides are the same rendering features for word-processing documents, spreadsheets, presentations, web pages, images, vectors, eBooks, Visio drawings, many source code files of different programming languages.

Download the DLLs or MSI installer from the downloads section or install the API in your .NET application via NuGet.

PM> Install-Package GroupDocs.Viewer

Convert CAD Drawings to View as HTML, PNG, JPG, or PDF in C#

In this article, I am only using the DWG format for the conversion and rendering to other formats with examples. Let’s start with the conversion of the DWG design file to render it as HTML with embedded as well as external resource options using C#.

Convert DWG to HTML with Embedded Resources in C#

The following are the steps of how to convert the DWG file to render as HTML.

The following source code converts the DWG file and renders it as HTML with embedded resources using C#.

Convert DWG to HTML with External Resources in C#

The following are the steps for converting the DWG file and render it as HTML file(s) with external resources.

The following source code renders the DWG file as HTML with external resources in C#.

Convert DWG to PDF, JPG, and PNG in C#

Just like the conversion to HTML format, DWG files can be rendered as PDF, PNG, and JPG format using the respective ViewOptions as follows:

Get Layouts and Layers of DWG in C#

The CAD files can contain multiple layouts and layers, you can get these layouts and layers using the following steps.

  • Load the DWG file using the Viewer class.
  • Create the ViewInfoOptions for HTML view rendering.
  • Using Viewer, get the CadViewInfo that has layouts.
  • Get the layouts from CadViewInfo and iterate over them.
  • Similarly, get the layers from CadViewInfo and iterate over them.

The following code shows how to get the layouts and layers of ا DWG file using C#.

Render CAD Layers of DWG file in C#

If you do not want to render all the layers but only some specific layer of the DWG, it can be done by setting layer names.

  • Load the DWG drawing using the Viewer class.
  • Create view options.
  • Add CAD layers to the View Options
  • Render DWG to HTML using View method.

The following code renders the layers of a CAD file of DWG format in C#.

Render CAD Layouts of DWG file in C#

By default, we only get the model presentation when we render a CAD file. We can set properties to render all the non-empty layouts along with the model.

  • Load the DWG drawing using the Viewer class.
  • Create view options.
  • Set the Render Layouts property to true.
  • Render DWG to HTML using View method.

The following code renders all the non-empty layouts along with the model of a CAD drawing with DWG format in C#.

Get a Free API License

You can get a free temporary license in order to use the API without evaluation limitations.

Conclusion

To conclude, I hope you have learned how to view CAD files in C# within the .NET applications. Further, you have seen, how to get and show models, layouts, and layers of CAD files within your application. You must be confident to build your own CAD Viewer using C#. You can experience the Online applications to view any of your files. These are built using GroupDocs.Viewer.

You can learn more about GroupDocs.Viewer for .NET using the documentation. In case you would have any queries, feel free to let us know via our forum.

See Also