Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Created April 27, 2021 14:41
Show Gist options
  • Save GroupDocsGists/f6f22f03f2b4f9c984932a11e77a1b23 to your computer and use it in GitHub Desktop.
Save GroupDocsGists/f6f22f03f2b4f9c984932a11e77a1b23 to your computer and use it in GitHub Desktop.
Render CAD Drawings | View DWG or DWF as HTML in C# using .NET API
// Render DWG CAD drawing to view as HTML with embedded resources using C#
using (Viewer viewer = new Viewer("drawing.dwg"))
{
HtmlViewOptions viewOptions = HtmlViewOptions.ForEmbeddedResources("page_{0}.html");
viewer.View(viewOptions);
}
// Render C# CAD drawing to view as HTML with external resources using C#
using (Viewer viewer = new Viewer("drawing.dwg"))
{
HtmlViewOptions viewOptions = HtmlViewOptions.ForExternalResources(
"page_{0}.html","page_{0}/resource_{1}","page_{0}/resources");
viewer.View(viewOptions);
}
// Get Layouts and Layers of DWG CAD drawing in C#
using (Viewer viewer = new Viewer("drawing.dwg"))
{
ViewInfoOptions viewInfoOptions = ViewInfoOptions.ForHtmlView();
CadViewInfo viewInfo = viewer.GetViewInfo(viewInfoOptions) as CadViewInfo;
Console.WriteLine("File type: " + viewInfo.FileType);
Console.WriteLine("Pages count: " + viewInfo.Pages.Count);
foreach (Layout layout in viewInfo.Layouts)
Console.WriteLine(layout);
foreach (Layer layer in viewInfo.Layers)
Console.WriteLine(layer);
}
// Render Layers of .dwg CAD drawing in C#
using (Viewer viewer = new Viewer("drawing.dwg"))
{
HtmlViewOptions viewOptions = HtmlViewOptions.ForEmbeddedResources();
viewOptions.CadOptions.Layers = new List<Layer>
{
new Layer("Walls"),
new Layer("Windows")
};
viewer.View(viewOptions);
}
// Render Layouts of .dwg CAD drawing in C#
using (Viewer viewer = new Viewer("drawing.dwg"))
{
HtmlViewOptions viewOptions = HtmlViewOptions.ForEmbeddedResources();
viewOptions.CadOptions.RenderLayouts = true;
viewer.View(viewOptions);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment