AnsweredAssumed Answered

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

Question asked by douglas.robbie on Sep 18, 2012
Latest reply on Sep 18, 2012 by douglas.robbie
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

Outcomes