.NET

Reply
Active Member
olivier.eckmann
Posts: 7
Registered: ‎03-13-2012
Message 1 of 9 (453 Views)

Managing DLL to work with multiple version of AutoCAD

453 Views, 8 Replies
07-12-2012 03:04 AM

Hello,

 

How do you manage SourceCode and Dll, when you need to write an application which must work with multi-version of AutoCAD?

 

In my case, I've AutoCAD 2008, 2010 and 2012 installed in my company. When methods or properties have changed, I don't know if its possible to use the same DLL.

I develop for 2008 with framework 2.0 and it works fine, but for exemple on a DBText, in A2008, to read or assign ID of text style, the properties is DBText.TextStyle. In 2010, this property is now named DBText.TextStyleId  

Is it possible to compile only ONE version which could work for both AutoCAD?

 

Thanks

 

Olivier

Valued Mentor
AubelecBE
Posts: 391
Registered: ‎01-27-2010
Message 2 of 9 (450 Views)

Re: Managing DLL to work with multiple version of AutoCAD

07-12-2012 03:35 AM in reply to: olivier.eckmann

hi i have the same prob..  you cant have 1 DLL for acad 2010 and 2012

2010 --> framework v3.5

2012 --> framework v4

 

so you need 2 DLL..

 

no choose here.. :smileytongue:

 

Active Member
olivier.eckmann
Posts: 7
Registered: ‎03-13-2012
Message 3 of 9 (439 Views)

Re: Managing DLL to work with multiple version of AutoCAD

07-12-2012 04:49 AM in reply to: AubelecBE

Thanks, but it's not a problem for framework.

I've compiled my DLL to target Framework 2.0 (AnyCPU), so my DLL work fine from AutoCAD 2007 to AutoCAD 2012 32&64 bits .

Problem appears only when method or properties have changed between versions.

 

If it ins't possible to have only 1 DLL, is it possible to have only 1 code for sources (with IF DEF), certainly in 2 solutions to reference good AUtoCAD DLL?

 

Olivier

*Expert Elite*
_gile
Posts: 2,084
Registered: ‎04-29-2006
Message 4 of 9 (426 Views)

Re: Managing DLL to work with multiple version of AutoCAD

07-12-2012 07:17 AM in reply to: olivier.eckmann

Hi,

 

As far as I know, you have to compile 2 different projects but you can have them in the same solution and share the code with some 'conditional compilation'.

 

In your solution add a new project targeting the framework 3.5, reference the 2010 acdbmgd.dll and acmgd.dll, add a conditional compilation symbol (project propeties > Build tab) i.e. ACAD_18.

Right click on the new project > Add > Existing element > select your source codes in the old project and add them as links (popup the Add button)

Then in your source code, add some compilation conditions :

 

#if ACAD_18

    text.TextStyleId = id;

#else

    text TextStyle = id;

#endif

 

PS: feel free to ask this question on a french site (CADxp, AcadLabs, ExMateria), I 'd be more comfortable to reply in French.

Gilles Chanteau
Active Member
olivier.eckmann
Posts: 7
Registered: ‎03-13-2012
Message 5 of 9 (421 Views)

Re: Managing DLL to work with multiple version of AutoCAD

07-12-2012 08:08 AM in reply to: _gile

Thanks.

 

I try to apply your suggestion.

 

Olivier

 

PS: Merci, je pensais avoir plus de réponse sur le site US, d'où mon post. Si je n'y arrive pas, je posterais sur CadXP

*Expert Elite*
GTVic
Posts: 915
Registered: ‎09-07-2004
Message 6 of 9 (377 Views)

Re: Managing DLL to work with multiple version of AutoCAD

07-16-2012 10:33 AM in reply to: olivier.eckmann

You will definitely need a new project for 2013 because of the changed references. But for 2012 and earlier you can use a single project. Here is an example using reflection.

 

Dim ThisDoc As DocumentManager.MdiActiveDocument
Dim vcText As New VersionCode
Dim tsTable As TextStyleTable
Dim TextEnt As DBText
Dim tsTableID As ObjectId = ThisDoc.Database.TextStyleTableId
Dim Style as String = "Standard" Using Trans As Transaction = ThisDoc.TransactionManager.StartTransaction() tsTable = CType(Trans.GetObject(tsTableID , OpenMode.ForRead), TextStyleTable) vcText.SetTextStyleId(TextEnt, tsTable(Style)) ' for both 2009/2010
Trans.Commit()
End Using

--------

Imports Autodesk.AutoCAD.DatabaseServices
Imports System.Reflection

Public Class VersionCode

    Public Function GetTextStyleId(ByVal Instance As DBText) As ObjectId
        If textStyleProperty IsNot Nothing Then
            Return DirectCast(textStyleProperty.GetValue(Instance, Nothing), ObjectId)
        Else
            Throw New MissingMemberException()
        End If
    End Function

    Public Function GetTextStyleId(ByVal Instance As MText) As ObjectId
        If mtextStyleProperty IsNot Nothing Then
            Return DirectCast(mtextStyleProperty.GetValue(instance, Nothing), ObjectId)
        Else
            Throw New MissingMemberException()
        End If
    End Function

    Public Sub SetTextStyleId(ByVal Instance As DBText, ByVal value As ObjectId)
        If textStyleProperty IsNot Nothing Then
            textStyleProperty.SetValue(instance, value, Nothing)
        Else
            Throw New MissingMemberException()
        End If
    End Sub

    Public Sub SetTextStyleId(ByVal Instance As MText, ByVal value As ObjectId)
        If mtextStyleProperty IsNot Nothing Then
            mtextStyleProperty.SetValue(instance, value, Nothing)
        Else
            Throw New MissingMemberException()
        End If
    End Sub

    Public Sub New()
        textStyleProperty = GetType(DBText).GetProperty("TextStyle")
        If textStyleProperty Is Nothing Then
            textStyleProperty = GetType(DBText).GetProperty("TextStyleId")
        End If
        mtextStyleProperty = GetType(MText).GetProperty("TextStyle")
        If mtextStyleProperty Is Nothing Then
            mtextStyleProperty = GetType(MText).GetProperty("TextStyleId")
        End If
    End Sub

    Private textStyleProperty As PropertyInfo = Nothing
    Private mtextStyleProperty As PropertyInfo = Nothing

End Class

 

*Expert Elite*
GTVic
Posts: 915
Registered: ‎09-07-2004
Message 7 of 9 (374 Views)

Re: Managing DLL to work with multiple version of AutoCAD

07-16-2012 10:46 AM in reply to: GTVic

I also had an issue with 2013 where the DLLs for the COM components are different. What I did there to avoid multiple solutions was to create one solution with two projects. The second project referenced the 64-bit DLLs and what I did was Add>Existing Item... and then in the browse dialog I used the Add As Link option to add all the 32-bit code modules and forms to the 64-bit project. Then with a bit of fiddling with the output options I was able to create a 32-bit DLL and 64-bit DLL with one compile and one set of source code.

Valued Mentor
jeff
Posts: 330
Registered: ‎05-12-2009
Message 8 of 9 (370 Views)

Re: Managing DLL to work with multiple version of AutoCAD

07-16-2012 11:28 AM in reply to: GTVic
Active Member
olivier.eckmann
Posts: 7
Registered: ‎03-13-2012
Message 9 of 9 (356 Views)

Re: Managing DLL to work with multiple version of AutoCAD

07-17-2012 12:11 AM in reply to: GTVic

I succesfully use Add as link, to share source code and ressoures.

I don't know reflexion, but it seems to be a good solution, I try to explore this way too.

 

Thanks a lot for all of your answers.

 

Olivier

 

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.