首页
/ The Building Coder Samples 开源项目教程

The Building Coder Samples 开源项目教程

2024-08-20 16:26:00作者:房伟宁

1. 项目的目录结构及介绍

The Building Coder Samples 项目的目录结构如下:

the_building_coder_samples/
├── bin
├── doc
├── lib
├── res
├── src
│   ├── Cmd
│   ├── ExternalCommands
│   ├── ModelessForm
│   ├── Ribbon
│   └── Util
├── tools
└── README.md

目录介绍

  • bin: 存放编译后的可执行文件。
  • doc: 存放项目文档。
  • lib: 存放项目依赖的库文件。
  • res: 存放资源文件,如图片、配置文件等。
  • src: 源代码目录,包含多个子目录,如 Cmd, ExternalCommands, ModelessForm, Ribbon, Util 等。
    • Cmd: 包含命令行工具的源代码。
    • ExternalCommands: 包含外部命令的源代码。
    • ModelessForm: 包含无模式窗体的源代码。
    • Ribbon: 包含Ribbon界面的源代码。
    • Util: 包含工具类和辅助函数的源代码。
  • tools: 存放项目开发和构建工具。
  • README.md: 项目说明文件。

2. 项目的启动文件介绍

项目的启动文件通常位于 src 目录下,具体位置可能因项目结构而异。在 The Building Coder Samples 项目中,启动文件可能位于 src/Cmdsrc/ExternalCommands 目录下。

例如,src/Cmd/CmdStart.cs 可能是一个启动文件,其主要功能是初始化项目并启动主程序。

using System;
using Autodesk.Revit.UI;

namespace the_building_coder_samples
{
    [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    public class CmdStart : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            try
            {
                // 初始化代码
                return Result.Succeeded;
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return Result.Failed;
            }
        }
    }
}

3. 项目的配置文件介绍

项目的配置文件通常用于存储项目的设置和参数。在 The Building Coder Samples 项目中,配置文件可能位于 res 目录下,例如 res/config.xml

配置文件示例

<configuration>
  <appSettings>
    <add key="LogLevel" value="Debug"/>
    <add key="OutputPath" value="bin"/>
  </appSettings>
  <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=.;Initial Catalog=MyDatabase;Integrated Security=True"/>
  </connectionStrings>
</configuration>

配置文件介绍

  • appSettings: 存储应用程序的设置,如日志级别 (LogLevel) 和输出路径 (OutputPath)。
  • connectionStrings: 存储数据库连接字符串,如默认连接 (DefaultConnection)。

通过这些配置文件,可以方便地管理和修改项目的运行参数,而无需修改源代码。

登录后查看全文
热门项目推荐