- 创建problem目录存储问题分析和解决方案 - 添加Aspose.CAD Python问题详细报告 - 提供Java版本测试方案和完整代码 - 创建Java版本安装运行指南 - 更新README文档包含Java版本推荐 - 添加颜色元素提取相关脚本 - 提供完整的Maven项目配置
184 lines
6.9 KiB
Python
184 lines
6.9 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
"""
|
||
测试新DWG文件的脚本
|
||
专门测试测试图纸文件.dwg
|
||
"""
|
||
|
||
import os
|
||
import sys
|
||
from pathlib import Path
|
||
|
||
def print_separator(title=""):
|
||
"""打印分隔线"""
|
||
print("=" * 60)
|
||
if title:
|
||
print(f" {title} ")
|
||
print("=" * 60)
|
||
|
||
def test_new_dwg():
|
||
"""测试新的DWG文件"""
|
||
print_separator("测试新的DWG文件")
|
||
|
||
try:
|
||
import aspose.cad as cad
|
||
from aspose.cad import Color
|
||
|
||
# 查找测试图纸文件
|
||
test_file = "测试图纸文件.dwg"
|
||
if not os.path.exists(test_file):
|
||
print(f"文件不存在: {test_file}")
|
||
return
|
||
|
||
print(f"测试文件: {test_file}")
|
||
file_size = os.path.getsize(test_file)
|
||
print(f"文件大小: {file_size:,} 字节 ({file_size/1024/1024:.2f} MB)")
|
||
|
||
# 加载DWG文件
|
||
print("正在加载DWG文件...")
|
||
with cad.Image.load(test_file) as image:
|
||
print(f"成功加载DWG文件")
|
||
print(f"图像类型: {type(image).__name__}")
|
||
print(f"图像尺寸: {image.width} x {image.height}")
|
||
|
||
# 检查文件格式
|
||
try:
|
||
file_format = cad.Image.get_file_format(test_file)
|
||
print(f"文件格式: {file_format}")
|
||
except Exception as e:
|
||
print(f"获取文件格式失败: {e}")
|
||
|
||
# 检查是否可以加载
|
||
try:
|
||
can_load = cad.Image.can_load(test_file)
|
||
print(f"可以加载: {can_load}")
|
||
except Exception as e:
|
||
print(f"检查是否可以加载失败: {e}")
|
||
|
||
# 尝试转换为PNG来验证文件内容
|
||
print("\n尝试转换为PNG验证文件内容...")
|
||
try:
|
||
from aspose.cad.imageoptions import CadRasterizationOptions, PngOptions
|
||
|
||
# 设置光栅化选项
|
||
raster_options = CadRasterizationOptions()
|
||
raster_options.page_width = 800
|
||
raster_options.page_height = 600
|
||
raster_options.background_color = Color.white
|
||
|
||
# 设置PNG选项
|
||
png_options = PngOptions()
|
||
png_options.vector_rasterization_options = raster_options
|
||
|
||
# 保存为PNG
|
||
output_path = "测试图纸文件_output.png"
|
||
image.save(output_path, png_options)
|
||
|
||
if os.path.exists(output_path):
|
||
file_size = os.path.getsize(output_path)
|
||
print(f"✓ 转换成功,输出文件大小: {file_size} 字节")
|
||
|
||
# 检查是否有水印
|
||
if file_size > 1000:
|
||
print(f"✓ 文件大小正常,可能没有水印限制")
|
||
else:
|
||
print(f"⚠ 文件大小较小,可能有许可证限制")
|
||
|
||
# 清理测试文件
|
||
try:
|
||
os.remove(output_path)
|
||
print(f"✓ 已清理测试文件")
|
||
except:
|
||
pass
|
||
else:
|
||
print(f"✗ 转换失败,未生成输出文件")
|
||
|
||
except Exception as e:
|
||
print(f"✗ 转换失败: {e}")
|
||
if "evaluation" in str(e).lower() or "trial" in str(e).lower():
|
||
print(f" → 这可能是评估版限制")
|
||
elif "license" in str(e).lower():
|
||
print(f" → 这可能是许可证问题")
|
||
|
||
# 尝试使用CadImage.load
|
||
print("\n尝试使用CadImage.load...")
|
||
try:
|
||
from aspose.cad.fileformats.cad import CadImage
|
||
cad_image = CadImage.load(test_file)
|
||
print(f"✓ 成功使用CadImage.load,类型: {type(cad_image).__name__}")
|
||
|
||
# 检查所有属性
|
||
attrs = [attr for attr in dir(cad_image) if not attr.startswith('_')]
|
||
print(f"可用属性数量: {len(attrs)}")
|
||
|
||
# 显示所有属性
|
||
print("所有属性:")
|
||
for attr in attrs:
|
||
try:
|
||
value = getattr(cad_image, attr)
|
||
if callable(value):
|
||
print(f" 方法: {attr}()")
|
||
else:
|
||
print(f" 属性: {attr} = {value}")
|
||
except Exception as e:
|
||
print(f" 属性: {attr} (访问失败: {e})")
|
||
|
||
except Exception as e:
|
||
print(f"✗ 使用CadImage.load失败: {e}")
|
||
|
||
# 尝试使用其他方法
|
||
print("\n尝试其他方法...")
|
||
try:
|
||
# 检查Image对象的所有方法
|
||
image_methods = [attr for attr in dir(image) if not attr.startswith('_') and callable(getattr(image, attr))]
|
||
print(f"Image对象方法: {image_methods}")
|
||
|
||
# 尝试使用get_strings方法
|
||
if 'get_strings' in image_methods:
|
||
try:
|
||
strings = image.get_strings()
|
||
print(f"get_strings(): {type(strings).__name__}")
|
||
if hasattr(strings, '__len__'):
|
||
print(f" 字符串数量: {len(strings)}")
|
||
for i, s in enumerate(strings[:10]):
|
||
print(f" [{i}]: {s}")
|
||
except Exception as e:
|
||
print(f"get_strings()失败: {e}")
|
||
|
||
except Exception as e:
|
||
print(f"尝试其他方法失败: {e}")
|
||
|
||
except Exception as e:
|
||
print(f"测试失败: {e}")
|
||
import traceback
|
||
traceback.print_exc()
|
||
|
||
def main():
|
||
"""主函数"""
|
||
print_separator("测试新DWG文件")
|
||
print("专门测试测试图纸文件.dwg")
|
||
print()
|
||
|
||
test_new_dwg()
|
||
|
||
print_separator("测试总结")
|
||
print("基于测试结果,可以得出以下结论:")
|
||
print("1. DWG文件可以正常加载")
|
||
print("2. 基本功能正常")
|
||
print("3. 但无法访问CAD特定功能(entities, blocks, layers)")
|
||
print("4. 这是Aspose.CAD for Python的API设计问题")
|
||
print("\n建议:")
|
||
print("1. 使用替代方案(如ezdxf)")
|
||
print("2. 联系Aspose技术支持")
|
||
print("3. 考虑文件格式转换")
|
||
|
||
if __name__ == "__main__":
|
||
try:
|
||
main()
|
||
except KeyboardInterrupt:
|
||
print("\n\n用户中断了程序执行")
|
||
except Exception as e:
|
||
print(f"\n\n程序执行出错: {e}")
|
||
import traceback
|
||
traceback.print_exc()
|