Export object to SHP

Export object to SHP

fieldguy
Advisor Advisor
1,218 Views
2 Replies
Message 1 of 3

Export object to SHP

fieldguy
Advisor
Advisor

I am almost finished with a SHP export application.  Using the sample in the map objectarx sdk I am able to export successfully.  My test dwg file only has 1 closed pline with object data in it.

 

The part I am stuck on is selecting objects.  I have an objectidcollection that contains the objects, but how do I tell the exporter to only export those objects?  The layerfilter is not an option.

 

When I have the objects in the collection exported I will post the code. 

 

0 Likes
Accepted solutions (2)
1,219 Views
2 Replies
Replies (2)
Message 2 of 3

norman.yuan
Mentor
Mentor
Accepted solution

This is a AutoCAD Map specific question.

 

The class "Autodesk.Gis.Map.ImportExport.Exporter" has a method SetSelectionSet(ObjectIdCollection), which is what you need, if you pass an ObjectIdCollection to this method, you also want to set ExportAll property to "false" (maybe not necessary, but I always do when exporting selected geometries).

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 3

fieldguy
Advisor
Advisor
Accepted solution

Excellent!  Thanks @norman.yuan

 

I have pretty much given up on the map forum. I found some shp export stuff in civil 3d as well so decided here was the best place to get the answer.  I am using civil 3d 2016.

 

Here's the important parts. 

 

using acapp = Autodesk.AutoCAD.ApplicationServices;
using acdb = Autodesk.AutoCAD.DatabaseServices;
using acgis = Autodesk.Gis.Map;


acdb.ObjectIdCollection expcoll = new acdb.ObjectIdCollection();
acapp.Document doc = acapp.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
PromptEntityOptions peo = new PromptEntityOptions("\nSelect an export entity: ");
Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView();
PromptEntityResult per = ed.GetEntity(peo);
if (per.Status == PromptStatus.OK)
	expcoll.Add(per.ObjectId);
acgis.MapApplication ma = acgis.HostMapApplicationServices.Application;
acgis.ImportExport.Exporter exp = ma.Exporter;
exp.Init("SHP", @"C:\\myacadfolder\\myshps\newfile.shp");
// exp.ExportAll = false;
exp.SetSelectionSet(expcoll);
acgis.ImportExport.ExpressionTargetCollection dm = null;
dm = exp.GetExportDataMappings();
exp.SetExportDataMappings(dm);
acgis.ImportExport.GeometryType lines = acgis.ImportExport.GeometryType.Line;
exp.SetStorageOptions(acgis.ImportExport.StorageType.FileOneEntityType, lines, string.Empty);
// exp.ClosedPolylinesAsPolygons = true;
acgis.ImportExport.ExportResults results;
try
{
	results = exp.Export(true);
}
catch (acgis.MapImportExportException mee)
{
	string badexport = "There is a problem with the export\n";
        MessageBox.Show(badexport + mee.Message);
}