/* Sample output at command line: Command: CLROOMAREAS Office 1, room 101, area: 10776.25 Office 2, room 102, area: 16326.25 */ using System; using System.Collections.Generic; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Geometry; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //In addition to autocad std references, added references to: // AecArchMgd.dll // AecBaseMgd.dll // AecBaseUtilsMgd.dll // AecPropDataMgd.dll using Autodesk.Aec.PropertyData.DatabaseServices; using Autodesk.Aec.DatabaseServices; using Autodesk.Aec.Arch.DatabaseServices; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [assembly: CommandClass(typeof(CLMEP2013.MainCommands2))] namespace CLMEP2013 { public class MainCommands2 { [CommandMethod("CLMEPGROUP", "CLROOMAREAS", CommandFlags.Modal)] public void CLROOMAREAS() { Document curDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database curDb = curDoc.Database; Editor curEd = curDoc.Editor; Transaction trans = curDb.TransactionManager.StartTransaction(); try { BlockTableRecord curDwgSpace = curDb.CurrentSpaceId.GetObject(OpenMode.ForRead) as BlockTableRecord; foreach (Autodesk.AutoCAD.DatabaseServices.ObjectId id in curDwgSpace) { Autodesk.AutoCAD.DatabaseServices.DBObject obj = id.GetObject(OpenMode.ForRead); if (obj.GetType() != typeof(Autodesk.Aec.Arch.DatabaseServices.Space)) continue; Space spaceObj = obj as Space; string spaceName = spaceObj.Name; double spaceArea = spaceObj.Area; Autodesk.AutoCAD.DatabaseServices.ObjectIdCollection idCol = PropertyDataServices.GetPropertySets(spaceObj); foreach (Autodesk.AutoCAD.DatabaseServices.ObjectId propId in idCol) { Autodesk.AutoCAD.DatabaseServices.DBObject propObj = propId.GetObject(OpenMode.ForRead); if (propObj.GetType() == typeof(PropertySet)) { PropertySet propSet = propObj as PropertySet; PropertySetDataCollection dataCol = propSet.PropertySetData; foreach (PropertySetData setdata in dataCol) { string name = propSet.PropertyIdToName(setdata.Id); if (name != "Number") continue; PropertyValueUnitPair valPair = propSet.GetValueAndUnitAt(setdata.Id); curEd.WriteMessage("\n{0}, room {1}, area: {2}", spaceName, valPair.Value, spaceArea); } } } } } catch (Autodesk.AutoCAD.Runtime.Exception ex) { curEd.WriteMessage("\nAutoCAD Exception: {0}", ex.ErrorStatus); } catch (System.Exception ex) { curEd.WriteMessage("\nSystem Exception: {0}", ex.Message); } finally { trans.Commit(); trans.Dispose(); } } } }