using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Windows.Documents;
using Autodesk.AutoCAD.Windows;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using ACSMCOMPONENTS20Lib;
// This line is not mandatory, but improves loading performances
[assembly
: CommandClass
(typeof(CLL_Drawing_list
.MyCommands))]
namespace CLL_Drawing_list
{
public class MyCommands
{
// Counts up the sheets for all the open sheet sets
[CommandMethod("SetSheetPropNames")]
public void SetSheetCount()
{
Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Document dwg = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument;
Editor ed = dwg.Editor;
PromptStringOptions ssFile
= new PromptStringOptions
("\nEnter Sheet Set Name: "); ssFile.AllowSpaces = true;
PromptResult ssFileRes = acDoc.Editor.GetString(ssFile);
string ssFilePath = (ssFileRes.StringResult);
AcSmSheetSetMgr sheetSetManager
= new AcSmSheetSetMgr
(); IAcSmDatabase db = sheetSetManager.OpenDatabase(ssFilePath , false);
IAcSmSheetSet ss = db.GetSheetSet();
int nSheetCount = 0;
//// 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();
AcSmDatabase sheetSetDatabase = default(AcSmDatabase);
while ((item != null))
{
sheetSetDatabase = (AcSmDatabase)item;
// Attempt to lock the database
if (LockDatabase(ref sheetSetDatabase, true) == true)
{
// Get the enumerator for the objects in the sheet set
IAcSmEnumPersist enumerator = sheetSetDatabase.GetEnumerator();
IAcSmPersist itemSheetSet = enumerator.Next();
// Step through the objects in the sheet set
while ((itemSheetSet != null))
{
// Increment the counter of the object is a sheet
if (itemSheetSet.GetTypeName() == "AcSmCustomPropertyValue")
{
nSheetCount = nSheetCount + 1;
ed.WriteMessage("\nNumber of Custom Property so far.." + nSheetCount.ToString());
AcSmCustomPropertyValue pv = (AcSmCustomPropertyValue)itemSheetSet;
try
{
string sValue = pv.GetValue().ToString();
ed.WriteMessage("\nThis item is......" + pv.GetValue().ToString());
}
catch { }
}
{
itemSheetSet = enumerator.Next();
}
}
// Create a sheet set property
// SetCustomProperty(sheetSetDatabase.GetSheetSet(), "Total Sheets", nSheetCount.ToString(), PropertyFlags.CUSTOM_SHEETSET_PROP);
// Unlock the database
LockDatabase(ref sheetSetDatabase, false);
// Clear and check for the next open sheet set
nSheetCount = 0;
}
else
{
MessageBox.Show("Unable to access " + sheetSetDatabase.GetSheetSet().GetName());
}
item = enumDatabase.Next();
}
}
// Used to lock/unlock a sheet set database
private bool LockDatabase(ref AcSmDatabase database, bool lockFlag)
{
bool dbLock = false;
// If lockFalg equals True then attempt to lock the database, otherwise
// attempt to unlock it.
if (lockFlag == true & database.GetLockStatus() == AcSmLockStatus.AcSmLockStatus_UnLocked)
{
database.LockDb(database);
dbLock = true;
}
else if (lockFlag == false && database.GetLockStatus() == AcSmLockStatus.AcSmLockStatus_Locked_Local)
{
database.UnlockDb(database, true);
dbLock = true;
}
else
{
dbLock = false;
}
return dbLock;
}
}
}
[code][/font]
[font=verdana]Any help would be appreciated [/font]
[font=verdana]Thank you[/font]