[Map 3D development practices series] Map Resource Explorer 3-add an AutoCAD-style Palette Interface

Source: Internet
Author: User

Directory

[Map 3D development practices series] background of Map Resource Explorer -- Kick off

[Map 3D development practices series] Map Resource Explorer 2-running and debugging

 

The previous article introduced how to create a project in Visual Studio to develop a Map 3D application, and compiled a very simple command line command. After loading our custom assembly using the netload command in Map 3D, enter the custom command to call related custom functions and implement our functions. In this form, we can write a lot of custom commands to develop more custom functions to expand Map 3D. However, in the actual project process, not only user-defined commands are used, but also interfaces are often displayed. For example, a dialog box may be displayed and other visual elements. This section describes how to add a user interface in AutoCAD Map 3D development.

 

As we mentioned above, Map 3D is a product based on AutoCAD. The rich APIs provided by AutoCAD. net api are used to create interfaces consistent with the AutoCAD style. Create an interface in Map 3D by using the AutoCAD. net api .. The release of Net framework 3.0 makes the development of WPF Technology in full swing. The Ribbon interface of AutoCAD also adopts the WPF technology. In order to make our program interface consistent with the AutoCAD Interface style, we also adopt the WPF Technology for the interface.

 

Adding a WPF Palette in AutoCAD is actually quite simple. First, add a WPF-based user control to our project.

You can use XAML to define your interface in this WPF user control, or use Microsoft Blend and other tools to design your user interface, which is not the focus of our discussion, if you are interested in WPF interface design, refer to MSDN or other materials. Now we are concerned about how to call in AutoCAD after such a WPF interface.

 

In AutoCAD, we can use the AutoCAD. net api to create a Palette and add this WPF user control to the Palette. See the following code:

 

 

// (C) Copyright 2002-2009 by Autodesk, Inc. //// Permission to use, copy, modify, and distribute this software in// object code form for any purpose and without fee is hereby granted, // provided that the above copyright notice appears in all copies and // that both that copyright notice and the limited warranty and// restricted rights notice below appear in all supporting // documentation.//// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS. // AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE.  AUTODESK, INC. // DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE// UNINTERRUPTED OR ERROR FREE.//// Use, duplication, or disclosure by the U.S. Government is subject to // restrictions set forth in FAR 52.227-19 (Commercial Computer// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)// (Rights in Technical Data and Computer Software), as applicable.//using System;using Autodesk.AutoCAD.Runtime;using Autodesk.AutoCAD.ApplicationServices;using Autodesk.AutoCAD.DatabaseServices;using Autodesk.AutoCAD.Geometry;using Autodesk.AutoCAD.EditorInput;using Autodesk.AutoCAD.Windows;namespace MyPaletteWebcast{  public class MyPlugin : IExtensionApplication  {    public void Initialize()    {      // Initialize your plug-in application here    }    public void Terminate()    {      // Do plug-in application clean up here    }    // create a reference to the modeless paletteset window    static PaletteSet ps = null;    static UserControl1 myUserControl = null;    // Define Command "MyCommand"    [CommandMethod("MyCommand")]    static public void MyCommand() // This method can have any name    {      // check to see if the ps is created      if (ps == null)      {        // create an instance of the ps        ps = new PaletteSet("MyCommand");        myUserControl = new UserControl1();        ps.AddVisual("MyPalette", myUserControl);      }      // show the paletteset      ps.Visible = true;    }  }}
 
Start AutoCAD, Map 3D, or Civil 3D, load the custom assembly using the netload command, and enter the custom command MyCommand to bring up the AutoCAD-style custom Palette.

 

With this simple code, we can define a custom command MyCommand. When executing this command, create a Palette to load the WPF user control and display it. Is it easy? You can also try it.

 

Now, let's take a look at the progress of Map 3D development.

 

Cheers,

Daniel

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.