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

Custom property in OPM

11 REPLIES 11
Reply
Message 1 of 12
jonathantourtois
2434 Views, 11 Replies

Custom property in OPM

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

 

 

11 REPLIES 11
Message 2 of 12

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
AutoCAD Engineering
Autodesk

Message 3 of 12

Hi Fenton,

Thanks for your reply,

 

Yes, of course... 😉

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

Message 4 of 12

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




Fenton Webb
AutoCAD Engineering
Autodesk

Message 5 of 12

The project is here...

Thank you

Message 6 of 12

Hi Fenton,

 

Have you had time for looking at these files ? 

Message 7 of 12

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
AutoCAD Engineering
Autodesk

Message 8 of 12

No problmem. Thank you guys for helping people like me... 🙂

 

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 ?!??

Message 9 of 12

try building your app as x86 rather than Any CPU




Fenton Webb
AutoCAD Engineering
Autodesk

Message 10 of 12

I tried, it did not change anything ...

Message 11 of 12

I compiled these 2 DLLs - one for 32bit and one for 64bit




Fenton Webb
AutoCAD Engineering
Autodesk

Message 12 of 12

...thank you Fenton, I've just tried the 32bits-dll, but it doesn't work. 😞

Still the same error...

And as Kean's DLL, yours only works for C# code.

 

Have you tried running my own code ? Have you like me the issue with the same TypeLoadException ?

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