Community
Civil 3D Customization
Welcome to Autodesk’s AutoCAD Civil 3D Forums. Share your knowledge, ask questions, and explore popular AutoCAD Civil 3D Customization topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MapClean c#

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
daryl
1261 Views, 12 Replies

MapClean c#

I need help with the automatic mapclean example provided by Daniel Du on the dev. blog. I am trying to interactively create the path to the dpf file. I can hard code it in to get it to work; otherwise, I have no luck. Any ideas?

 

My issue is with this line of code   cadAction.LoadProfile(@"C:\Work\mapcleandemo\myclean.dpf");

I am trying to dynamically add paths like the following:

 

filepath = String.Format(@"{0}", filepath);

or

filepath = String.Format("\"" + "{0}" + "\"", filepath);

 

cadAction.LoadProfile(filepath);

 

I believe it is not working due to the file path. I do check earlier in the code that it can find the file before trying to load it.

 

[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();

  }

 

}

Geospatial Application Development
Banks and Banks Consulting
12 REPLIES 12
Message 2 of 13
Jeff_M
in reply to: daryl


@Daryl wrote:

I need help with the automatic mapclean example provided by Daniel Du on the dev. blog. I am trying to interactively create the path to the dpf file. I can hard code it in to get it to work; otherwise, I have no luck. Any ideas?

 

My issue is with this line of code   cadAction.LoadProfile(@"C:\Work\mapcleandemo\myclean.dpf");

I am trying to dynamically add paths like the following:

 

filepath = String.Format(@"{0}", filepath);

or

filepath = String.Format("\"" + "{0}" + "\"", filepath);

 

cadAction.LoadProfile(filepath);

 

I believe it is not working due to the file path. I do check earlier in the code that it can find the file before trying to load it.

 

 


How/where are you specifying the initial value of filepath?

Jeff_M, also a frequent Swamper
EESignature
Message 3 of 13
daryl
in reply to: Jeff_M

Below is the string. Basically, the information( dpf file)  is stored in the applicationplugins folder, which the "appfolder" is that path. I append the additional string.                

 

 

string appfolder = PGA.Autodesk.Settings.AcadSettings.AppFolderScriptPath;

                

               

string filepath = System.IO.Path.Combine(appfolder,"MapClean",layername);

             filepath +=".dpf";

            

               

if (!System.IO.File.Exists(filepath))

                   throw new FileNotFoundException(filepath);

 

filepath = String.Format("{0}", filepath);

               

               

//filepath = @"C:\USERS\DARYL BANKS\APPDATA\ROAMING\AUTODESK\APPLICATIONPLUGINS\PGA-PUTTTINSURFACE2014.BUNDLE\CONTENTS\SCRIPTS\MAPCLEAN\S-CARTPATH.DPF";

Geospatial Application Development
Banks and Banks Consulting
Message 4 of 13
Jeff_M
in reply to: daryl

Providing your appPath is getting a valid string, which it must be in order to pass the FileExists test, you should just be able to pass filepath, no need to Format.

 

            string layername = "test";
            string appfolder = @"C:\Users\Jeff-i7\AppData\Roaming\Autodesk\ApplicationPlugins\Test";
            string filepath = System.IO.Path.Combine(appfolder, "MapClean", layername);
            filepath += ".dpf";

            if (!System.IO.File.Exists(filepath))
                throw new System.IO.FileNotFoundException(filepath);

            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(filepath);

 I was able to run the command with the code above inserted into your code.

Jeff_M, also a frequent Swamper
EESignature
Message 5 of 13
Partha.Sarkar
in reply to: daryl

Hi daryl,

 

This seems to be an issue of forming the correct location for the profile file.

I presume with Jeff's code snippet you could resolve the filepath issue already.

 

Thanks,



Partha Sarkar
Developer Technical Services
Autodesk Developer Network

Message 6 of 13
daryl
in reply to: daryl

Jeff,

 

Thanks for the testing. I am including the dwg and the dpf file for your use. The error is actually thrown on the GroupFix method. However, if I paste my hard coded path into the filepath variable, then it is not thrown. Also, it does not perform as expected either. I am submitting my class. Keep in mind I have been testing and changing items to locate the source of problem. I have put a Document lock on the command.

Geospatial Application Development
Banks and Banks Consulting
Message 7 of 13
daryl
in reply to: daryl

Log file

Geospatial Application Development
Banks and Banks Consulting
Message 8 of 13
daryl
in reply to: daryl

Okay, Thanks Jeff! I was able to verify the file was read correctly by saving it back to the folder.

 

   cadAction.SaveProfile(filepath + "saved");

 

Since the error was not the filepath, I am working through the actual error of getting the selection set from the dpf file.

 

"ManagedMapApi"

 

  at Autodesk.Gis.Map.Interop.ThrowMapTopologyExceptionForErrorStatus(Int32 errorStatus)
   at Autodesk.Gis.Map.Interop.CheckTopologyError(Int32 errorStatus)
   at Autodesk.Gis.Map.Topology.TopologyClean.get_CreatedSelectionSet()

 

  AdsErrorCode -5001 int

 

Geospatial Application Development
Banks and Banks Consulting
Message 9 of 13
Jeff_M
in reply to: daryl

OK, I'm seeing the same as you with your data. I'll have a better look tonight...just leaving my office now (never got a chance to look at this today until just a few minutres ago).

Jeff_M, also a frequent Swamper
EESignature
Message 10 of 13
daryl
in reply to: daryl

Okay, I have a working version. See if you get similar results. I am uploading the class. I removed the document lock and did not need to supply the selected objects to the method. The cartpath.dpf will create a new object on layer '0' for visual cue of the change.

 

  

while (!cadCleanobj.Completed)

                    {

                       

try

                        {

                           

if (cadCleanobj.GroupErrorCount > 0)

                            {

                                cadCleanobj.GroupFix();              

                            }

                            cadCleanobj.GroupNext();

                        }

                       

catch (Exception ex)

                        {

                           

ACADLogging.LogMyExceptions(String.Format("MapClean:{0}", ex.Message));

                           

if (count++ > 5) return;

                        }

                    }

Geospatial Application Development
Banks and Banks Consulting
Message 11 of 13
Jeff_M
in reply to: daryl

I also got a working version, using the first class and dpf. All I did was wrap the cadCleanobj.GroupFix(); in a try/catch block. The resulting drawing appears to be the same as running Mapclean manually and loading the same dpf.

 

            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)
                {
                    try
                    {
                        cadCleanobj.GroupFix();
                    }
                    catch { }
                    cadCleanobj.GroupNext();
                }
                //Commit the changes
                cadCleanobj.End();
            }

 

Jeff_M, also a frequent Swamper
EESignature
Message 12 of 13
Partha.Sarkar
in reply to: Jeff_M

daryl -

 

Let us know if this is resolved now.

 

Thanks,

 



Partha Sarkar
Developer Technical Services
Autodesk Developer Network

Message 13 of 13
daryl
in reply to: Jeff_M

Thanks everyone!!

Geospatial Application Development
Banks and Banks Consulting

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

Post to forums  

Rail Community


 

Autodesk Design & Make Report