I use Python.
I need to get a geometry information of the Face as well as I get it through the user interface (Menu -> Information -> Object or Ctrl+I).
Actually I need just the following parameter:
Normal - Absolute I = -0.420212290 J = -0.907389507 K = -0.008118760
I tried to record journal file:
selectedObjects1 = [NXOpen.NXObject.Null] * 1 selectedObjects1 = face self.theSession.Information.DisplayObjectsDetails(
But this code displays a ListingWindow. Of course I can parse it, but I think there is a better way.
How can I get this geometry parameter?
You can get some face information from the .AskFaceData function. If the face is planar, this will also give you the normal direction. If the face is not planar, the normal direction will change depending on where you measure it. Using the .AskFaceProps function, you can get the normal direction for a given U V parameter. Given a point in 3D space, you can get the U V parameter on the face with .AskFaceParm.
Some useful functions to get surface information:
Thank you! But I don't understand how to use it?
I found some information in official documentation here
Signature: AskFaceData(face) Parameters: face (Tag) – Face obj_id
Ok. I wrote:
... k = NXOpen.UF.Modeling.AskFaceData(face.Tag) # face is an instance of NXOpen.Face
And I catch an error:
descriptor 'AskFaceData' requires a 'NXOpen.UF.Modeling' object but received a 'int'
I got it! I need to get session first:
theUfSession = NXOpen.UF.UFSession.GetUFSession() jj = theUfSession.Modeling.AskFaceData(face.Tag)
There's a bit more to it than that. You'll want to consult the API help docs to get information on the required arguments to the AskFaceData function. The function returns several pieces of information; to do this, you must declare variables for it to operate on. The function will change the values of the variables that you pass in; after the function runs, the variables will hold the data corresponding to the face tag that you passed in.
The code below (in VB) shows how to call the function.
Dim faceType As Integer Dim facePt(2) As Double Dim faceDir(2) As Double Dim bbox(5) As Double Dim faceRadius As Double Dim faceRadData As Double Dim normDirection As Integer theUfSession.Modl.AskFaceData(someface.tag, faceType, facePt, faceDir, bbox, faceRadius, faceRadData, normDirection)
A faceType value of 22 indicates that the surface is planar. If it is planar, the faceDir array will hold the normal direction.
here try this and let me know if it works. language is python
import NXOpen import NXOpen.BlockStyler import NXOpen.Features import NXOpen.UF import NXOpen.GeometricAnalysis import NXOpen.Facet import random import math class geom_info: # Constructor for NX Styler class # --------------------------------------------------
---------------------------- def __init__(self): # class members self.theSession = None self.theUI = None self.theLw= None self.theDialogName = "" self.theDialog = None #Get the UF session self.theUfSession = None try: self.theSession = NXOpen.Session.GetSession() self.theUI = NXOpen.UI.GetUI() self.theLw = self.theSession.ListingWindow #create print window self.theUfSession = NXOpen.UF.UFSession.GetUFSession() except Exception as ex: # ---- Enter your exception handling code here ----- raise ex def get_info(self): # declare global variables global workPart, face_list self.theLw.Open() self.theLw.WriteLine("Hello NX World!") self.theLw.WriteLine("") workPart = self.theSession.Parts.Work theUfSession = NXOpen.UF.UFSession.GetUFSession() #get all the solid bodies for body in workPart.Bodies: #get a list of all the faces face_list=body.GetFaces() #cycle through each face in the solid body for i in range(len(face_list)): self.theLw.WriteLine(str(face_list[i])) #create a temp object temp_face=face_list[i] self.theLw.WriteLine("") #get the tag for each face self.theLw.WriteLine("The face tag is "+str(temp_face.Tag)) self.theLw.WriteLine("") #A tuple consisting of (type,point,dir,box,radius,rad_data,norm_dir) jj = theUfSession.Modeling.AskFaceData(temp_face.Tag) self.theLw.WriteLine("Geometry info is "+str(jj)) self.theLw.WriteLine("Face type is NX surface type code 16 = cylinder 17 = cone 18 = sphere 19 = revolved (toroidal) 20 = extruded 22 = bounded plane 23 = fillet (blend) 43 = b-surface 65 = offset surface 66 = foreign surface "+str(jj)) self.theLw.WriteLine("") self.theLw.WriteLine("Direction information is "+str(jj)) self.theLw.WriteLine("") self.theLw.WriteLine("Face Boundary is "+str(jj)) self.theLw.WriteLine("") self.theLw.WriteLine("Radius is "+str(jj)) def main(): try: #create instance of class myclass = geom_info() #call the method myclass.get_info() except Exception as ex: # ---- Enter your exception handling code here ----- NXOpen.UI.GetUI().NXMessageBox.Show("Block Styler", NXOpen.NXMessageBox.DialogType.Error, str(ex)) if __name__ == "__main__": main()
Sorry, I missed that you were using Python; use @AlexLee's example instead...
Thanks for posting the example. I'd like to use Python more when we move to NX10, your example will come in handy.
When you write out the information, it looks like a few references are off... I think they should be:
self.theLw.WriteLine("Direction information is "+str(jj)) self.theLw.WriteLine("") self.theLw.WriteLine("Face Boundary is "+str(jj)) self.theLw.WriteLine("") self.theLw.WriteLine("Radius is "+str(jj))
You were right! This is Python. And AskFaceData returns me a tuple of values which are described in documentation. Now I completely understand how it works :-)
Thank you all!