.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to use Export API for autocad document object?

2 REPLIES 2
Reply
Message 1 of 3
yuh0317
2812 Views, 2 Replies

How to use Export API for autocad document object?

 void Export([In, MarshalAs(UnmanagedType.BStr)] string FileName, [In, MarshalAs(UnmanagedType.BStr)] string Extension, [In, MarshalAs(UnmanagedType.Interface)] AcadSelectionSet SelectionSet);

 

Who can tell me how to use Export API?

 

Autodesk.AutoCAD.Interop.AcadApplicationClass acadApp = null;
try
{
acadApp = new Autodesk.AutoCAD.Interop.AcadApplicationClass();
if (acadApp != null)
{
string dwgFileName = @"C:\Test.dwg";
Autodesk.AutoCAD.Interop.AcadDocument document = acadApp.Documents.Open(dwgFileName);
document.Export(...);
document.Close(false);

}
}
catch (Exception ex)
{
Console.Write(ex.ToString());
}
finally
{
if (acadApp != null)
{
acadApp.Quit();
}
}

2 REPLIES 2
Message 2 of 3
Balaji_Ram
in reply to: yuh0317

Hello,

 

Here is a sample code directly migrated from the ActiveX documentation (acadauto.chm).

 

[CommandMethod("MyExport")]
public void ExportMethod()
{
	Document doc = Application.DocumentManager.MdiActiveDocument;
	Editor ed = doc.Editor;
	AcadDocument acadDoc = doc.AcadDocument as AcadDocument;

	// This example exports the current drawing to DXF format.
	// Note that a valid selection set must be provided, even
	// though the contents of the selection set are ignored.

	// Define the name for the exported file
	string exportFile = null;
	exportFile = "C:\\Temp\\DXFExprt.dxf";
	// Adjust path to match your system

	// Create an empty selection set
	AcadSelectionSet sset = default(AcadSelectionSet);
	sset = acadDoc.SelectionSets.Add("TEST");

	// Export the current drawing to the file specified above.
	acadDoc.Export(exportFile, "DXF", sset);
}

 Hope this helps.



Balaji
Developer Technical Services
Autodesk Developer Network

Message 3 of 3
Juergen_Becker
in reply to: Balaji_Ram

Hi,

 

I must export into a object, which are on specific layer.

 

I changed your code as followed:

 

Int16[] hFilterType = new Int16[1];
object[] hFilterData = new object[1];
hFilterType[0] = 8;
hFilterData[0] = "Kontur";
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
AcadDocument acadDoc = doc.GetAcadDocument() as AcadDocument;
string exportFile = null;
exportFile = "C:\\Temp\\DXFExport";
AcadSelectionSet sset = default(AcadSelectionSet);
sset = acadDoc.SelectionSets.Add("TEST");
sset.Clear();
sset.Select(Autodesk.AutoCAD.Interop.Common.AcSelect.acSelectionSetAll, Type.Missing, Type.Missing, hFilterType, hFilterData);
sset.Highlight(true);
acadDoc.Export(exportFile, "DXF", sset);

 The selectionset is ok, because the objects are highlighted, but the DXF-File is wrong. The DXF file contains all object objects of the drawing not only the ones on the layer "Kontur".

 

What is wrong with my code?

 

Best Regards Jürgen

I hope my tip helps. If so then give me kudos and mark the tip as a solution.
Thanks.

Jürgen A. Becker
Building Services

Development and Support
Autodesk Forge Spezialist


CAD-Becker.de
https://www.CAD-Becker.de

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost