196 lines
6.8 KiB
Python
196 lines
6.8 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
"""
|
||
测试Aspose.CAD 23.6版本
|
||
验证降级版本是否能解决API问题
|
||
"""
|
||
|
||
import os
|
||
import sys
|
||
from pathlib import Path
|
||
|
||
def print_separator(title=""):
|
||
"""打印分隔线"""
|
||
print("=" * 60)
|
||
if title:
|
||
print(f" {title} ")
|
||
print("=" * 60)
|
||
|
||
def test_version_23_6():
|
||
"""测试Aspose.CAD 23.6版本"""
|
||
print_separator("测试Aspose.CAD 23.6版本")
|
||
|
||
try:
|
||
import aspose.cad as cad
|
||
from aspose.cad.fileformats.cad import CadImage
|
||
|
||
print(f"Aspose.CAD版本: {cad.VERSION}")
|
||
|
||
# 查找DWG文件
|
||
dwg_files = list(Path('.').glob('*.dwg'))
|
||
if not dwg_files:
|
||
print("未找到DWG文件")
|
||
return False
|
||
|
||
test_file = str(dwg_files[0])
|
||
print(f"使用文件: {test_file}")
|
||
|
||
# 测试1:基本加载
|
||
print("\n测试1:基本加载")
|
||
try:
|
||
with cad.Image.load(test_file) as image:
|
||
print(f"成功加载,类型: {type(image).__name__}")
|
||
print(f"图像尺寸: {image.width} x {image.height}")
|
||
except Exception as e:
|
||
print(f"基本加载失败: {e}")
|
||
return False
|
||
|
||
# 测试2:使用CadImage.load
|
||
print("\n测试2:使用CadImage.load")
|
||
try:
|
||
cad_image = CadImage.load(test_file)
|
||
print(f"成功使用CadImage.load,类型: {type(cad_image).__name__}")
|
||
|
||
# 检查是否有CAD特定属性
|
||
attrs = [attr for attr in dir(cad_image) if not attr.startswith('_')]
|
||
print(f"可用属性数量: {len(attrs)}")
|
||
|
||
# 查找可能包含实体的属性
|
||
entity_attrs = [attr for attr in attrs if 'entit' in attr.lower() or 'block' in attr.lower() or 'layer' in attr.lower()]
|
||
print(f"可能的实体属性: {entity_attrs}")
|
||
|
||
# 尝试访问这些属性
|
||
for attr in entity_attrs:
|
||
try:
|
||
value = getattr(cad_image, attr)
|
||
print(f" {attr}: {type(value).__name__}")
|
||
if hasattr(value, '__len__'):
|
||
print(f" 长度: {len(value)}")
|
||
|
||
# 如果长度大于0,尝试访问前几个元素
|
||
if len(value) > 0:
|
||
for i in range(min(3, len(value))):
|
||
item = value[i]
|
||
print(f" [{i}]: {type(item).__name__}")
|
||
|
||
# 如果是CadLine,尝试提取信息
|
||
if type(item).__name__ == 'CadLine':
|
||
print(f" 找到CadLine!")
|
||
if hasattr(item, 'first_point') and hasattr(item, 'second_point'):
|
||
print(f" 起点: {item.first_point}")
|
||
print(f" 终点: {item.second_point}")
|
||
|
||
except Exception as e:
|
||
print(f" {attr}: 访问失败 - {e}")
|
||
|
||
return True
|
||
|
||
except Exception as e:
|
||
print(f"使用CadImage.load失败: {e}")
|
||
return False
|
||
|
||
except Exception as e:
|
||
print(f"测试失败: {e}")
|
||
import traceback
|
||
traceback.print_exc()
|
||
return False
|
||
|
||
def test_alternative_approaches():
|
||
"""测试其他方法"""
|
||
print_separator("测试其他方法")
|
||
|
||
try:
|
||
import aspose.cad as cad
|
||
from aspose.cad.fileformats.cad import CadImage
|
||
|
||
# 查找DWG文件
|
||
dwg_files = list(Path('.').glob('*.dwg'))
|
||
if not dwg_files:
|
||
print("未找到DWG文件")
|
||
return False
|
||
|
||
test_file = str(dwg_files[0])
|
||
|
||
# 方法1:尝试直接创建CadImage实例
|
||
print("\n方法1:直接创建CadImage实例")
|
||
try:
|
||
cad_image = CadImage()
|
||
print(f"成功创建CadImage实例: {type(cad_image).__name__}")
|
||
|
||
# 检查方法
|
||
methods = [attr for attr in dir(cad_image) if not attr.startswith('_') and callable(getattr(cad_image, attr))]
|
||
print(f"可用方法: {methods}")
|
||
|
||
# 尝试使用load方法
|
||
if 'load' in methods:
|
||
try:
|
||
loaded = cad_image.load(test_file)
|
||
print(f"使用实例方法load成功: {type(loaded).__name__}")
|
||
except Exception as e:
|
||
print(f"使用实例方法load失败: {e}")
|
||
|
||
except Exception as e:
|
||
print(f"创建CadImage实例失败: {e}")
|
||
|
||
# 方法2:尝试使用其他导入方式
|
||
print("\n方法2:尝试其他导入方式")
|
||
try:
|
||
from aspose.cad.fileformats.cad.cadobjects import CadLine
|
||
print("成功导入CadLine")
|
||
|
||
# 尝试创建CadLine实例
|
||
line = CadLine()
|
||
print(f"成功创建CadLine实例: {type(line).__name__}")
|
||
|
||
# 检查CadLine的属性
|
||
line_attrs = [attr for attr in dir(line) if not attr.startswith('_')]
|
||
print(f"CadLine属性数量: {len(line_attrs)}")
|
||
|
||
# 查找坐标相关属性
|
||
coord_attrs = [attr for attr in line_attrs if 'point' in attr.lower() or 'coord' in attr.lower()]
|
||
print(f"坐标相关属性: {coord_attrs}")
|
||
|
||
except Exception as e:
|
||
print(f"其他导入方式失败: {e}")
|
||
|
||
return True
|
||
|
||
except Exception as e:
|
||
print(f"测试其他方法失败: {e}")
|
||
return False
|
||
|
||
def main():
|
||
"""主函数"""
|
||
print_separator("Aspose.CAD 23.6版本测试")
|
||
print("验证降级版本是否能解决API问题")
|
||
print()
|
||
|
||
# 测试23.6版本
|
||
success = test_version_23_6()
|
||
|
||
if success:
|
||
print("\n" + "=" * 60)
|
||
print(" 23.6版本测试结果 ")
|
||
print("=" * 60)
|
||
print("✓ 23.6版本可以正常加载DWG文件")
|
||
print("✓ 需要进一步测试是否能访问CAD特定功能")
|
||
|
||
# 测试其他方法
|
||
test_alternative_approaches()
|
||
else:
|
||
print("\n" + "=" * 60)
|
||
print(" 23.6版本测试结果 ")
|
||
print("=" * 60)
|
||
print("✗ 23.6版本仍然存在API问题")
|
||
print("建议尝试其他版本或替代方案")
|
||
|
||
if __name__ == "__main__":
|
||
try:
|
||
main()
|
||
except KeyboardInterrupt:
|
||
print("\n\n用户中断了程序执行")
|
||
except Exception as e:
|
||
print(f"\n\n程序执行出错: {e}")
|
||
import traceback
|
||
traceback.print_exc()
|