Hi all,
my English isn't very good, but I hope you will understand me 🙂
I'm quite new in ESRI tools, ArcObject's and so on. At this moment we (at work) started changing ArcGis 9.3 to 10. Everything has been OK so far. But now there is one problem - Class Extension. Adding and removing I've done, but... not really. Let me explain this:
I log in and then I use my command button to add (I use IClassSchemaEdit2.AlterClassExtensionCLSID() method) class extansion to selected tables. I verify that and there is what I added. But problem begins when I turn off ArcCatalog and then I turn it on once again. All added Class extansions disappeared! Why? In ArcGIS 9.3 it was easier, because one insert into appropirate table and class extension is remembered.
PS.
With Workspace Extension there aren't any problems like with Class Extension.
IGxApplication gxApp = m_application as IGxApplication; IGxSelection gxSel = null; IEnumGxObject enumGxObj = null; IGxObject gxObj = null; gxSel = gxApp.Selection; enumGxObj = gxSel.SelectedObjects; gxObj = enumGxObj.Next(); while (gxObj != null) { Tools.AddRemoveExtension(gxObj, true, "{32B73670-FF7E-4e52-A0D2-740716E011D1}"); gxObj = enumGxObj.Next(); }
public static void AddRemoveExtension(IGxObject gxObj, bool add_remove, string GUID) { ... IGxDataset pGxDataSet = gxObj as IGxDataset; IDataset pDataSet = pGxDataSet.Dataset; IObjectClass pObjectClass = pDataSet as IObjectClass; if(pObjectClass != null && !gxObj.Name.ToUpper().Contains("GEODB.TS_")) try { ChangeClassExtension(pObjectClass, GUID, null, add_remove); } catch(Exception e) { System.Windows.Forms.MessageBox.Show(errorMsg); } }
private static void ChangeClassExtension(IObjectClass objectClass, String extensionUID, IPropertySet extensionProperties, bool add_remove) { ISchemaLock schemaLock = (ISchemaLock)objectClass; try { // Attempt to get an exclusive schema lock. schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock); // Cast the object class to the IClassSchemaEdit2 interface. IClassSchemaEdit2 classSchemaEdit = (IClassSchemaEdit2)objectClass; if (!String.IsNullOrEmpty(extensionUID) && add_remove == true) { // Create a unique identifier (UID) object and change the extension. UID extUID = new UIDClass(); extUID.Value = extensionUID; classSchemaEdit.AlterClassExtensionCLSID(extUID, extensionProperties); } else { // Clear the class extension. classSchemaEdit.AlterClassExtensionCLSID(null, null); } } catch (COMException comExc) { throw new Exception("Could not change class extension.", comExc); } finally { schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock); } }
Thanks syamarth for reply.
My code looks like this:
1. First I get all selected items in ArcCatalog
IGxApplication gxApp = m_application as IGxApplication; IGxSelection gxSel = null; IEnumGxObject enumGxObj = null; IGxObject gxObj = null; gxSel = gxApp.Selection; enumGxObj = gxSel.SelectedObjects; gxObj = enumGxObj.Next(); while (gxObj != null) { Tools.AddRemoveExtension(gxObj, true, "{32B73670-FF7E-4e52-A0D2-740716E011D1}"); gxObj = enumGxObj.Next(); }
In Tools class I have all methodes I use to setting extension.
2. In AddRemoveExtension method I check if selected item is appropriate and then I try to get IObjectClass object:
public static void AddRemoveExtension(IGxObject gxObj, bool add_remove, string GUID) { ... IGxDataset pGxDataSet = gxObj as IGxDataset; IDataset pDataSet = pGxDataSet.Dataset; IObjectClass pObjectClass = pDataSet as IObjectClass; if(pObjectClass != null && !gxObj.Name.ToUpper().Contains("GEODB.TS_")) try { ChangeClassExtension(pObjectClass, GUID, null, add_remove); } catch(Exception e) { System.Windows.Forms.MessageBox.Show(errorMsg); } }
3. After that I use method found by me in ESRI help (the same page you gave me in your post above)
private static void ChangeClassExtension(IObjectClass objectClass, String extensionUID, IPropertySet extensionProperties, bool add_remove) { ISchemaLock schemaLock = (ISchemaLock)objectClass; try { // Attempt to get an exclusive schema lock. schemaLock.ChangeSchemaLock(esriSchemaLock.esriExclusiveSchemaLock); // Cast the object class to the IClassSchemaEdit2 interface. IClassSchemaEdit2 classSchemaEdit = (IClassSchemaEdit2)objectClass; if (!String.IsNullOrEmpty(extensionUID) && add_remove == true) { // Create a unique identifier (UID) object and change the extension. UID extUID = new UIDClass(); extUID.Value = extensionUID; classSchemaEdit.AlterClassExtensionCLSID(extUID, extensionProperties); } else { // Clear the class extension. classSchemaEdit.AlterClassExtensionCLSID(null, null); } } catch (COMException comExc) { throw new Exception("Could not change class extension.", comExc); } finally { schemaLock.ChangeSchemaLock(esriSchemaLock.esriSharedSchemaLock); } }
And yes - I have separated project with ClassExtension and the other one with all buttons to adding/removing ClassExtension and WorkspaceExtension.
I think there aren't any other Applications that have reference of this Class Extension.