Revit属性集验证工具

一个实现Revit IFC源代码中精确解析逻辑的CLI工具和MCP服务器,用于验证Revit属性集(PSET)定义文件。

  • by byggstyrning
  • Python
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 byggstyrning/revit-pset-validator

使用说明

Revit PSET验证器

用于验证Revit特性集(PSET)定义文件的CLI工具和MCP服务器

一个直接的验证器,从Revit IFC源代码中实现精确的解析逻辑(PropertyMap.cs)并检查常见问题。该工具既可以作为独立的CLI使用,也可以作为MCP服务器使用。

特性

  • ✅ 精确的Revit解析逻辑 -完全匹配PropertyMap.cs行为
  • ✅ 关键验证 -检测实体名称大小写问题(IFCSPACE与IFCSPACE)
  • ✅ 全面检查 -验证数据类型、结构、重复项等
  • ✅ CLI工具 -独立命令行界面
  • ✅ MCP服务器 -用于AI集成的模型上下文协议服务器
  • ✅ 清除错误消息 -行号和修复建议
  • ✅ JSON输出 -用于自动化的机器可读输出

快速开始

安装

# Clone repository
git clone https://github.com/byggstyrning/revit-pset-validator.git
cd revit-pset-validator

# Install dependencies
pip install -e .

# Or install with dev dependencies
pip install -e ".[dev]"

从PyPI安装(如果可用)

pip install revit-pset-validator

CLI使用情况

# Validate a PSET file
python -m pset_validator PSET-SPECIFIC.txt

# JSON output for automation
python -m pset_validator PSET-SPECIFIC.txt --format json

# Exit code on errors (for CI/CD)
python -m pset_validator PSET-SPECIFIC.txt --exit-code

# Treat warnings as errors
python -m pset_validator PSET-SPECIFIC.txt --warnings-as-errors --exit-code

MCP服务器使用情况(光标/克劳德桌面)

FastMCP服务器可以与Cursor或Claude Desktop一起使用。添加到MCP配置中:

对于光标:

  1. 首先,安装软件包:

    pip install -e .
    
  2. 然后在游标设置中进行配置→ MCP服务器:

    {
      "mcpServers": {
        "pset-validator": {
          "command": "python",
          "args": ["-m", "pset_validator.server"],
          "env": {}
        }
      }
    }
    
  3. 重新启动游标 在添加MCP服务器配置之后。

注: 确保 python 命令指向您安装包的同一Python环境。您可以通过以下方式进行验证:

python -c "import pset_validator; print('OK')"

对于Claude Desktop: 添加 claude_desktop_config.json:

{
  "mcpServers": {
    "pset-validator": {
      "command": "python",
      "args": ["-m", "pset_validator.server"],
      "env": {}
    }
  }
}

或者独立运行:

python -m pset_validator.server

可用的MCP工具:

  • validate_pset_file(file_path: str) -从磁盘验证PSET文件
  • validate_pset_content(content: str) -验证字符串中的PSET内容

验证规则

关键验证(错误)

  1. 实体名称案例:必须是 IfcSpace,不 IFCSPACE (区分大小写-至关重要!)
  2. 实体格式: Ifc + EntityName (正确案例)
  3. 属性集结构:以制表符分隔的列格式正确
  4. 数据类型:有效的Revit PropertyType 仅限姓名(Label, Text, Boolean, Integer, Real等等)-- 不 IfcLabel / IfcText (Revit会剥离 Ifc 前缀;在PSET文件中使用解析的导出器名称)
  5. 必填字段:PropertySet行必须具有名称、级别(I/T)和实体列表
  6. 文件格式:建筑红线采用正确的制表符分隔格式

附加验证(警告)

  1. 重复属性:属性集中的属性名称相同
  2. 重复的属性集:相同实体的相同属性集名称
  3. 空属性集:未定义属性的属性集
  4. 缺少Revit参数:Revit参数列为空时发出警告
  5. PropertySet之外的属性:在PropertySet声明之前定义的属性

PSET文件示例

# User Defined PropertySet Definition File
PropertySet:	BIP	I	IfcWall
	BSABe			LABEL		BSABe
	BSABwr			LABEL		BSABwr
	TypeID			LABEL

输出示例

有效文件

Validating: PSET-SPECIFIC.txt
Property Sets: 14
Properties: 185

============================================================
[OK] File is valid!

带有错误和警告的文件

Validating: PSET.txt
Property Sets: 6
Properties: 174

============================================================

[ERROR] Errors: 1
  ERROR: Line 2: Entity name 'IFCSPACE' uses wrong case (all uppercase)
    -> Use 'IfcSpace' instead of 'IFCSPACE'

[WARNING] Warnings: 1
  WARNING: Line 5: Property 'TypeID' missing Revit parameter mapping
    -> Add Revit parameter name in third column (optional but recommended)

============================================================

发展

运行测试

# Run all tests
pytest tests/ -v

# Run with coverage
pytest tests/ --cov=src/pset_validator --cov-report=html

# Run specific test file
pytest tests/unit/test_parser.py -v

代码格式化

# Format code
black src/ tests/

# Lint code
ruff check src/ tests/

项目结构

revit-pset-validator/
├── src/
│   └── pset_validator/
│       ├── __init__.py
│       ├── __main__.py          # CLI entry point
│       ├── server.py            # FastMCP server (MCP mode)
│       ├── validator.py         # Core validation logic
│       ├── parser.py            # PSET file parsing (matches PropertyMap.cs)
│       └── models.py            # Pydantic models for validation results
├── tests/
│   ├── resources/               # Test resources
│   │   ├── DefaultUserDefinedParameterSets.txt  # Official Autodesk template
│   │   └── test_sample.pset.txt                 # Test PSET file
│   ├── unit/
│   │   ├── test_parser.py
│   │   ├── test_validator.py
│   │   └── test_models.py
│   └── integration/
│       └── test_cli.py
├── pyproject.toml
└── README.md

解析逻辑

解析器实现了Revit IFC的精确逻辑 PropertyMap.cs (第327-393行):

  1. 行处理:修剪前导空格/制表符,跳过空行和注释
  2. 属性集行:不区分大小写的“PropertySet:”前缀,至少有4个制表符分隔的部分
  3. 地界线:至少2个制表符分隔的部分,仅在PropertySet块内处理
  4. 实体:用逗号、分号或空格分隔
  5. PropertySet之外的属性:静默跳过(无错误)

支持的数据类型

标签、文本、布尔值、整数、实数、面积、体积、正长度、长度、标识符、热透射率、计数、货币、电流、力、频率、照度、逻辑、光通量、归一化比率、平面角、正平面角、正值、功率、压力、比率、热力学温度、体积流量、色温、电性能、电压、分类参考

贡献

欢迎投稿!请随时提交拉取请求。

许可证

MIT许可证-请参阅 许可证 文件以获取详细信息。

参考文献

相关项目

  • revit ifc -官方Autodesk Revit IFC导出器源代码