Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Thursday, December 29, 2011

Use COM Interoperability with .NET


Limitations and Using Interop (COM)
The .NET API does not expose all the functionality of AutoCAD Civil 3D, and it exposes less than the COM API. The following areas are not yet exposed in .NET:

  • Survey
  • Points
  • Surfaces
  • Sites and Parcels
  • Sections
  • Data Bands
  • Labels (except Alignment, Profile and Profile View labels)
In addition, there are some areas in implemented functionality that are not yet complete:

  • Pipes: interference checks (except interference check styles)
  • Corridors:
    • creating new corridors
    • adding baselines to corridors
    • creating or modifying corridor boundaries or masks
    • creating featurelines from polylines
    • computing cut and fill
    • setting the CodeSetStyle
If you require this functionality in your .NET project, you can use the corresponding COM objects.

To use AutoCAD Civil 3D COM APIs from .NET
  1. Create a .NET solution and project.
  2. Select Add Reference from the Project menu or Solution Explorer.
  3. On the COM tab, select the AutoCAD 2011 Type Library and the AutoCAD/ObjectDBX Common 18.0 Type Library.
  4. On the COM tab, selec the AEC Base 6.5 Application Library and the AEC Base 6.5 Object Library.
  5. On the COM tab, select the required Autodesk Civil Engineering 8.0 libraries for the functionality you require (for example, Land and UI Land for Alignments).
  6. Add the Autodesk.AutoCAD.Interop and Autodesk.AECC.Interop.Ui namespaces to your using or Imports statement.
NoteYou may see warnings about types not being found in various Autodesk.AutoCAD.Interop namespaces (warning type 1684). To disable these warnings, enter 1684 under Supress Warnings on the Build tab of the project’s properties.

In case libraries are not showed in the COM tab, they can be loaded by corresponding tlb files:

  • The AutoCAD 2010 type library, acax18enu.tlb, located at :\Program Files\Common Files\Autodesk Shared.
  • The AutoCAD/ObjectDBX Common 18.0 type library, axdb18enu.tlb, located at :\Program Files\Common Files\Autodesk Shared.
  • Autodesk Civil Engineering 8.0 libraries (for example, Land and UI Land), located at :\Program Files\Common Files\Autodesk Shared\Civil Engineering 80\Aecc*.tlb

Thursday, January 27, 2011

Optimizing the loading of AutoCAD .NET applications

Optimizing the loading of AutoCAD .NET applications
http://through-the-interface.typepad.com/through_the_interface/2006/09/optimizing_the_.html

Automatic loading of .NET modules
http://through-the-interface.typepad.com/through_the_interface/2006/09/automatic_loadi.html

Sunday, November 21, 2010

Tạo Windows Form trong AutoCAD .Net

Showing a splash-screen from your AutoCAD .NET application

(http://through-the-interface.typepad.com/through_the_interface/2007/06/showing_a_splas.html)

Thanks once again to Viru Aithal for the inspiration behind this post, although I did write most of the code, this time. :-)
Adding a splash screen can give a touch of class to your application, assuming it's done non-intrusively. This post focuses on how best to do so within AutoCAD, and use the time it's displayed to perform initialization for your application.
The first thing you need to do is add a Windows Form to your project:
Splash_screen_1
You should select the standard "Windows Form" type, giving an appropriate name (in this case I've used "SplashScreen", imaginatively enough).
Splash_screen_2
Once this is done, you should set the background for the form to be your preferred bitmap image, by browsing to it from the form's BackgroundImage property:
Splash_screen_3
Now we're ready to add some code. Here's some C# code that shows how to show the splash-screen from the Initialize() method:

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Prompts; // This is the name of the module

namespace SplashScreenTest
{
  public class Startup : IExtensionApplication
  {
    public void Initialize()
    {
      SplashScreen ss = new SplashScreen();

      // Rather than trusting these properties to be set
      // at design-time, let's set them here
      ss.StartPosition =
        System.Windows.Forms.FormStartPosition.CenterScreen;
      ss.FormBorderStyle =
        System.Windows.Forms.FormBorderStyle.None;
      ss.Opacity = 0.8;
      ss.TopMost = true;
      ss.ShowInTaskbar = false;

      // Now let's disply the splash-screen
      Application.ShowModelessDialog(
        Application.MainWindow,
        ss,
        false
      );
      ss.Update();

      // This is where your application should initialise,
      // but in our case let's take a 3-second nap
      System.Threading.Thread.Sleep(3000);

      ss.Close();
    }
    public void Terminate()
    {
    }
  }
}
Some notes on the code:
  • I used a sample application called "Prompts" - you should change the using directive to refer to your own module name.
  • We're setting a number of properties dynamically (at runtime), rather than stepping through how to set them at design-time.
  • We've set the splash screen to be 80% opaque (or 20% transparent). This is easy to adjust.
  • Some of the additional properties may be redundant, but they seemed sensible to set (at least to me).
Here's the result... I've set up my application to demand-load when I invoke a command, which allowed me to load a DWG first to show off the transparency of the splash-screen (even though the above code doesn't actually define a command - so do expect an "Unknown command" message, if you do exactly the same thing as I have). You may prefer to set the module to load on AutoCAD startup, otherwise.
Splash_screen_4

Update:
Roland Feletic brought it to my attention that this post needed updating for AutoCAD 2010. Thanks, Roland!
I looked into the code, and found that the call to ShowModelessDialog needed changing to this:
      Application.ShowModelessDialog(
        Application.MainWindow.Handle,
        ss,
        false
      );
I also found I had to add an additional assembly reference to PresentationCore (a .NET Framework 3.0 assembly).