问题描述
嘿,在CAD程序SiemensNX中,我有一个活动的工作部件。在此WorkPart中,我具有一些功能(例如曲线)。对于此功能,我创建了一个FeatureGroup,例如在Windows资源管理器中包含文档的文件夹。 现在,我尝试通过编程接口查找NxOpen活动WorkPart中的所有FeatureGroup。我在C#中执行此操作,但对VBA的任何帮助对我来说也都可以。
我尝试这个:
foreach(FeatureGroup FGroupX in workpart.Features)
{
do something with current FGroupX ...
}
“ workpart.features”为我提供了活动WorkPart中所有功能的集合。但是此集合的每个功能(不是来自“ Featuregroup”类型)的for循环崩溃。
是否存在另一种合适的解决方案来查找活动WorkPart中的所有FeatureGroup?
解决方法
通过附加的功能类型if-check解决了该问题:
foreach(Feature curFeature in workpart.Features)
{
Type type = curFeature.getType();
if(type == typeof(FeatureGroup))
{
FeatureGroup fg = (FeatureGroup)curFeature //explicite conversion to FeatureGroup-Type
//do something with fg
}
}