Cancel
Showing results for 
Search instead for 
Did you mean: 

Get bodies of a feature

Valued Contributor
Valued Contributor

I'm trying to find all of the bodies that belong to a feature.  In this instance a split body.

I've tried using:

For Each feat As Features.Feature In theSession.Parts.Work.Features
            If feat.FeatureType = "SPLIT BODY" Then
                
                Dim feat_ent() As NXObject = feat.getentities

            End If
Next

But this results in feat_ent being empty.

 

Is there a way of achieving this?

 

Thanks,

 

Mark

6 REPLIES

Re: Get bodies of a feature

Valued Contributor
Valued Contributor

To partially answer my own question Smiley Happy

I've managed to get bodies out by casting to a bodyfeature

 

For Each feat As Features.Feature In theSession.Parts.Work.Features
            
 Dim split_feat As Features.BodyFeature
           

          If feat.FeatureType = "SPLIT BODY" Then
                split_feat = CType(feat, Features.BodyFeature)
               Dim feat_ent() As NXObject = split_feat.Getbodies
               msgbox(feat_ent.length)
            End If
           

 Next

This seems a little clunky.  If I didn't have a case where it was just a split body and I needed all features that have bodies, is there a simple way to do this without having to add cases for every type of feature that I'd be interested in?

 

Re: Get bodies of a feature

Honored Contributor
Honored Contributor

One possible solution would be to iterate through the feature collection, using TryCast to attempt to cast each to a BodyFeature. If it doesn't cast to a BodyFeature, then there are no bodies to return.

Re: Get bodies of a feature

Phenom
Phenom
In Java there is an 'instanceof' operator to test if an object is an instance of some parent type. Is there anything like that in VB?
Graham Inchley Snr R&D Engineer (Systems Development), Sandvik Coromant
Lenovo ThinkPad W540, Win7, 16GB. Developing in: Java | C | KF
Production: NX8.5.3.3 MP11 64bit Testing: NX9.0.2.5

Re: Get bodies of a feature

Valued Contributor
Valued Contributor

Cowski,

 

I've not tried it yet but the TryCast looks like a good workaround.

 

I do find it odd that the 'Features.Feature' type has the 'ShowBody'/'HideBody' subs but not a 'GetBodies' sub.

 

Thanks,

Re: Get bodies of a feature

Honored Contributor
Honored Contributor

"In Java there is an 'instanceof' operator to test if an object is an instance of some parent type. Is there anything like that in VB?"

 

Yes, the TypeOf operator.

Re: Get bodies of a feature

Legend
Legend

You can use the uf function UFModl.IsBodyFeature(..) to find out if the feature creates a body or not.