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();
}
}
Solved! Go to Solution.
Solved by Jeff_M. Go to Solution.
@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?
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";
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.
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,
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.
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
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;
}
}
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(); }
daryl -
Let us know if this is resolved now.
Thanks,