Alternative to ucsDef.SetByThreePoints in assembly

Alternative to ucsDef.SetByThreePoints in assembly

NSBowser
Advocate Advocate
490 Views
1 Reply
Message 1 of 2

Alternative to ucsDef.SetByThreePoints in assembly

NSBowser
Advocate
Advocate

I've been working to create a function which will allow the user to pick three items (a point, a plane, and a (planar) Face) which will define the location and orientation of a UCS in a specific type of assembly. The creation of this UCS is all but impossible manually since the features are oriented arbitrarily in space, and geometry may not be used in an Assembly for placing a UCS.

 

Using the selections indicated above, for the end goal of using ucsDef.SetByThreePoints, I was able to create Unit Vectors and finally Work Points representing the origin, xDirection and yDirection.

 

I only then realized that SetByThreePoints DOES NOT function at the assembly level. WONDERFUL!!!

 

I am now lost at how I can go about creating a UCS with the information I have available. I realize I must have to use a Matrix to define the Translation of the UCS, before applying it to the UCS via ucsDef.Transformation = matrix, but I am at a loss as how to take those three vectors and convert them into a usable translation matrix. I just don't see how i can take my finshed resultants and determine what the individual rotations were that got to that result.

 

If anyone could provide any insight in moving from the one to the other I would be very grateful!


Best of Luck

---------------------------------------------------------------------------------------------------------------------------------
If you find this reply helpful or insightful, please use the 'Accept as Solution' or 'Kudos' button below.
0 Likes
Accepted solutions (1)
491 Views
1 Reply
Reply (1)
Message 2 of 2

NSBowser
Advocate
Advocate
Accepted solution

As is usually the case, as soon as I take the time to describe the problem in detail, I discover the point I've been overlooking.

Revisiting the API Help Documentation I found a sample that showed using unit vectors to create the coordinate system of the matrix directly.

 

Here is the code I ended up with finally, maybe this will help someone else looking to do this as well.

 

UnitVector zUnitVector = facePlane.Normal;
UnitVector xUnitVector = vertPlane.Plane.Normal;
UnitVector yUnitVector = xUnitVector.CrossProduct(zUnitVector);

Matrix matrix = transGeo.CreateMatrix();
matrix.SetCoordinateSystem(pickPt, xUnitVector.AsVector(), yUnitVector.AsVector(), zUnitVector.AsVector());

UserCoordinateSystemDefinition ucsDef = compDef.UserCoordinateSystems.CreateDefinition();
ucsDef.Transformation = matrix;

Best of Luck

---------------------------------------------------------------------------------------------------------------------------------
If you find this reply helpful or insightful, please use the 'Accept as Solution' or 'Kudos' button below.
0 Likes