C# NxOpen - 查找活动工作部分中的所有功能组
C# NxOpen - Find all Feature Groups in active Work Part
嗨,在 CAD 程序 SiemensNX 中,我有一个活动的工作部件。在这个 WorkPart 中,我有一些特征(例如曲线)。对于此功能,我创建了一个功能组,例如 windows 资源管理器中包含文档的文件夹。
现在我尝试通过编程接口 NxOpen 查找活动 WorkPart 中的所有 FeatureGroup。我在 C# 中执行此操作,但 VBA 中的任何帮助对我来说也应该没问题。
我试试这个:
foreach(FeatureGroup FGroupX in workpart.Features)
{
do something with current FGroupX ...
}
“workpart.features”为我提供了活动 WorkPart 中所有特征的集合。但是对于这个集合中不是来自“Featuregroup”类型的每个特征,for 循环都会崩溃。
是否有其他合适的解决方案来查找活动 WorkPart 中的所有特征组?
使用额外的 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
}
}
嗨,在 CAD 程序 SiemensNX 中,我有一个活动的工作部件。在这个 WorkPart 中,我有一些特征(例如曲线)。对于此功能,我创建了一个功能组,例如 windows 资源管理器中包含文档的文件夹。 现在我尝试通过编程接口 NxOpen 查找活动 WorkPart 中的所有 FeatureGroup。我在 C# 中执行此操作,但 VBA 中的任何帮助对我来说也应该没问题。
我试试这个:
foreach(FeatureGroup FGroupX in workpart.Features)
{
do something with current FGroupX ...
}
“workpart.features”为我提供了活动 WorkPart 中所有特征的集合。但是对于这个集合中不是来自“Featuregroup”类型的每个特征,for 循环都会崩溃。
是否有其他合适的解决方案来查找活动 WorkPart 中的所有特征组?
使用额外的 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
}
}