Is the Feature part of any Feature Group?

Hello all,

is anybody there who can give me a clue where the problem is.
I am trying to find out if given feature(associative line or simple line) in part navigator is part of any Feature Group and if not then I would like to move it to some feature group (it is not part of my question). Problematic function is:

ufs.Modl.IsFeatureASetMember(thexname, isGroup)

The failure says: Invalid object type

My code

Option Strict Off
Option Explicit On
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

Sub Main()

Dim theSession As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
Dim thexname As Tag = Nothing
Dim isGroup As Integer

lw.Open()
For Each temp As Line In workPart.Lines

'get the feature
ufs.Modl.AskObjectFeat(temp.Tag, thexname)

'ask if the line is part of any feature group
ufs.Modl.IsFeatureASetMember(thexname, isGroup)

If Not thexname = Nothing Then
lw.WriteLine("thexname: " & thexname)
lw.WriteLine("isGroup: " & isGroup)
End If
Next
lw.Close()

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

End Function

End Module

thanks for help

Note that geometry such as points and curves can be unassociative, which means that they are not controlled by a feature (AskObjectFeat will return null). Check that "thexname" is null before using it in the "isFeatureASetMember" function.

Such a stupid thing. Thanks
Updated code:

Option Strict Off
Option Explicit On
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports System.Collections.Generic

Module Module1

Sub Main()

Dim theSession As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
Dim thexname As Tag = Nothing
Dim isGroup As Integer
Dim featuresToGroup As New List(Of Tag)

lw.Open()
For Each temp As Line In workPart.Lines

'get the feature
ufs.Modl.AskObjectFeat(temp.Tag, thexname)

'ask if the line is part of any feature group
If Not thexname = Nothing Then
ufs.Modl.IsFeatureASetMember(thexname, isGroup)
If Not isGroup Then
featuresToGroup.Add(thexname)
End If
End If
Next
lw.Close()

Dim subGroupTag1 As Tag
ufs.Modl.CreateSetOfFeature("outputFileDate", featuresToGroup.ToArray, featuresToGroup.Count, 1, subGroupTag1)
End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

End Function

End Module

Meantime found somewhere another solution:

Sub GroupTheLines()

Dim featuresToGroup As New List(Of Tag)
Dim notGrouped As New List(Of Features.Feature)

For Each tempFeat As Features.Feature In workPart.Features
If tempFeat.IsInternal Then
Continue For
End If

If Not TypeOf (tempFeat) Is Features.FeatureGroup Then
Dim groupFound As Boolean = False
For Each child As Features.Feature In tempFeat.GetChildren
If TypeOf (child) Is Features.FeatureGroup Then
groupFound = True
Exit For
End If
Next
If Not groupFound Then
If TypeOf (tempFeat) Is Features.AssociativeLine Then
featuresToGroup.Add(tempFeat.Tag)
End If
End If
End If
Next
Dim subGroupTag1 As Tag
ufs.Modl.CreateSetOfFeature("outputFileDate", featuresToGroup.ToArray, featuresToGroup.Count, 1, subGroupTag1)
End Sub

You probably need this. IsFeatureASetMember Return 1 if the feature is a member of a set. Otherwise, return 0.If the line is not parameterized, then it passes. Sorry for my English - this is Google translation.Program for Python/

import NXOpen
import NXOpen.UF
import NXOpen.Features
import random

theSession = NXOpen.Session.GetSession()
workPart = theSession.Parts.Work
theLw = theSession.ListingWindow
ufs = NXOpen.UF.UFSession.GetUFSession()
theLw.Open()

def main():

for temp in workPart.Lines:

#get the feature
thexname = ufs.Modeling.AskObjectFeat(temp.Tag)
if thexname :
#ask if the line is part of any feature group
isGroup = ufs.Modeling.IsFeatureASetMember(thexname)

theLw.WriteLine(" thexname = "+str(thexname))
theLw.WriteLine(" isGroup = "+str(isGroup))

if __name__ ==

import NXOpen
import NXOpen.UF
import NXOpen.Features
import random

theSession = NXOpen.Session.GetSession()
workPart = theSession.Parts.Work
theLw = theSession.ListingWindow
ufs = NXOpen.UF.UFSession.GetUFSession()
theLw.Open()

def main():

for temp in workPart.Lines:

#get the feature
thexname = ufs.Modeling.AskObjectFeat(temp.Tag)
if thexname :
#ask if the line is part of any feature group
isGroup = ufs.Modeling.IsFeatureASetMember(thexname)

theLw.WriteLine(" thexname = "+str(thexname))
theLw.WriteLine(" isGroup = "+str(isGroup))

if __name__ == '__main__':

If you want to get groups with elements belonging to them

import NXOpen
import NXOpen.UF
import NXOpen.Features

theSession = NXOpen.Session.GetSession()
workPart = theSession.Parts.Work
theLw = theSession.ListingWindow
ufs = NXOpen.UF.UFSession.GetUFSession()

theLw.Open()

def main():

for temp in workPart.Features:

if type(temp) == NXOpen.Features.FeatureGroup :

theLw.WriteLine("Feature Group: " + ufs.Modeling.AskFeatName(temp.Tag))
setFeatureTags, numFeatures = ufs.Modeling.AskAllMembersOfSet(temp.Tag)

for i in range(numFeatures):
theLw.WriteLine(" " + ufs.Modeling.AskFeatName(setFeatureTags[i]))

if __name__ == '__main__':
main()