I'm trying to insert fasteners into holes using NX Open. As far as the base point is concerned, it is fine. But I'm struggling with orienting fasteners correctly to insert them into randomly oriented holes. I understand that one way is to calculate the orientation matrix from two vectors - fastener axis vector and hole axis vector. But I discovered that I quite forgot all those maths topics. Is there any ready C# (or maybe VB) algorithm that does exactly that?
Best option is to find the seating faces on the hole as well as the fastener, get their face normals and orient your fastener normal opposite to the hole seating face normal.
I guess you would want to create assembly constraints between the hole and fastener. I would suggest you record a journal and modify the code to suit your requirement.
"and orient your fastener normal opposite to the hole seating face normal."
That's exactly the question - how is the orientation matrix computed? The journal won't give you the answer. This is the maths problem.
I can create assembly constraints, but it's optional in the application that I'm making. Also, that is the extra operation that has cairries overhead. I believe it's quite costly in terms of time to use assembly contraints - and then delete them - merely to orient components. In this case orientation matrix must be used.
Or correct me if I am wrong. I'm not 100% getting NX Open orientation matrix at the moment. Is there more info on it somewhere in the docs?
I have some python code that does something similar. I made another post on how to set up numpy with NX Open. Feel free to pm me if there is anything unclear.
check here for the methods/attributes that will give you your fastener/hole vectors. It's likely that NX will return the vectors in a list or a tuple
#use numpy to turn your vectors into matrices
dot_product=numpy.dot(fastener_array,hole_array) #assuming that fastener_array and hole_array are unit vectors of length 1 if dot_product==1.0: #insert whatever you want your code to do below
alternatively, you could use the cross product
cross_product=numpy.cross(fastener_array,hole_array) cross_norm=la.norm(cross_product) #if normalized cross product =0, then vectors are parallel if cross_norm==0.0:
Thanks everyone for suggestions! I was really busy, but I'll soon check everything out and get back to you with the result.
I finally got round to having another go at this task and finally solved it. I obtained matrix from the cylindrical hole face using the theUFSession.Csys.AskMatrixOfObject. It was of the wrong orientation for my purpose - components were upside down - so I had to find a way to rotate it in a correct position. The solution came from the example called "rotate selected component about its own x axis" in the Solution center. So this problem is solved for me.