In a block dialog I'm trying to get the user to select a Hole (feature type HolePackage) and from that I want to find the associated SymbolicThread for the Hole if there is one.
Initially I just thought I'd be able to do HolePackage.getChildFeatures(), but that returns nothing
By hacking my code to interrogate the features in the part I found there is a feature which reports its type as SIMPLE_HOLE that is an internal feature (I guess internal to the HolePackage). It is this feature that has the SymbolicThread as a child.
Is there any way I can get the SIMPLE_HOLE from the HolePackage feature so I can then get the SymbolicThread? I can't seem to find any 'getInternalFeatures()' method...
Dell 7530 Precision, Win10, 32GB. Developing in: Java | C | KF
Production: [NX12.0.2 MP1]
Solved! Go to Solution.
Are you looking to get the actual arc objects that represent the simplified thread for a threaded hole? Or something else, like the thread data?
Nothing that complicated, I simply want to find the SymbolicThread Feature.
I found the following convoluted process works, but it's super clunky and I haven't yet tested if it only finds the SymbolicThreads associated to the Hole feature:
for each body associated to the hole for each face of the body if face is cylindrical for each feature associated to the face if feature is instance of BodyFeature for each child feature of BodyFeature if child feature is SymbolidThread collect child feature in a list end end end end end end end
I was hoping to do something more like:
for each child feature of hole if child feature is SymbolidThread collect child feature in a list end end
Or using Java Streams, a one liner:
List<SymbolicThread> threads = hole.getChildFeatures().filter(child -> child.featureType().equals("SYMBOLIC_THREAD")).collect(Collectors.toList());
The pseudo code I posted above with many 'for each' and 'if' statements did work, but found additional threads on the body if there were any. I've revised it now and got it to only find the thread for the hole feature I'm interested in.
From my original post you can see that I can find an 'internal' feature that reports it's type as SIMPLE_HOLE. This has the thread as a child. So it would be nice to be able to get the internal features of the main hole (type = HolePackage). Anyone know if its possible to get internal features? Obviously there is no simple 'Feature.getInternalFeatures()'.
I don't know of a direct way to get what you want, but I know that internal features will have the same timestamp as the 'external' feature. Iterating through the features, checking the timestamp, .IsInternal property, and feature type should get what you want.
The code in the link below loops through the feature tree and builds a dictionary for later reference. I have not done much work with internal features since this code was written, perhaps there is a better way to do it now.
Using the Timestamp, excellent idea!
I've now refactored my code to use this logic. For performance, rather than cycle through all features in the part, I decided to just cycle through the bodies that the Hole returns from .getBodies() and cycle through all features each of the bodies returns from .getFeatures().
Still would be nice to have a more robust way to find these things, but this solution is much better than mine.
Thanks @cowski1 .