Hi all!
I am mainly developing for AutoCAD 2013/2014 and I need some help to understand how to implement a custom property as a drop-down list using OPM and .NET/C# wrapper. I have successfully created categorized custom properties already and can read/save them in XRecords via the OPM. I further implemented the members for IDynamicEnumProperty (using an ObjectARX DLL) in .NET/C# which are:
// ENUM-PROPERTY INTERFACE METHODS DEFINITION enum myEnum { steel = 0, copper, wood }; public void GetNumPropertyValues( int numValues ) { numValues = 3; } public void GetPropValueName( int index, out String valueName ) { valueName = Enum.GetName(typeof(myEnum), index); } public void GetPropValueData( int index, ref Object valueName ) { valueName = index; }
And I have implemented the GetCurrentValueData() and SetCurrentValueData() members in my .NET/C# wrapper as per the IDynamicProperty2 interface as following:
public void GetCurrentValueData( Object pUnk, ref Object varData ) { AcadObject obj = pUnk as AcadObject; if ( obj != null ) { using ( Active.Document.LockDocument( DocumentLockMode.ProtectedAutoWrite, null, null, true ) ) { using ( var tr = Active.Transaction ) { ObjectId ObjId = new ObjectId( (IntPtr) obj.ObjectID ); DBObject DbObj = tr.GetObject( ObjId, OpenMode.ForRead ); if ( DbObj != null ) { try { if ( !DbObj.ExtensionDictionary.IsNull ) { DBDictionary xDict = tr.GetObject( DbObj.ExtensionDictionary, OpenMode.ForRead, false ) as DBDictionary; Xrecord xRec = new Xrecord(); xRec = tr.GetObject( xDict.GetAt( "myEnum" ), OpenMode.ForRead, false ) as Xrecord; ResultBuffer resbuf = xRec.Data; if ( resbuf != null ) { TypedValue[] result = resbuf.AsArray(); varData = (myEnum) Enum.ToObject( typeof( myEnum ), result[ 0 ].Value ); //varData = (int) result[ 0 ].Value; return; } } } catch ( Autodesk.AutoCAD.Runtime.Exception e ) { Console.Write( e ); tr.Abort(); } } } } } }
public void SetCurrentValueData( Object pUnk, Object varData ) { AcadObject obj = pUnk as AcadObject; if ( obj != null ) { using ( Active.Document.LockDocument( DocumentLockMode.ProtectedAutoWrite, null, null, true ) ) { using ( var tr = Active.Transaction ) { ObjectId ObjId = new ObjectId( (IntPtr) obj.ObjectID ); DBObject DbObj = tr.GetObject( ObjId, OpenMode.ForWrite ); if ( DbObj.ExtensionDictionary.IsNull ) DbObj.CreateExtensionDictionary(); if ( DbObj != null ) { DbObj.UpgradeOpen(); DBDictionary xDict = tr.GetObject( DbObj.ExtensionDictionary, OpenMode.ForWrite ) as DBDictionary; // the value 70 denotes an integer value ResultBuffer resBuf = new ResultBuffer( new TypedValue(70, myEnum.Wood) ); Xrecord xRec = new Xrecord(); xRec.Data = resBuf; xDict.SetAt( "myEnum", xRec ); tr.AddNewlyCreatedDBObject( xRec, true ); tr.Commit(); } else { tr.Abort(); } } } } m_pSink.OnChanged( this ); }
This code compiles without error but instead of the expected drop-down list the OPM only shows a field where I can enter or edit integer numbers, but there is no drop-down list when clicking on the field.No idea why this does not work ...
Hi Markus,
I have replied to your other post on this topic :