Trim surfaces

Hello,
I have some bodies(faces),sew and revolved surfaces mixed in the part navigator. There is also a ref revolved surface which will be used as tool in trimming op.
Some of them are intersecting the tool. What I want to do is running a loop which asks each bodies in the part and each faces belong to the bodies respectively and try to be trimmed by the tool. If the loop meets the nonintersecting faces then it will jump simply with "on error resume next"
But there is a problem with the code. It finds some tag belongs to faces but the tags are invalid error that I am getting although I used ufs.modl.askfeatbody(..... , ......)
Where am I wrong?

Can you post the code you have so far?

Tuesday
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim bodies = theSession.Parts.Work.Bodies
Dim lw As ListingWindow = theSession.ListingWindow
Dim datumPlane1 As DatumPlane = CType(workPart.Datums.FindObject("DATUM_CSYS(0) YZ plane"), DatumPlane)
Dim cutter As Tag = Nothing
Dim target As Tag = Nothing
Dim theUFSession As UFSession = UFSession.GetUFSession
Dim cuttingFaceFeat As Features.Feature
Dim fcs_ As Face = Nothing
For Each bod As Body In bodies
Dim faces = bod.GetFaces()
For Each fcs As Face In faces 'find all faces in each bodies
Dim facefeat As Features.Feature
Dim facefeattag() As Tag = Nothing
theUFSession.Modl.AskFaceFeats(fcs.Tag, facefeattag) 'get the feature tag that belongs to the selected face and write into facefeattag
facefeat = Utilities.NXObjectManager.Get(facefeattag(0)) ' get the feature from this tag
Dim theDistance As Double = DistanceFinder(datumPlane1.Tag, fcs.Tag) ' what is the distance between floor and selected face
If theDistance = 0 Then 'if the distance is 0 then the cutter is that face.
cutter = facefeat.Tag 'the cutter is obtained from the feature tag
lw.WriteLine("Cutter:" & cutter.ToString)
fcs_ = fcs 'The cutting face, a global variable assignment for after use
cuttingFaceFeat = facefeat
Exit For
End If
Next fcs
Next bod

For Each bod0 As Body In bodies
Dim faces0 = bod0.GetFaces()
For Each fcs0 As Face In faces0
Dim facefeat0 As Features.Feature 'looking for the target feature which will be obtained from one of its face
Dim facefeattag0() As Tag = Nothing ' the array so as to store the tags
theUFSession.Modl.AskFaceFeats(fcs0.Tag, facefeattag0)
facefeat0 = Utilities.NXObjectManager.Get(facefeattag0(0))
''''''''''''''''''''''''
Dim facefromfeaturetag() As Tag = Nothing
theUFSession.Modl.AskFeatFaces(facefeat0.Tag, facefromfeaturetag)
'''''''''''''''''''''''''''
Dim theDistance As Double = DistanceFinder(fcs_.Tag, facefromfeaturetag(0))
'Dim theDistance As Double = DistanceFinder(fcs0.Tag, fcs_.Tag)
target = facefeat0.Tag
If theDistance = 0 And target <> cutter Then
MsgBox(theDistance & " " & cutter & " " & target)
lw.WriteLine("target feature name: " & facefeat0.GetFeatureName)
lw.WriteLine("target feature type: " & facefeat0.GetType.ToString)
lw.WriteLine("cutterfeature name: " & cuttingFaceFeat.GetFeatureName)
lw.WriteLine("cutter feature type: " & cuttingFaceFeat.GetType.ToString)
lw.WriteLine("targettag: " & target)
lw.WriteLine("cuttertag: " & cutter)
lw.WriteLine("")
trimmer(cutter, target)
trimmer(target, cutter)
' If ObjectFromTag(cutter).GetType.ToString = "NXOpen.Features.Revolve" And facefeat0.GetType.ToString = "NXOpen.Features.Sew" Then
'End If
Exit For
End If
Exit For
Next fcs0
Exit For
Next bod0