.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to code a drop-down list for a custom property using OPM and .NET/C# ?

1 REPLY 1
Reply
Message 1 of 2
markus.keller
1369 Views, 1 Reply

How to code a drop-down list for a custom property using OPM and .NET/C# ?

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 ... Smiley Sad

 

Regards,
Markus
1 REPLY 1
Message 2 of 2
Balaji_Ram
in reply to: markus.keller

Hi Markus,

 

I have replied to your other post on this topic :

http://forums.autodesk.com/t5/NET/How-to-implement-Drop-down-list-based-on-IDynamicEnumProperty-in/t...



Balaji
Developer Technical Services
Autodesk Developer Network

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost