By Partha Sarkar
Autodesk Design Review is a viewer application which allows us to view, print, annotate, and compare 2D and 3D DWF files. It has a set of public API which allows us to create custom application focused on viewing DWF files, Object properties, Printing etc. You can get more details on Autodesk Design Review API from the Developer Center Page.
In this blog post, I am sharing some code snippet using Design Review / DWF Viewer API which shows how to load a DWF file, how to get the object properties of the components of DWF object model, how to control visibility of a component in the DWF file and access the DWF file properties. Here is the screenshot of the sample Windows Forms application which embedding Design Review / DWF Viewer control and few buttons for specific task -
And here is the relevant C# code snippet for each task -
privatevoid button1_Click(object sender, EventArgs e)
{
// Option 2 - Using OpenFileDialog
OpenFileDialog oFileDialog = newOpenFileDialog();
oFileDialog.ShowDialog();
axCExpressViewerControl1.SourcePath = oFileDialog.FileName;
}
privatevoid DWF_Property_Click(object sender, EventArgs e)
{
ECompositeViewer.IAdECompositeViewer CompositeViewer;
AdCommon.IAdCollection Sections;
CompositeViewer = (ECompositeViewer.IAdECompositeViewer)axCExpressViewerControl1.ECompositeViewer;
Sections = (AdCommon.IAdCollection)CompositeViewer.Sections;
MessageBox.Show("Pages Count : " + Sections.Count);
//Loop through Sections Collection using foreach
foreach (ECompositeViewer.IAdSection Section in Sections)
{
MessageBox.Show(Section.Title);
MessageBox.Show("Order of the section \"" + Section.Title + "\" is " + Section.Order);
}
}
privatevoid button_ObjProp_Click(object sender, EventArgs e)
{
try
{
ECompositeViewer.IAdECompositeViewer compvwr =
(ECompositeViewer.IAdECompositeViewer)axCExpressViewerControl1.ECompositeViewer;
ECompositeViewer.IAdSection sec = (ECompositeViewer.IAdSection)compvwr.Section;
ECompositeViewer.IAdContent con = (ECompositeViewer.IAdContent)sec.Content;
AdCommon.IAdCollection adobj = (AdCommon.IAdCollection)con.get_Objects(1); //for selected object
AdCommon.IAdObject obj = (AdCommon.IAdObject)adobj[1];
string str = "";
foreach (AdCommon.IAdProperty prop in (AdCommon.IAdCollection)obj.Properties)
{
str = str + "Name: " + prop.Name + " Value: " + prop.Value + Environment.NewLine;
}
// Properties of the selected object will be displayed in a Text Box
textBox1.Text = str;
}
catch
{
// TODO: Add your error handling here.
}
} //
privatevoid button_hideObj_Click(object sender, EventArgs e)
{
try
{
ECompositeViewer.IAdECompositeViewer compvwr =
(ECompositeViewer.IAdECompositeViewer)axCExpressViewerControl1.ECompositeViewer;
ECompositeViewer.IAdSection sec = (ECompositeViewer.IAdSection)compvwr.Section;
ECompositeViewer.IAdContent con = (ECompositeViewer.IAdContent)sec.Content;
AdCommon.IAdCollection adobj = (AdCommon.IAdCollection)con.get_Objects(1); //for selected object
AdCommon.IAdObject obj = (AdCommon.IAdObject)adobj[1];
compvwr.ExecuteCommand("HIDE");
}
catch
{
// TODO: Add your error handling here.
}
}
Hope this is useful to you!
[ Updated on 20/Nov/2013 ]
I am updating this blog post with the following notes and screenshot to show what all components you need to reference from Autodesk Design Review to build this C# .NET code sample.
Autodesk Design Review 2013 API Reference document has a topic - "Setting References in C# .NET" which lists the Autodesk Design Review components you need to reference in your project to build this sample.
Here is the screenshot of the Design Review components I have used in my project -
You can also download this C# .NET sample application from here ADR2013WinFormAppCS.
Recent Comments