using System; using System.Collections.Generic; using System.Linq; using System.Text; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.Aec.Building.ApplicationServices; using Autodesk.Aec.Building.DatabaseServices; using Autodesk.Aec.Building.Piping.DatabaseServices; using Autodesk.Aec.PropertyData.DatabaseServices; using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application; using AecPropDb = Autodesk.Aec.PropertyData.DatabaseServices; [assembly: CommandClass(typeof(CLMEP2012.CLMEPCommands))] namespace CLMEP2012 { public class CLMEPCommands { [CommandMethod("CLMEPTest", "CLMEP1", CommandFlags.Modal)] public void CLMEP1() { PromptEntityOptions peo = new PromptEntityOptions("\nSelect a pipe: "); peo.SetRejectMessage("\nNeed to select a pipe object!"); peo.AddAllowedClass(typeof(Pipe), true); peo.AllowNone = false; peo.AllowObjectOnLockedLayer = true; PromptEntityResult per = ActiveDwg.Editor.GetEntity(peo); if (per.Status != PromptStatus.OK) return; Transaction trans = ActiveDwg.TransactionManager.StartTransaction(); try { Pipe pipe = per.ObjectId.GetObject(OpenMode.ForRead) as Pipe; PipeSystemDefinition sysDef = pipe.SystemId.GetObject(OpenMode.ForRead) as PipeSystemDefinition; ActiveDwg.Editor.WriteMessage("\nSystem def: {0}", sysDef.Name); DataRecord datRec = PartManager.GetEngineeringData(pipe); DataField engField = datRec.DataFields.FindByContext(Context.RoutingPreferenceId); PipePartRoutingPreferencesStyle routePref = engField.ValueObjectId.GetObject(OpenMode.ForRead) as PipePartRoutingPreferencesStyle; ActiveDwg.Editor.WriteMessage("\nRouting pref: {0}", routePref.Name); datRec = PartManager.GetPartData(pipe); //foreach (DataField df in datRec.DataFields) //{ // ActiveDwg.Editor.WriteMessage("\n{0} - {1} - {2} - {3} - {4} - {5} - {6}", // df.Context, df.ContextString, df.Index, df.Name, df.PropertySetUsage, df.Type, df.Units); //} engField = datRec.DataFields.FindByContextAndIndex(Context.ConnectionSizeNominalDiameter, 1); ActiveDwg.Editor.WriteMessage("\nNom Size: {0}", engField.ValueDouble); } catch (Autodesk.AutoCAD.Runtime.Exception ex) { ActiveDwg.Editor.WriteMessage("\nCLMEP1 - AutoCAD Exception: " + ex.ErrorStatus.ToString()); } catch (System.Exception ex) { ActiveDwg.Editor.WriteMessage("\nCLMEP1 - System Exception: " + ex.Message); } finally { trans.Commit(); trans.Dispose(); } } } }