Cancel
Showing results for 
Search instead for 
Did you mean: 

Painting FacetedBody by Facet

Experimenter
Experimenter

Hello,

 

I have imported an STL into NX and now I have a FacetedBody.  In addition to the STL file, I have another data file that tells me what color each triangle of my STL should be.  I would like to be able to cycle through the facets of the faceted body and apply NXOpen.Facet.PaintFacetBodyBuilder.  The problem is, I can't seem to get to cycle through the facets.  I know I can cycle through using UF, but it seems the NXOpen.Facet.PaintFacetBodyBuilder uses IFacets which as far as a n00b like me can tell, are not compatible and do not have a conversion to UFFacets.  Can anyone lend some assistance?

6 REPLIES

Re: Painting FacetedBody by Facet

Legend
Legend

Hi @SSPollock

 

I am even curiours about your question. Try doing this.. set your selection filter to to facet body check if you able to select anything workspace. if you can select, then you need to check your code.

if you can't then instead of facet body try passing solid body into the builder.

 

::Smiley SurprisedPTIMUS_PRIME

::Smiley SurprisedPTIMUS_PRIME

Re: Painting FacetedBody by Facet

Siemens Phenom Siemens Phenom
Siemens Phenom

Where do you see a reference to "IFacet" things?

 

And how are you going to change the color of facets?

 

I haven't looked into this thoroughly, but the root of the problem might be the (sad) fact that NX has several different kinds of facetted bodies. There are old-style "NX" facet bodies, newish "JT" facet bodies, and now brand new "convergent" facet bodies. Some operations are supported on one type, but not on others. The workaround is convert to a type that's supported by whatever operation you want to perform. To do this, you can use NXOpen.Facet.FacetedBodyCollection.Convert.

山田
yamada

Re: Painting FacetedBody by Facet

Siemens Experimenter Siemens Experimenter
Siemens Experimenter

Hi SSPollack, Is your problem resolved? I can help you if not...

Re: Painting FacetedBody by Facet

Experimenter
Experimenter

It remains unsolved.  I worked with GTAC on this issue and found that there was a bug in the NX code that prevented this from working.  It should be fixed now in the latest release (12.04 I think...), but I haven't updated yet to test.

Re: Painting FacetedBody by Facet

Siemens Experimenter Siemens Experimenter
Siemens Experimenter
'This program displays unit normals of each facet on a body with name MYFACETBODY
'
' Program demonstrates these calls: GetFirstFacetOnBody, AskUnitNormal, GetNextFacet and Destroy
Option Infer On
Public Class DisplayUnitNormalsOnEachFacet
 
   Public Shared Sub Main()
 
      ' This just finds an object with the name "MYFACETBODY".
      Dim body1 As NXOpen.Body = Snap.NX.NXObject.FindByName("MYFACETBODY")
 
      ' Create points
      LoopOverAllFacets(body1)
 
   End Sub
 
 
   ' Creates a point at each vertex of a facetted body
   Public Shared Sub LoopOverAllFacets(body1 As NXOpen.Body)
      Dim facet1 As NXOpen.ConvergentFacet = body1.GetFirstFacetOnBody()
 
      Dim nullConvergetFacet As System.DBNull

        ' we want to delete each facet as soon as we are done with displaying the normal
	  Dim facetToDelete As NXOpen.ConvergentFacet
 
	  Do 
	    'Get Centroid of the facet
		Dim centroid As NXOpen.Point3d
		centroid.X = 0.0
		centroid.Y = 0.0
		centroid.Z = 0.0
		
	    centroid.X = centroid.X + facet1.Vertex0.X
	    centroid.Y = centroid.Y + facet1.Vertex0.Y
	    centroid.Z = centroid.Z + facet1.Vertex0.Z
	                                   
	    centroid.X = centroid.X + facet1.Vertex1.X
	    centroid.Y = centroid.Y + facet1.Vertex1.Y
	    centroid.Z = centroid.Z + facet1.Vertex1.Z
	                                   
	    centroid.X = centroid.X + facet1.Vertex2.X
	    centroid.Y = centroid.Y + facet1.Vertex2.Y
	    centroid.Z = centroid.Z + facet1.Vertex2.Z
	    
	    centroid.X =  centroid.X/3
	    centroid.Y =  centroid.Y/3
	    centroid.Z =  centroid.Z/3
		
            Dim unitNormal As NXOpen.Vector3d = facet1.GetUnitNormal()
		Dim loc(2) As Double
		loc(0) = centroid.X
		loc(1) = centroid.Y
		loc(2) = centroid.Z
		
		'Get the normal
		Dim norm(2) As Double
		norm(0) = unitNormal.X
		norm(1) = unitNormal.Y
		norm(2) = unitNormal.Z
		
		'Display the normals
		Dim ufs = NXOpen.UF.UFSession.GetUFSession
		ufs.Disp.Conehead(0, loc, norm, 0)
		 
		facetToDelete = facet1
        facet1 = body1.GetNextFacet( facet1 ) 
		
            'Destroy the facet of last iteration
            facetToDelete.Destroy()
		
	 Loop Until facet1 Is nullConvergetFacet
	 
   End Sub
 End Class

Re: Painting FacetedBody by Facet

Siemens Experimenter Siemens Experimenter
Siemens Experimenter

The above vb script helps cycling over facets of a convergent body. You can easily extend this code to paint each facet with certain code using Paint Facet Body feature