1 / 39

Introduction to the AutoCAD 2006 Application Programming Interface

Introduction to the AutoCAD 2006 Application Programming Interface. AutoCAD 2006 API Overview. Agenda:. How to port your application to AutoCAD 2006 The New .NET Interface Why do we want to use .NET? How can I use it to develop with AutoCAD 2006? How can I build on top of my existing code?

shelby
Download Presentation

Introduction to the AutoCAD 2006 Application Programming Interface

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. Introduction to the AutoCAD 2006Application Programming Interface

  2. AutoCAD 2006 API Overview Agenda: • How to port your application to AutoCAD 2006 • The New .NET Interface • Why do we want to use .NET? • How can I use it to develop with AutoCAD 2006? • How can I build on top of my existing code? • ObjectARX API and UI customization updates • Where to learn more…

  3. The AutoCAD 2006 API Overview • The Rice • Making sure your application runs • Basic steps to support Rio • The Wine • Opportunities to add value • Leveraging the new features and API’s to increase the value of your and our products

  4. The Rice • Install Update • Test • That’s it – binary application compatibility! • Minor Registry version incremented to 16.2 • Installers need updating for this key • e.g. demand loading keys, etc.

  5. The Wine – New API’s • AutoCAD Managed .NET API • ObjectARX SDK and UI customization updates

  6. What is Microsoft .NET?What we know from our experience so far… • Intelligent symbolic representation • Mature language constructs • Collections, Events, Delegates • Common programming pitfalls addressed • Memory management, consistent Exception handling, unified strings • Source and binary inter-module communication • goes beyond C++ and COM • Meta data allows design- and run-time object usage and extension • Programming style • Multiple supported languages – Choose your weapons

  7. What is Microsoft .NET?More of what we know … • Common Base Class Library • Unified solutions for common design patterns • E.g. File I/O is the same for VB, C# and managed C++! • API Interop is very easy! • C++ and COM interop is built into .NET!

  8. Assembly IL Code Assembly IL Code Assembly IL Code CLRExecution Model Source code VB C# C++ Compiler vbc.exe csc.exe cc.exe Managed Code (dll or exe) Common Language Runtime JIT Compiler Native Code Operating System Services

  9. Why use the AutoCAD Managed API (.NET)?

  10. Programming in .NET - Advantages Clean memory management • Old Way (C++) - Potential for memory leaks! char *pName=(char*)malloc(128); strcpy(pName,"Hello"); //... free(pName); • New Way - .NET • C++ - String *pName=newString("Hello") • VB - Dim Name As String = "Hello" • C# - String Name=“Hello”; • // Garbage collection handles deallocation; no ‘delete’!

  11. Programming in .NET - Advantages Consistent exception handling • Old Way – VB: Can be very confusing and problematic! On Error GoTo UnexpectedError Dim x AsDouble = 10/0 ‘…error! UnexpectedError: MsgBox Str$(Err.Number) • New – VB .NET Try Dim x As Double= 10/0‘…error which throws exception Catch ‘…what happened? Division by Zero! Finally ‘…cleanup - do this either way End Try

  12. Programming in .NET - Advantages Strings are all Unicode! • Old Way – Unmanaged C++/COM CComBSTR bStr(newVal); COLE2T szName(bStr); _tcscpy(m_szLayer,szName); // <sigh> • New Way – .NET • C++: String *m_pszLayer=newString(newVal); • VB: Dim Name As String = newVal • C#: String Name=newVal;

  13. Why move to .NET in AutoCAD?Mature API constructs What’s wrong with this function declaration? int acedSSGet(constchar * str, const void * pt1, const void * pt2, const struct resbuf * filter, ads_name ss);

  14. Why move to .NET in AutoCADMature API constructs Some 6 new classes defined to encapsulate acedSSGet() Dim values() As TypedValue = { _ New TypedValue(DxfCode.Start, "CIRCLE"), _ New TypedValue(DxfCode.Color, 1) _ } Dim sfilter As New SelectionFilter(values) Dim SelOpts As New PromptSelectionOptions() SelOpts.MessageForAdding = "Select Red Circles:" SelOpts.AllowDuplicates = True Dim res As PromptSelectionResult = ed.GetSelection(SelOpts, sfilter)

  15. Why do we want to use .NET?Mature API constructs virtual Acad::ErrorStatus AcEdInputPointFilter::processInputPoint( bool& changedPoint, AcGePoint3d& newPoint, bool& displayOsnapGlyph, bool& changedTooltipStr, char*& newTooltipString, bool& retry, AcGiViewportDraw* drawContext, AcApDocument* document, bool pointComputed, int history, const AcGePoint3d& lastPoint, const AcGePoint3d& rawPoint, const AcGePoint3d& grippedPoint, const AcGePoint3d& cartesianSnappedPoint, const AcGePoint3d& osnappedPoint, AcDb::OsnapMask osnapMask, const AcArray<AcDbCustomOsnapMode*>& customOsnapModes, AcDb::OsnapMask osnapOverrides, const AcArray<AcDbCustomOsnapMode*>& customOsnapOverrides, const AcArray<AcDbObjectId>& pickedEntities, const AcArray< AcDbObjectIdArray, AcArrayObjectCopyReallocator< AcDbObjectIdArray > >& nestedPickedEntities, const AcArray<int>& gsSelectionMark, const AcArray<AcDbObjectId>& keyPointEntities, const AcArray< AcDbObjectIdArray, AcArrayObjectCopyReallocator< AcDbObjectIdArray > >& nestedKeyPointEntities, const AcArray<int>& keyPointGsSelectionMark, const AcArray<AcGeCurve3d*>& alignmentPaths, const AcGePoint3d& computedPoint, const char* tooltipString);

  16. Why do we want to use .NET?Mature API constructs Is now… ‘Define the event handler m_ed.PointMonitor += new PointMonitorEventHandler(callback_PointMonitor); ‘Define the callback function – no crazy reference parameters! private void callback_PointMonitor(object sender, PointMonitorEventArgs e) { WriteLine(String.Format("PointMonitor :", e.Context.ComputedPoint)); }

  17. AutoCAD .NET and C++ DevelopersTwo FAQs • Q: Why should an ObjectARX developer use managed C++? • Expose existing ARX code to managed languages • .NET platform development enhancements • Garbage collection, reflection, serialization, XML, etc. • WinForms • Access to AutoCAD Managed API beyond • Q: Why should an AutoCAD developer use C++? • Custom Object/Entity available in C++/ARX only. • Native platform interop - mixed managed and unmanaged code • Leverage C++’s unique strengths (e.g., templates, generic programming, multiple inheritance, deterministic resource management and cleanup) • C++ native platform performance edge

  18. AutoCAD .NET API Documentation How do I get started? ObjectARX SDK Includes: • SDK Samples! • ObjectARX Developer’s Guide • Managed Reference Guide • Acad_Mgd.chm • ADN extranet • DevNotes • DevHelp Online • Visual Studio Class Browser

  19. AutoCAD Database Ownership Hierarchy See the ObjectARX Developer’s Guide and SDK samples for reference…

  20. Important Managed Classes

  21. Demand Loading .NET applications [HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\R16.2\ACAD-4001:409\Applications\AcLayer] "DESCRIPTION"="AutoCAD Layer Manager" "LOADER"="C:\\Program Files\\AutoCAD 2006\\aclayer.dll" "LOADCTRLS"=dword:0000000e "MANAGED"=dword:00000001 [HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\R16.2\ACAD-4001:409\Applications\AcLayer\Commands] "LAYER"="LAYER" [HKEY_LOCAL_MACHINE\SOFTWARE\Autodesk\AutoCAD\R16.2\ACAD-4001:409\Applications\AcLayer\Groups] "ACLAYER_CMDS"="ACLAYER_CMDS“ Use Installers to set these keys!

  22. What’s new in AutoCAD’s .NET API ?What happened to Open/Close? Managed Applications use Transactions exclusively Why? • Exception handling is vastly simpler • Cleaner, more robust code • Less likely to leave objects in an open state • Performance is superior to Open/Close • Each Close() has associated overhead • Simultaneous write access • Multiple write-enabled pointers allowed • Nested transactions allowed

  23. Managed .NET API for AutoCAD 2006Using Open/Close with Exceptions • Try • BlockTable = Database.BlockTableId.Open(OpenMode.ForRead) • ModelSpace = BlockTable(BlockTableRecord.ModelSpace).Open(OpenMode.ForWrite) • Text = New MText • Text.SetContents("Hello World !!") • ModelSpace.AppendEntity(text) • Finally • If Not BlockTable Is Nothing Then • BlockTable.Close() • End If • If Not ModelSpace Is Nothing Then • ModelSplace.Close() • End If • If Not Text Is Nothing Then • Text.Close() • End If • End Try

  24. Managed .NET API for AutoCAD 2006Using Transactions with Exceptions • Dim Trans As Transaction • Trans = db.TransactionManager.StartTransaction() • Try • BlockTable = Trans.GetObject(Database.BlockTableId, OpenMode.ForRead) • ModelSpace = Trans.GetObject(BlockTable(BlockTableRecord.ModelSpace), OpenMode.ForWrite) • Text = New MText() • Text.Contents = "Hello World !!" • ModelSpace.AppendEntity(Text) • Trans.AddNewlyCreatedDBObject(Text, True) • Trans.Commit() • Finally • Trans.Dispose() • End Try

  25. 1 2 3 4 Transaction 2 obj2 obj3 obj2 obj3 Transaction 1 obj1 obj2 obj1 obj2 obj1 obj3 obj1 obj3 obj2 obj2 obj2 Nesting Transactions 1. Client starts Trans1 and gets Obj1 & Obj2 2. Client starts Trans2 and gets Obj2 & Obj3 3. Client commits Trans2 • Trans2 changes are committed 4a. Client commits Trans1 • Trans1 changes are committed 4b. Client aborts Trans1 instead • Trans1 (and Trans2) changes are rolled back obj1 obj3 obj2 Database

  26. Managed .NET API for AutoCAD 2006 AutoCAD 2006 Managed SDK Samples: • Tab Extension • Selection Set • Docking Palette • Events/Reactors • Custom Jig

  27. AutoCAD API Interoperability New API Development Existing code base

  28. ObjectARX Interop – Platform Invoke How do I access my old unmanaged code? Declare Auto Function MessageBox Lib "user32.dll" (ByVal hWnd As Integer, _ ByVal txt As String, ByVal caption As String, ByVal Typ As Integer) As Integer <Autodesk.AutoCAD.Runtime.CommandMethod("pinvoke")> _ Public Function platformInvoke() mgPolyTestApp.MessageBox(0, “Houston, we have a problem", "Platform Invoke Example", 0) End Function

  29. AutoCAD API Interoperability Mixed mode modules: Wrapping ObjectARX for a Managed API AutoCAD Unmanaged C++/ObjectARX API Mixed Module (e.g. acdbmgd.dll) It Just Works (IJW) and P/Invoke Managed C++ code C++ Only! AutoCAD 2006 .NET Applications (Any .NET language)

  30. ObjectARX Interop – Project Settings Setup for Managed C++ extensions in ObjectARX modules Compiler settings for using managed C++ • General – Use managed extensions = Yes • C++ - General – Compile as Managed = Assembly Support (/CLR) • C++ - General – Debug information format = not Edit and Continue • C++ - General – Detect 64-bit portability = No • C++ - Code Generation – Basic runtime checks = Default • C++ - Code Generation – Enable Minimal Rebuild =No • C++ - Precompiled Headers – Create/Use Precompiled header = No • Link – Input - Force Symbol References - __DllMainCRTStartup@12 • Link – Command Line – Addition Options - /NOENTRY Comment out dbgrip.h in dbxheaders.h (in the SDK includes) • Suggested: use #ifdef _MANAGED or similar for conditional #include Add references to standard and AutoCAD managed assemblies: #using <mscorlib.dll> #using <c:\Program Files\AutoCAD 2006\acmgd.dll> #using <c:\Program Files\AutoCAD 2006\acdbmgd.dll> //…and any others required for you Use the ‘managed’ compiler directive to compile managed ARX code #pragma managed Optional: Remove warnings regarding incompatibilities with __fastcall #pragma warning(disable: 4561)

  31. ObjectARX Interop – Entry Point /NOENTRY used in mixed managed modules – Use acrxEntryPoint instead: See: http://support.microsoft.com/?id=81442 extern "C" AcRx::AppRetCode acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt) { if(msg==AcRx::kInitAppMsg) __crt_dll_initialize();// Manually initialize static and global vars if(msg==AcRx::kPreQuitMsg) __crt_dll_terminate(); return AcRx::kRetOK; } Good News is: ObjectARX 2006 Wizard handles this for you in mixed-managed projects!!

  32. AutoCAD 2006: Dynamic Blocks API • API Provides programmatic manipulation of block intelligence • Access underlying intelligence of enhanced blocks • Managed, ActiveX and ObjectARX APIs • Developed managed API SDK Sample “DynBlockProps” – Modifying properties • Dynamic Blocks uses several new core API technologies • “Technology” APIs can be used as general purpose tools for existing ARX classes! • AcDbEvalGraph – provide intelligent inter-object references • AcDbBlockInsertionPoints – application-defined grip points for blocks • AcDbAlignment – intelligent alignment of entities • Includes managed RxEvent reactor delegate • SDK samples created to demonstrate core APIs • Specify Block Insertion points, Entity Grips, and Alignment

  33. 2006: New Classes and Enhancements New Compiler-neutral string utility class - AcString • No dependency on ATL/MFC • Provides conversion between UNICODE and ANSI • Comparable functionality to MFC’s ‘CString’ class • See the ‘SheetSet’ SDK sample New Arc-length Dimension class – AcDbArcDimension • Represents AutoCAD Arc length Dimensions Tool Palette ObjectARX/COM Enhancements • Context Menu enhancements • API Support for new Multi-Edit feature – IAcadTool2

  34. 2006: Menu and Toolbar Customization Only the file format Is different… Deployment model • Same as Menus/Toolbars • Per-user support folder • Existing ActiveX interface • Same as always

  35. AutoCAD 2006 API Wishlist Items in green delivered in AutoCAD 2006

  36. Where to Learn More – ADN and ADN Mentoring ADN • The Autodesk support program for professional software developers. • Unlimited direct support from Autodesk software engineers • Access to virtually all Autodesk software including betas (for software development use only) • Technical briefings and API training classes • Learn more at www.autodesk.com/joinadn ADN Mentoring Program • Onsite Mentoring by Autodesk software engineer for up to 1 week at your site • Offsite mentoring – phone, video email etc from engineer who visited • Complements ADNsupport: • Your mentor knows much more about your issues and can help direct you in the future • Your Mentor can liaise with internal Autodesk product and API experts • Your Mentor can access Autodesk source code, and internal knowledge bases

  37. Where to Learn More about .NET –Books & Blogs • Visual Basic .NET and the .NET Platform by Andrew Troelsen APress • Visual Basic .NET Programming by Gary Cornell and Jonathan Morrison APress • Applied Microsoft .NET Framework Programming by Jeffrey Richter Microsoft Press • Windows Forms Programming in C# by Chris Sells • Blogs (WebLogs) • MSDN

  38. Where to Learn More about .NET – Tips & Tricks • Reflector • Browse .NET assemblies, disassemble, decompile • http://sharptoolbox.madgeek.com • Ildasm • Disassemble .NET assemblies • Visual Studio Tools • Fuslogv • Diagnose load time problems • Visual Studio Tools • FxCop • Check conformance with Design Guidelines • http://www.gotdotnet.com/team/fxcop/

  39. Introduction to the AutoCAD 2006API

More Related