Why is this adding a the new feature class to the mxd?

231
2
Jump to solution
09-18-2012 06:47 AM
New Contributor
Hi,

I am building a suite of Add-Ins. This one is to make a back up of a selected layer. When the tool is run the backed up feature class is added to the mxd. I don't want it to be added to the map document and I can't figure out why it is being added. Any suggestions?

       public static IWorkspace FileGdbWorkspaceFromPath(String path)         {             Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");             IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);             return workspaceFactory.OpenFromFile(path, 0);         }          public IFeatureClass GetFeatureClassOfSelectedFeatureLayer(IFeatureLayer featureLayer)         {             IFeatureClass featureClass = featureLayer.FeatureClass;             return featureClass;         }          protected override void OnClick()         {             IWorkspace workSpace = FileGdbWorkspaceFromPath(@"G:\PROJECTS\SCHOOL_SAFETY_MAPPING_APPLICATION_20120606\DATA\SchoolSafety.gdb");             CreateFeatureClass(workSpace, "SelectedLayerBU");         }          public void CreateFeatureClass(IWorkspace workspace, String featureClassName)         {             IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;              IWorkspace2 pWorkspace2 = workspace as IWorkspace2;              ////Delete the Feature Class if it already exists////             if (pWorkspace2.get_NameExists(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureClass, "SelectedLayerBU"))             {                 FeatureClass featureC = (FeatureClass)featureWorkspace.OpenFeatureClass("SelectedLayerBU");                 IDataset dataSet;                 ISchemaLock schemaLock = (ISchemaLock)featureC;                 dataSet = featureC;                 dataSet.Delete();                 schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock);             }              IFeatureClass featureSelected = GetFeatureClassOfSelectedFeatureLayer((IFeatureLayer)ArcMap.Document.SelectedLayer);              try             {                 featureWorkspace.CreateFeatureClass("SelectedLayerBU", featureSelected.Fields, featureSelected.CLSID, featureSelected.EXTCLSID, featureSelected.FeatureType, featureSelected.ShapeFieldName, null);                 Geoprocessor gp = new Geoprocessor();                 gp.SetEnvironmentValue("workspace", @"G:\PROJECTS\SCHOOL_SAFETY_MAPPING_APPLICATION_20120606\DATA\SchoolSafety.gdb");                  Append append = new Append(); //this tool uploads the feature class                 append.inputs = featureSelected;                 append.target = @"G:\PROJECTS\SCHOOL_SAFETY_MAPPING_APPLICATION_20120606\DATA\SchoolSafety.gdb\SelectedLayerBU";                  gp.Execute(append, null);              }              catch (Exception exc)             {                 MessageBox.Show(Convert.ToString(exc));                 return;             }


Thanks,
Robbie
Reply
0 Kudos
1 Solution

Accepted Solutions
Regular Contributor III
You're using a geoprocessing tool.  The geoprocessing environment has a global setting to automatically add outputs to the map.  You can turn it off, either through the ArcMap UI or through code (IGeoProcessor.AddOutputsToMap).

View solution in original post

Reply
0 Kudos
2 Replies
Regular Contributor III
You're using a geoprocessing tool.  The geoprocessing environment has a global setting to automatically add outputs to the map.  You can turn it off, either through the ArcMap UI or through code (IGeoProcessor.AddOutputsToMap).

View solution in original post

Reply
0 Kudos
New Contributor
Thanks Neil. That might have been the fastest answer ever.
Reply
0 Kudos