Hi Everybody,
I'm pretty new to NXopen API and I'm dealing with a problem using an Istance of workPart.FacetedBodies.CreateSTLImportBuilder() in order to import an .stl file in my part.
I haven't find example of this builder on forums and I can't understand how to obtain created FacetedBody, in order to set it's layer and color.
By the following code I can import the .stl file pointed by STLfileDIR, but using getObject I've the error that is not possible to cast the object to an Facet.FacetedBody ( and the same using a DisplayableObject)
Many thanks!
Public Sub ImportSTL()
Dim STLfileDIR As String = "/../"
Dim LayerSet As Integer = 99
Dim mySession As Session = Session.GetSession()
Dim workPart As Part = mySession.Parts.Work
Dim displayPart As Part = mySession.Parts.Display
Dim STLbuilder As Facet.STLImportBuilder
STLbuilder = workPart.FacetedBodies.CreateSTLImportBuilder()
STLbuilder.File = STLfileDIR
STLbuilder.AngularTolerance = Facet.STLImportBuilder.AngularToleranceTypes.Coarse
STLbuilder.FacetBodyType = Facet.STLImportBuilder.FacetBodyTypes.Nx
STLbuilder.STLFileUnits = Facet.STLImportBuilder.STLFileUnitsTypes.Millimeters
Dim nXObject1 As nxopen.NXobject
Dim facetedBody1 As Facet.FacetedBody
nXObject1 = STLbuilder.Commit()
facetedBody1 = STLbuilder.GetObject
STLbuilder.Destroy()
workPart.Layers.MoveDisplayableObjects(LayerSet, facetedBody1)
End Sub
re: get faceted body
Some of the builder objects don't return what you would expect; I don't know if this is an oversight or if it is by design. One work-around to this problem is to get a list of all the faceted bodies in the part before running the import then getting another list after running the import; the new bodies in the "after import" list are the ones that were imported.
I'd suggest contacting GTAC and opening an incident report on this issue. Perhaps they have a better way of getting the newly imported bodies or they can create an enhancement request to improve the process in a future version of NX.