已知DxfName,获取类型和本地名称?
(1)问题-------------------------已知"LINE",得到GetType(Line)
已知"LWPOLYLINE",得到GetType(Polyline)
(2)问题-------------------------
已知"LINE",得到"直线"
已知"LWPOLYLINE",得到"多段线"
反向的操作很简单:
RXClass.GetClass(typeof(Line)).DxfName
但必须是高版本
DxfName => type没有找到直接的方法,如果一定要实现
可以先反射DatabaseServices下所有Entity的子类,自己建一个字典 需要DxfName => type,如能反射所有子类,问题就好解决了。
具体从哪入手? 本帖最后由 雪山飞狐_lzh 于 2011-1-28 20:31 编辑
DxfName有重复项,:)
就没有直接用字典了,比如"Insert"
public static void Test2()
{
var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
Type t = typeof(Entity);
var dict =
Assembly.GetAssembly(t)
.GetTypes()
.Where(type => type.IsSubclassOf(t))
.Where(type => RXClass.GetClass(type) != null)
.GroupBy(type => RXClass.GetClass(type).DxfName);
foreach (var s in dict)
ed.WriteMessage("\n{0}:{1}", s.Key,s.ElementAt(0).Name);
}
很好,反射成功。结果说明,DxfName和Entity Type不存在固定的对应关系。要让lisp和.NET有一致的类型限定,还得找别的方法。 <CommandMethod("TTT")> Public Sub TTT()
Dim doc = Application.DocumentManager.MdiActiveDocument
Dim ed = doc.Editor
Dim et As Type = GetType(Entity)
Dim typs() As Type = Assembly.GetAssembly(et).GetTypes
Dim var = From typ As Type In typs Where typ.IsSubclassOf(et)
Dim dict As New Dictionary(Of String, Type)
For Each typ As Type In var
Dim cls As RXClass = RXClass.GetClass(typ)
If cls IsNot Nothing Then
Dim dxf As String = cls.DxfName
If dxf <> Nothing Then
If Not dict.ContainsKey(dxf) Then
dict.Add(dxf, typ)
Else
ed.WriteMessage(vbLf & "Same DXF: {0}({1})", dxf, typ.Name)
End If
Else
ed.WriteMessage(vbLf & "DXF Nothing: {0}", typ.Name)
End If
Else
ed.WriteMessage(vbLf & "RXClass Nothing: {0}", typ.Name)
End If
Next
For Each s In dict
ed.WriteMessage(vbLf & "{0}:{1}", s.Key, s.Value.Name)
Next
End Sub 如果是Lisp数据的话,可以考虑直接用
SystemObjects.ClassDictionary获取,这个字典是个string,RXClass的键值对
Key对应的是Axr的类名,如"AcDbLine" SystemObjects.ClassDictionary可以代替反射,但是解决不了最初的问题。
页:
[1]