Message 1 of 12
Custom property in OPM
Not applicable
04-08-2013
10:25 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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