我正在尝试使用IronPython通过COM Interop DLL在某些CAD软件MicroStation中进行一些自动化。当我尝试从对象获取“自定义类型”时,它会抛出ValueErrors。我的快速代码如下:
import sys, clr, System, os
sys.path.append("C:\\Program Files (x86)\\Bentley\\MicroStation V8i (SELECTseries)\\MicroStation\\assemblies")
clr.AddReferenceToFile("bentley.interop.microstationdgn.dll")
from Bentley.Interop.MicroStationDGN import Application, Point2d, Point3d, TextElement
t = System.Type.GetTypeFromProgID("MicroStationDGN.Application")
ms = System.Activator.CreateInstance(t)
elem = ms.ActiveDesignFile.GetElementByID64(509)
coord = elem.Origin
ValueError:指定的记录无法映射到托管值类。
elem.Origin应该给我一个Point3d对象......
但是,如果我这样做:
>>> test = Point3d()
>>> Point3d.X.SetValue(test, 1)
>>> Point3d.Y.SetValue(test, 1)
>>> elem.Origin = test
>>> elem.Rewrite()
我能够'设置'元素的Origin值。 (我可以在CAD软件中验证元素的原点已经移动了。)
我确信我错过了一些简单的COM / IronPython事情,但是我已经查看了文档,没有任何内容跳出来。
任何帮助将不胜感激!
答案 0 :(得分:0)
啊!我读到了这个:
http://support.microsoft.com/kb/811445
我必须先注册这些类型!所以我执行了这个:
C:\Windows\Microsoft.NET\Framework\v4.0.30319>regasm "C:\Program Files (x86)\Ben
tley\MicroStation V8i (SELECTseries)\MicroStation\assemblies\bentley.interop.mic
rostationdgn.dll"
Microsoft (R) .NET Framework Assembly Registration Utility 4.0.30319.1
Copyright (C) Microsoft Corporation 1998-2004. All rights reserved.
Types registered successfully
C:\Windows\Microsoft.NET\Framework\v4.0.30319>
现在:
>>> elem.Origin
<Bentley.Interop.MicroStationDGN.Point3d object at 0x000000000000002E [Bentley.Interop.MicroStationDGN.Point3d]>
>>> elem.Origin.X
1.0
真棒。