private void IAcSmEvents_OnChanged(AcSmEvent ev, IAcSmPersist comp) { Autodesk.AutoCAD.ApplicationServices.Document activeDocument = default(Autodesk.AutoCAD.ApplicationServices.Document); activeDocument = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; AcSmSheet oSheet = default(AcSmSheet); AcSmSubset oSubset = default(AcSmSubset); if (ev == AcSmEvent.ACSM_DATABASE_OPENED) { activeDocument.Editor.WriteMessage("\n" + comp.GetDatabase().GetFileName() + " was opened."); } if (ev == AcSmEvent.ACSM_DATABASE_CHANGED) { activeDocument.Editor.WriteMessage("\n" + comp.GetDatabase().GetFileName() + " database changed."); } if (ev == AcSmEvent.SHEET_DELETED) { oSheet = (AcSmSheet)comp; activeDocument.Editor.WriteMessage("\n" + oSheet.GetName() + " was deleted."); } if (ev == AcSmEvent.SHEET_SUBSET_CREATED) { oSubset = (AcSmSubset)comp; activeDocument.Editor.WriteMessage("\n" + oSubset.GetName() + " was created."); } if (ev == AcSmEvent.SHEET_SUBSET_DELETED) { oSubset = (AcSmSubset)comp; activeDocument.Editor.WriteMessage("\n" + oSubset.GetName() + " was deleted."); } }
public void StepThroughOpenSheetSets() { // Get a reference to the Sheet Set Manager object IAcSmSheetSetMgr sheetSetManager = new AcSmSheetSetMgr(); // Get the loaded databases IAcSmEnumDatabase enumDatabase = sheetSetManager.GetDatabaseEnumerator(); // Get the first open database IAcSmPersist item = enumDatabase.Next(); string customMessage = ""; // If a database is open continue if ((item != null)) { int count = 0; // Step through the database enumerator while ((item != null)) { // Append the file name of the open sheet set to the output string customMessage = customMessage + "\n" + item.GetDatabase().GetFileName(); // Get the next open database and increment the counter item = enumDatabase.Next(); count = count + 1; } customMessage = "Sheet sets open: " + count.ToString() + customMessage; } else { customMessage = "No sheet sets are currently open."; } // Display the custom message MessageBox.Show(customMessage); }
// Synchronize the properties of a sheet with the sheet set private void SyncProperties(AcSmDatabase sheetSetDatabase) { // Get the objects in the sheet set IAcSmEnumPersist enumerator = sheetSetDatabase.GetEnumerator(); // Get the first object in the Enumerator IAcSmPersist item = enumerator.Next(); // Step through all the objects in the sheet set while ((item != null)) { IAcSmSheet sheet = null; // Check to see if the object is a sheet if (item.GetTypeName() == "AcSmSheet") { sheet = (IAcSmSheet)item; // Create a reference to the Property Enumerator for // the Custom Property Bag IAcSmEnumProperty enumeratorProperty = item.GetDatabase().GetSheetSet().GetCustomPropertyBag().GetPropertyEnumerator(); // Get the values from the Sheet Set to populate to the sheets string name = ""; AcSmCustomPropertyValue customPropertyValue = null; // Get the first property enumeratorProperty.Next(out name, out customPropertyValue); // Step through each of the properties while ((customPropertyValue != null)) { // Check to see if the property is for a sheet if (customPropertyValue.GetFlags() == PropertyFlags.CUSTOM_SHEET_PROP) { //// Create a reference to the Custom Property Bag //AcSmCustomPropertyBag customSheetPropertyBag = sheet.GetCustomPropertyBag(); //// Create a reference to a Custom Property Value //AcSmCustomPropertyValue customSheetPropertyValue = new AcSmCustomPropertyValue(); //customSheetPropertyValue.InitNew(sheet); //// Set the flag for the property //customSheetPropertyValue.SetFlags(customPropertyValue.GetFlags()); //// Set the value for the property //customSheetPropertyValue.SetValue(customPropertyValue.GetValue()); //// Create the property //customSheetPropertyBag.SetProperty(name, customSheetPropertyValue); SetCustomProperty(sheet, name, customPropertyValue.GetValue(), customPropertyValue.GetFlags()); } // Get the next property enumeratorProperty.Next(out name, out customPropertyValue); } } // Get the next Sheet item = enumerator.Next(); } }