By Daniel Du
I am asked about this question: I know how to run MapClean in Map 3D UI, and create/load profile to run the mapclean process repeatedly. but is it possible to run MapClean programmatically? The answer is yes, we can create a custom application to run MapClean programmatically. Here is the code snippet, please note that we need add reference to ManagedMapApi.dll, which can be found in Map 3D installation folder.
[CommandMethod("clean")]
public void DrawingCleanUp()
{
Autodesk.Gis.Map.Topology.Variable cadAction
= new Autodesk.Gis.Map.Topology.Variable();
//Load a dpf script file, it can be generated by Map 3D UI
cadAction.LoadProfile(@"C:\Work\mapcleandemo\myclean.dpf");
//The instance of this class should be released by explicitly
//calling Dispose() in order to avoid memory leak.
//See also ‘using’ keyword in C# and VB.Net.
using (Autodesk.Gis.Map.Topology.TopologyClean cadCleanobj
= new Autodesk.Gis.Map.Topology.TopologyClean())
{
//Open a file first to avoid MapTopologyException
cadCleanobj.Init(cadAction, null);
cadCleanobj.Start();
cadCleanobj.GroupNext();
while (!cadCleanobj.Completed)
{
cadCleanobj.GroupFix();
cadCleanobj.GroupNext();
}
//Commit the changes
cadCleanobj.End();
}
}
Hope this helps!

Leave a Reply