在SP3D中,选中一个工厂对象,如何使用代码获取其类得接口及属性呢?
- 通过MetadataManager获取工厂对象全部接口
具体思路是通过ClientServiceProvider.WorkingSet获取当前的连接信息,通过连接信息获取其MetadataManager,通过MetadataManager获取所选对象类的具体信息ClassInformation ,通过ClassInformation 获取接口信息,代码如下所示:
SP3DConnection oConnection =ClientServiceProvider.WorkingSet.ActiveConnection;
SelectSet oSet = ClientServiceProvider.SelectSet;
BusinessObject oBo = oSet.SelectedObjects[0];
MetadataManager oMetadateMgr = oConnection.MetadataMgr;
ClassInformation oCI = oMetadateMgr.
GetClassInfo(oBo.UserClassInfo.Name, oBo.UserClassInfo.Namespace);
ReadOnlyDictionary oInterfaceColl = oCI.Interfaces;
string interfaceName = “”;
foreach (InterfaceInformation oIf in oInterfaceColl.Values)
{
try
{
interfaceName = “\r\n” + interfaceName + oIf.Name ;
}
catch { }
}
return interfaceName;
使用3DBox运行结果如下所示:
2、获取工厂对象得全部接口及接口下的属性
在上面的代码中增加ReadOnlyDictionary properties = oIf.Properties;获取的某个接口的所有属性,再通过遍历获取属性名称,具体代码如下:
SP3DConnection oConnection = ClientServiceProvider.WorkingSet.ActiveConnection;
SelectSet oSet = ClientServiceProvider.SelectSet;
BusinessObject oBo = oSet.SelectedObjects[0];
MetadataManager oMetadateMgr = oConnection.MetadataMgr;
ClassInformation oCI = oMetadateMgr.GetClassInfo(oBo.UserClassInfo.Name, oBo.UserClassInfo.Namespace);
ReadOnlyDictionary oInterfaceColl = oCI.Interfaces;
string interfaceName = “”;
foreach (InterfaceInformation oIf in oInterfaceColl.Values)
{
try
{
interfaceName = “\r\n” + interfaceName + oIf.Name ;
ReadOnlyDictionary properties = oIf.Properties;
foreach (PropertyInformation opp in properties.Values)
{
try
{
interfaceName = “\r\n” + interfaceName + opp.Name;
}
catch { }
}
}
catch { }
}
return interfaceName;
使用3DBox运行结果如下所示:
微信公众号 数智化工