Skip to content
| Marketplace
Sign in
Visual Studio>Templates>AutoCADPluginTemplate
AutoCADPluginTemplate

AutoCADPluginTemplate

方敏

|
39 installs
| (0) | Free
AutoCAD2025 .NET8.0 Plugin Project Template v0.0.2
Download

AutoCAD2025 .NET8.0 插件项目模版 v0.0.2

1、框架

基于AutoCAD2025 .NET8.0框架的AutoCAD类库模版 由AutoCADPluginProject.csproj、AcadCmds.cs、GlobalUsing.cs三个文件构成!

2、文件内容

AutoCADPluginProject.csproj内容:

<Project Sdk="Microsoft.NET.Sdk">
	<PropertyGroup>
		<TargetFramework>net8.0-windows</TargetFramework>
		<ImplicitUsings>enable</ImplicitUsings>
		<Nullable>enable</Nullable>
		<LangVersion>preview</LangVersion>
		<UseWPF>true</UseWPF>
		<UseWindowsForms>true</UseWindowsForms>
	</PropertyGroup>

	<!--<ItemGroup>
		<FrameworkReference Include="Microsoft.WindowsDesktop.App"></FrameworkReference>
	</ItemGroup>-->

	<ItemGroup>
		<PackageReference Include="AutoCAD.NET" Version="25.0.1" />
	</ItemGroup>
</Project>

AcadCmds.cs内容:

[assembly: CommandClass(typeof($safeprojectname$.AcadCmds))]
[assembly: ExtensionApplication(typeof($safeprojectname$.AcadCmds))]

namespace $safeprojectname$;

public class AcadCmds : IExtensionApplication
{
    public void Initialize()
    {
        // 如果需要将程序的目录加入信任路径,将下行代码取消注释
        // AppendSupportPath(CurrentDirectory.FullName);
    }

    public void Terminate()
    {
        // 这里不能调用输出函数,因为这个函数执行的时候,已经没有editor对象了。
        // 所以如果不是想要在cad关闭的时候清理某些东西,这里不用写任何的代码。
    }

    /// <summary>
    /// 查看所有功能命令-See Command
    /// </summary>
    [Description("查看所有功能命令-See All Command")]
    [CommandMethod(nameof(SACMD), CommandFlags.Session | CommandFlags.UsePickSet)]
    public void SACMD()
    {
        var type = typeof(AcadCmds);
        // 仅获取自己编写的方法
        var methods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
        foreach (MethodInfo method in methods)
        {
            if (method != null)
            {
                var attributes = method.GetCustomAttributes(typeof(DescriptionAttribute), false);
                if (attributes.Length > 0)
                {
                    
                    var descAttr = attributes[0] as DescriptionAttribute;
                    Acap.DocumentManager.MdiActiveDocument.Editor.WriteMessage($"\n{method.Name};{descAttr?.Description}");
                }
            }
        }
    }

    /// <summary>
    /// Your Command Description
    /// </summary>
    [Description("Your Command Description")]
    [CommandMethod(nameof(YourCommand), CommandFlags.Session | CommandFlags.UsePickSet)]
    public void YourCommand()
    {
        //Your Codes
    }
}

GlobalUsing.cs内容:

#region System Using
global using System;
global using System.Collections.Generic;
global using System.Linq;
global using System.Text;
global using System.Threading.Tasks;
global using System.ComponentModel;
global using System.Reflection;
#endregion System Using

#region AutoCAD Using
global using Autodesk.AutoCAD.Runtime;
global using Autodesk.AutoCAD.EditorInput;
global using Autodesk.AutoCAD.DatabaseServices;
global using Acap = Autodesk.AutoCAD.ApplicationServices.Application;
global using Acaop = Autodesk.AutoCAD.ApplicationServices.Core.Application;
#endregion AutoCAD Using
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft