Run MapClean Profile Programmatically

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!


Comments

2 responses to “Run MapClean Profile Programmatically”

  1. Hello Mr. Daniel. I have problem with TopologyClean.Init(action, IdCollection). If I use ObjectIdCollection, or if I use null, I have same result. “All” object are cleaning, not only this in my ObjectIdCollection. What I doing wrong?
    Thanks.
    Robert

  2. Daniel Avatar
    Daniel

    Hi Robert,
    I have noticed this issue, and logged a change request about this. Sorry for the inconvenience.

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading