.NET

Reply
Active Member
jonathantourtois
Posts: 9
Registered: ‎04-08-2013
Message 1 of 12 (680 Views)

Custom property in OPM

680 Views, 11 Replies
04-08-2013 10:25 AM

Hi,

 

I'm trying to translate the C# code from this post to VB.NET.

It's about exposing an ObjectARX module to .NET.

 

I've ever tried converting by hand, or even with online converters. In both case, I've no syntax errors, but when I run the VB.NET code, I get a singular "TypeLoadException: Signature of the body and declaration in a method implementation do not match." during the MyEntryPoint.Initialize method.

I don't get this exception when I run the C# code.

I'm using AutoCAD 2012 32bits.

 

So what's wrong ? Could a guru here help me, please ?

 

Public Class EntryPoint
        Implements IExtensionApplication

        Private custProp As CustomProp = Nothing

        Public Sub Initialize() Implements IExtensionApplication.Initialize
            Dim folderPath As String = System.IO.Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly.Location)
            Dim assemblyPath = System.IO.Path.Combine(folderPath, "asdkOPMNetExt.dll")
            Reflection.Assembly.LoadFrom(asdkOPMNetExt.dll)
'Add the Dynamic Property
Dim classDict As Dictionary = SystemObjects.ClassDictionary
Dim lineDesc As RXClass = DirectCast(classDict.At("AcDbLine"), RXClass)
Dim pPropMan As IPropertyManager2 = DirectCast(xOPM.xGET_OPMPROPERTY_MANAGER(lineDesc), IPropertyManager2)
custProp = New CustomProp() pPropMan.AddProperty(DirectCast(custProp, Object))
End Sub

Public Sub Terminate() Implements IExtensionApplication.Terminate
' Remove the Dynamic Property
Dim classDict As Dictionary = SystemObjects.ClassDictionary
Dim lineDesc As RXClass = DirectCast(classDict.At("AcDbLine"), RXClass)
Dim pPropMan As IPropertyManager2 = DirectCast(xOPM.xGET_OPMPROPERTY_MANAGER(lineDesc), IPropertyManager2)
pPropMan.RemoveProperty(DirectCast(custProp, Object))
custProp = Nothing
End Sub
End Class

 

 <Guid("F60AE3DA-0373-4d24-82D2-B2646517ABCB"), ProgId("OPMNetSample.CustomProperty.1"), ClassInterface(ClassInterfaceType.None), ComDefaultInterface(GetType(IDynamicProperty2)), ComVisible(True)> _
    Public Class CustomProp
        Implements IDynamicProperty2
        Private m_pSink As IDynamicPropertyNotify2 = Nothing

        ' Unique property ID

        Public Sub GetGUID(ByRef propGUID As Guid) Implements IDynamicProperty2.GetGUID
            propGUID = New Guid("F60AE3DA-0373-4d24-82D2-B2646517ABCB")
        End Sub

        ' Property display name

        Public Sub GetDisplayName(ByRef szName As String) Implements IDynamicProperty2.GetDisplayName
            szName = "My integer property"
        End Sub

        ' Show/Hide property in the OPM, for this object instance

        Public Sub IsPropertyEnabled(pUnk As Object, ByRef bEnabled As Integer) Implements IDynamicProperty2.IsPropertyEnabled
            bEnabled = 1
        End Sub

        ' Is property showing but disabled

        Public Sub IsPropertyReadOnly(ByRef bReadonly As Integer) Implements IDynamicProperty2.IsPropertyReadOnly
            bReadonly = 0
        End Sub

        ' Get the property description string

        Public Sub GetDescription(ByRef szName As String) Implements IDynamicProperty2.GetDescription
            szName = "This property is an integer"
        End Sub

        ' OPM will typically display these in an edit field
        ' optional: meta data representing property type name,
        ' ex. ACAD_ANGLE

        Public Sub GetCurrentValueName(ByRef szName As String) Implements IDynamicProperty2.GetCurrentValueName
            Throw New System.NotImplementedException()
        End Sub

        ' What is the property type, ex. VT_R8

        Public Sub GetCurrentValueType(ByRef varType As UShort) Implements IDynamicProperty2.GetCurrentValueType
            ' The Property Inspector supports the following data
            ' types for dynamic properties:
            ' VT_I2, VT_I4, VT_R4, VT_R8,VT_BSTR, VT_BOOL
            ' and VT_USERDEFINED.

            varType = 3
            ' VT_I4
        End Sub

        ' Get the property value, passes the specific object
        ' we need the property value for.

        Public Sub GetCurrentValueData(pUnk As Object, ByRef pVarData As Object) Implements IDynamicProperty2.GetCurrentValueData
            ' TODO: Get the value and return it to AutoCAD

            ' Because we said the value type was a 32b int (VT_I4)
            pVarData = CInt(4)
        End Sub

        ' Set the property value, passes the specific object we
        ' want to set the property value for

        Public Sub SetCurrentValueData(pUnk As Object, varData As Object) Implements IDynamicProperty2.SetCurrentValueData
            ' TODO: Save the value returned to you

            ' Because we said the value type was a 32b int (VT_I4)
            Dim myVal As Integer = CInt(varData)
        End Sub

        ' OPM passes its implementation of IDynamicPropertyNotify, you
        ' cache it and call it to inform OPM your property has changed

        Public Sub Connect(pSink As Object) Implements IDynamicProperty2.Connect
            m_pSink = DirectCast(pSink, IDynamicPropertyNotify2)
        End Sub

        Public Sub Disconnect() Implements IDynamicProperty2.Disconnect
            m_pSink = Nothing
        End Sub
    End Class

 

 

ADN Support Specialist
fenton.webb
Posts: 352
Registered: ‎07-24-2007
Message 2 of 12 (658 Views)

Re: Custom property in OPM

04-08-2013 03:14 PM in reply to: jonathantourtois

Why are you trying to convert it? It's just a waste of time :-) Just reference the code (via a C# DLL) from your VB.NET code and be done?

 

 





Fenton Webb

Developer Technical Services

Autodesk Developer Network


Active Member
jonathantourtois
Posts: 9
Registered: ‎04-08-2013
Message 3 of 12 (654 Views)

Re: Custom property in OPM

04-08-2013 03:22 PM in reply to: fenton.webb

Hi Fenton,

Thanks for your reply,

 

Yes, of course... :smileywink:

But I would like to undestand why it does work in VB...?! Any idea ?

 

Also, thinking about referencing it, how could i add more custom properties : would I have to duplicate this C# code n-times ?...

 

In fact, the goal was to write some "generic code", something like an abstract class...

ADN Support Specialist
fenton.webb
Posts: 352
Registered: ‎07-24-2007
Message 4 of 12 (651 Views)

Re: Custom property in OPM

04-08-2013 03:37 PM in reply to: jonathantourtois

If you send me a build able "ready to go" project, I'll take a look for ya...





Fenton Webb

Developer Technical Services

Autodesk Developer Network


Active Member
jonathantourtois
Posts: 9
Registered: ‎04-08-2013
Message 5 of 12 (630 Views)

Re: Custom property in OPM

04-08-2013 10:56 PM in reply to: fenton.webb

The project is here...

Thank you

Active Member
jonathantourtois
Posts: 9
Registered: ‎04-08-2013
Message 6 of 12 (602 Views)

Re: Custom property in OPM

04-10-2013 11:36 PM in reply to: jonathantourtois

Hi Fenton,

 

Have you had time for looking at these files ? 

ADN Support Specialist
fenton.webb
Posts: 352
Registered: ‎07-24-2007
Message 7 of 12 (582 Views)

Re: Custom property in OPM

04-11-2013 11:05 AM in reply to: jonathantourtois

Sorry for the delay.

 

The problem is that, as with all mixed mode DLLs, you need a specific 32bit and 64bit versions to target both 32bit and 64bit versions of AutoCAD. You are referencing the 64bit version and running it on a 32bit version of AutoCAD.





Fenton Webb

Developer Technical Services

Autodesk Developer Network


Active Member
jonathantourtois
Posts: 9
Registered: ‎04-08-2013
Message 8 of 12 (576 Views)

Re: Custom property in OPM

04-11-2013 11:32 AM in reply to: fenton.webb

No problmem. Thank you guys for helping people like me... :smileyhappy:

 

I still don't understand. According to comments in Kean's blog, this DLL runs on 32bit systems (which is my case, too).

 

Besides, I have no errors when I run the C#-version of the code, only in VB.net (using the same machine, the same environnement, the same AutoCAD-version...)

Amazing ?!??

ADN Support Specialist
fenton.webb
Posts: 352
Registered: ‎07-24-2007
Message 9 of 12 (572 Views)

Re: Custom property in OPM

04-11-2013 11:49 AM in reply to: jonathantourtois

try building your app as x86 rather than Any CPU





Fenton Webb

Developer Technical Services

Autodesk Developer Network


Active Member
jonathantourtois
Posts: 9
Registered: ‎04-08-2013
Message 10 of 12 (570 Views)

Re: Custom property in OPM

04-11-2013 11:55 AM in reply to: fenton.webb

I tried, it did not change anything ...

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.