From a Journal found on this forum I was trying to select all extrude features in a part and put them in featuregroup.
I get the journal to create the group but the extrudes are not added to the group.
What am I doing wrong?
Thanks for your help!!
Option Strict Off
Imports System
Imports System.Collections
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Features
Imports NXOpen.Utilities
Module Module1
Dim theSession As Session = Session.GetSession()
Dim lw As ListingWindow = theSession.ListingWindow
Dim ufs As UFSession = UFSession.GetUFSession()
Sub Main()
Dim toBeGrouped() As Features.Feature = getFeatures
Dim featTags(toBeGrouped.Length - 1) As Tag
For ii As Integer = 0 To toBeGrouped.Length - 1
featTags(ii) = toBeGrouped(ii).Tag
Next
Dim fGroup As Tag = Tag.Null
ufs.Modl.CreateSetOfFeature("TEST", featTags, toBeGrouped.Length, 1, fGroup)
End Sub
Function getFeatures
Dim gotFeature As ArrayList = New ArrayList
Dim feats As Features.FeatureCollection = theSession.Parts.Display.Features
For Each feat As Feature In feats
Try
if feat.FeatureType = "EXTRUDE" then
gotFeature.add(feat)
End if
Catch ex As Exception
End Try
Next
'do something with exception
return gotfeature.ToArray(GetType(Features.Feature))
End Function
Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return CType(Session.LibraryUnloadOption.Immediately, Integer)
End Function
End Module
re: feature group
I tried the code and it seemed to work for me. I created a new part with various features, when I ran the code a feature group named "TEST" was created and all the extrude features were added to it.
I'm not sure it will make a difference, but what version of NX are you using? I tested on NX 9.0.3.4
journal only works in displayed part mode, not in work part mode
Thanks for your reply!
The problem seems to be that the journal works correct in a displayed part mode but when the same part is a workpart in an assembly, the feature group is created but the features (extrudes) aren't added to the group.
Do you have any idea what part of the code is causing this behavior? and can it be solved by altering the code?
Many thanks in advance!
re: feature set
The following line of code looks at all the features in the display part:
Dim feats As Features.FeatureCollection = theSession.Parts.Display.Features
The .CreateSetOfFeature method will create a feature set in the work part. The journal code posted previously collects features from the display part and attempts to create a feature set in the work part. The code will only work correctly when the display part is the same as the work part.
To change this behavior, collect the features from the work part:
Dim feats As Features.FeatureCollection = theSession.Parts.Work.Features
Thanks
That is very usefull information, thanks!
Now it works fine.