1 / 30

Using .NET 4.0 with AutoCAD

Using .NET 4.0 with AutoCAD. Albert Szilvasy Software Architect, AutoCAD Team. Agenda. The basics Getting AutoCAD to boot .NET 4.0 Migrating apps Using new features now Type embedding, late binding in C# Dynamic Language Runtime Script Hosting Into the future

aricin
Download Presentation

Using .NET 4.0 with AutoCAD

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Using .NET 4.0 with AutoCAD Albert Szilvasy Software Architect, AutoCAD Team

  2. Agenda • The basics • Getting AutoCAD to boot .NET 4.0 • Migrating apps • Using new features now • Type embedding, late binding in C# • Dynamic Language Runtime • Script Hosting • Into the future • Implementing a dynamic type • More scriptable .NET API

  3. Booting .NET 4.0 in AutoCAD • .NET 4.0 does not automatically roll forward .NET 2.0 apps • Edit acad.exe.config and add the following <startup useLegacyV2RuntimeActivationPolicy="true"> <supportedRuntime version="v4.0"/> </startup> • .NET 4.0 Beta 2 is NOT compatible with AutoCAD 2010 • working with Microsoft to fix some issues • possibly some workarounds in Update 2

  4. Migrating C#/VB.NET apps • Simply open project in Visual Studio 2010 • Set Target Framework to .NET 4.0 • Client Profile will NOT work

  5. Migrating mixed mode apps • Trickier • C++ compiler/linker C/C++ runtime/ATL/MFC must stay on Visual Studio 2008 level • Linker errors due to mismatching metadata • Possible • Edit cl.exe.config and link.exe.config to bind them to .NET 4.0 • Apply workaround to avoid mismatching metadata error • #ifdef __CLR_VER • #if __CLR_VER > 20050727 • #error We can remove this workaround now. • #endif • #else • #define _TP_CALLBACK_ENVIRON _TP_CALLBACK_ENVIRON_workaround • #endif

  6. Using New Features Now

  7. Type embedding • Compiler embeds the interop types into your dll • Only the types that you actually use • Works for both VB and C# • Helpful if you use COM interop assemblies • Avoids having to redistribute interop assemblies for Office, other apps • Reduces the number of failure points • Easier deployment

  8. Demo: type embedding

  9. Late binding in C# • VB.NET has always had this feature • C# programmers had to use reflection • Slow and cumbersome • New dynamic keyword

  10. Late binding in C# • dynamic only exists at compile time, dynamic = object at runtime • Advantages • Easier to support incompatible versions of AutoCAD • Allows interop with scripting languages (Python, Ruby) • Disadvantage • No compile time checks, every error is a runtime error • Slightly slower

  11. Demo: Late binding in C#

  12. Dynamic Language Runtime • Open source project and it is also part of .NET 4.0 • Open source: http://www.codeplex.com/dlr • .NET 4.0: System.Core.dll • Built on top of the CLR • Key benefits • Makes it easier to implement a ‘dynamic’ language: • Python, Ruby (by Microsoft) • Scheme, a LISP dialect (http://ironscheme.codeplex.com/) • Dynamic features in ‘static’ languages (dynamic keyword in C#) • Enables interop between static and dynamic languages • C#/VB.NET classes can exhibit dynamic behavior • Common hosting model for dynamic languages

  13. Dynamic Language Runtime

  14. Script Hosting • DLR makes is easy to execute script written in any language that supports the DLR • The host can provide entry points: • ‘Application’ • ‘ThisDrawing’

  15. Scripts: Pluses and Minuses • Advantages • No build, restart cycle: good for quick experimentation • Easy, safe way to share scripts in clear text • Lot of languages are available • Python, ruby, scheme (today) • Vb.net, C#, others (years to come) • Full power of .NET/COM object model • Easier to maintain compatibility • Disadvantages • No integrated debugging (yet) • No intellisense (yet) • Just like LISP before VLIDE

  16. Demo: Simple IronPython integration

  17. Into the future

  18. Your Customization Experience

  19. Object Models in AutoCAD

  20. Programming Languages

  21. DLR preserves your investment DLR

  22. Exposing dynamic behavior • DLR allows applications to expose dynamic behavior • Why would you do this? • Provide convenient, lightweight syntax • Consider:

  23. Implementing a dynamic object • Multiple levels of engagement • Simple property bag: ExpandoObject • You simply instantiate this type • Easy and powerful: DynamicObject • Derive from this type • Does not work for value types • Full power but more work: DynamicMetaObject • Any type can implement IDynamicMetaObjectProvider • Must deal with Expression Trees (Abstract Syntax Tree)

  24. Making a smarter ObjectId • Implement IDynamicMetaObjectProvider • ObjectId “knows” the type of the object that it points to (see ObjectClass property) • ObjectId can expose all properties/method of the underlying object and inject Open/Close • Syntactically more pleasing • Easier to write correct code • Easy to implement, does not require advance knowledge properties/methods • Performance overhead is minimized by DLR callsite caching

  25. Expression Trees • Programs can be represented as trees operations (Abstract Syntax Trees) • A = 1+1 • DynamicMetaObject allows you to build Expression Trees on the fly and insert them into the AST generated by the compiler • DLR compiles the Expression Tree into IL = A + 1 1

  26. Demo: Smart ObjectId

  27. Disclaimer • Remember .NET 4.0 is still in beta • Lots of forward looking stuff here • Do NOT count on anything presented appear in shipping product

  28. Other resources • CP208-1: Developing for AutoCAD Using IronPython and IronRuby – Wednesday 10-11:30am • http://www.codeplex.com/dlr • http://www.codeplex.com/IronPython

  29. Questions?

More Related