...gonna give it a try...will let you know how it works in my application.
Not having any good luck.
I used your code to try and collect the faces from the hole shown in the picture. Currently my code expects the user to pick a cylindrical face that represents the hole to be processed. Internally I look for every other hole in the part with the same radius and put in a list of NXObjects. I then parse the list and do some attribute defnition and then color the faces. The list of NXObjects contains faces. When I debugged, theScCollector.GetObjects().Length -1 returned 2 in the ReDim statement and 1 in the For statement? I ended up with a Null tag in theBossFaces array which caused the displayModification1.Apply to bomb. The only face in theBossFaces array was the first face selected in the passed to array. It didn't pick up the chamfer.
Function SetFaceColor(color As Integer, holeSelected As List(Of NXObject)) Dim theScCollector As ScCollector = workPart.ScCollectors.CreateCollector() Dim theSelectionIntentRules(0) As SelectionIntentRule Dim displayModification1 As DisplayModification displayModification1 = theSession.DisplayManager.NewDisplayModification() displayModification1.ApplyToAllFaces = False displayModification1.ApplyToOwningParts = False displayModification1.NewColor = color For i = 0 To holeSelected.Count - 1 Dim theFaceBossPocketFacesRule As FaceBossPocketFacesRule = workPart.ScRuleFactory.CreateRuleFaceBossPocket(holeSelected(i)) theSelectionIntentRules(0) = theFaceBossPocketFacesRule theScCollector.ReplaceRules(theSelectionIntentRules, False) Dim theBossFaces As DisplayableObject() = Nothing Dim k As Integer = 0 ReDim theBossFaces(theScCollector.GetObjects().Length - 1) For k = 0 To theScCollector.GetObjects().Length - 1 theBossFaces(i) = theScCollector.GetObjects(i) Next k displayModification1.Apply(theBossFaces) ' displayModification1.Dispose() Next Return 0 End Function
I made a small working example :-)
For your way of using you have to create many rules:
Here you are Setting always the same rule with new faces " theSelectionIntentRules(0) = theFaceBossPocketFacesRule"
You have to set every face in a new rule.
Every rule has got one(!) seed face and returns some faces. You have to use one rule for every seed face you found with the same diameter. Then redim "theSelectionIntentRules()" and add every rule to that array.
and maybe some more errorhandling and cleaning up the objects (obejct = nothing) to prevent some weird behaviour :-)
I just wanted to show that "finding the pocket faces" is integrated in NX already. I found one Problem with my method:
If you have a counterbore hole you should select the top most (biggest diameter) or the collected faces does not cover the whole pocket:
|_ _| |__|
If you select the outer diameter, the whole pocket is selected, if you select the inner diameter, the outer Diameter is ignored...
I tried your small working sample and it did select all the faces when I picked the cylindrical face of the hole. I like the simplicity of it and wish I could get it to work in my application. Just not having any luck at it.
I was trying to embed the collector inside the loop to allow it to be reinitialized for each selected face. Each time through the loop I would expect it to create a new rule due to scope. However, I'm not getting through the loop for the first iteration. I can't see what is different in my coding versus yours that is causing mine to fail. The GetObjects method does not seem to "get"?
I was starting with something simple and would add that the "problem" you discovered presents another "problem" for me. The attributes I'm writing are to convert a hole into a threaded hole for FBM purposes. These attributes need to be on the hole surface that is to be threaded in order for FBM to function correctly. If I have to select the largest diameter of the counterbores for coloring, I'm going to have to code my way to the largest diameter so I can keep the attributes where they need to be. If that is the case, I might as well stick with my initial approach, even though this collector is a neat API.
Still trying to sort this out for future reference!
Finally figured it out. TYPO on my part. I was already using "i" as a counter, so had switched to "k" in your coding, but didn't get all of them switched. Not it works as expected, and, I see the issue you noticed with counterbores in my larger sample.
Here's the corrected code:
Function SetFaceColor(color As Integer, holeSelected As List(Of NXObject)) Dim theDisplayModification As NXOpen.DisplayModification = theSession.DisplayManager.NewDisplayModification() theDisplayModification.ApplyToAllFaces = True theDisplayModification.ApplyToOwningParts = False theDisplayModification.NewColor = color For i = 0 To holeSelected.Count - 1 Dim theScCollector As ScCollector = workPart.ScCollectors.CreateCollector() Dim theFaceBossPocketFacesRule As FaceBossPocketFacesRule = workPart.ScRuleFactory.CreateRuleFaceBossPocket(holeSelected(i)) Dim theSelectionIntentRules(0) As SelectionIntentRule theSelectionIntentRules(0) = theFaceBossPocketFacesRule theScCollector.ReplaceRules(theSelectionIntentRules, False) Dim theBossFaces As DisplayableObject() = Nothing Dim k As Integer = 0 ReDim theBossFaces(theScCollector.GetObjects().Length - 1) For k = 0 To theScCollector.GetObjects().Length - 1 theBossFaces(k) = theScCollector.GetObjects(k) Next k theDisplayModification.Apply(theBossFaces) Next theDisplayModification.Dispose() Return 0 End Function
Kind of disappointed that it doesn't catch the counterbores, Steve? Amy? any thoughts?
I would also add it runs faster than my original code....