NXOpen.BlockStyler.FaceCollector

I've developed a block styler using the FaceCollector for the selection of a face. Now, I want to cast the face that is selected from this operation. How do I cast this face into a face object?

The FaceCollector.GetSelectedObjects() method will return the selected faces as an array of tagged objects.

If you are using "Option Strict Off" at the beginning of your code, the compiler can cast certain objects for you. In this case, the following code should work:

For Each tempFace As Face In theFaceCollector.GetSelectedObjects

'do something with tempFace

Next

This works because we know all the objects in the collector are "face" objects, the compiler should be able to successfully cast the object to type "face". If we tried to use a different object type in the "For Each" declaration, we'd have problems.

If you are using "Option Strict On", or just prefer to cast the objects yourself, you could use code such as:

For Each tempObj As TaggedObject In theFaceCollector.GetSelectedObjects

Dim tempFace As Face = CType(tempObj, Face)
'do something with tempFace

Next

Again, this should work since we know all the objects are of type "face". We could place the conversion in a Try block if we didn't know the type of "tempObj" beforehand or if we just want to catch any unexpected rogue errors.