How to Move and Rotate Bodies?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone,
I'm working on a project where I need to find the plane with the largest area and use its normal vector as the Z-axis to establish a User Coordinate System (UCS). My next step is to rotate and move the skewed bodies (i.e., the models that are not aligned) into another coordinate system. However, I haven't been able to find any relevant API or examples that could help me achieve this. Could someone please provide some guidance?
Here's the code I have so far:
/// <summary> /// Aligns all bodies based on the plane with the largest area. /// </summary> /// <param name="doc">The PartDocument containing the model.</param> public static void CorrectTheModel(PartDocument doc){ // Get the plane with the largest area. Plane maxFace = GetMaxAreaFace(doc).Geometry as Plane; ComponentDefinition oCompDef = doc.ComponentDefinition; // Get the normal vector of the plane with the largest area. double[] normals = new double[3]; maxFace.Evaluator.GetNormal(new double[2], ref normals); double[] points = new double[3]; maxFace.Evaluator.GetPointAtParam(new double[2] { 0.5, 0.5 }, ref points); Application ThisApplication = doc.Parent as Application; // Create the Z-axis vector. var VectorZ = ThisApplication.TransientGeometry.CreateVector(normals[0], normals[1], normals[2]); // Create the Y-axis vector. var VectorY = ThisApplication.TransientGeometry.CreateVector(0, 1, 0); // Calculate the X-axis vector. var VectorX = VectorY.CrossProduct(VectorZ); // Create the origin point. Point Origin = ThisApplication.TransientGeometry.CreatePoint(points[0], points[1], points[2]); // Create a transformation matrix for the new coordinate system. Matrix newMatrix = ThisApplication.TransientGeometry.CreateMatrix(); newMatrix.SetCoordinateSystem(Origin, VectorX, VectorY, VectorZ); // Define the new UCS. var oUCSDef = oCompDef.UserCoordinateSystems.CreateDefinition(); oUCSDef.Transformation = newMatrix; // Add the new UCS to the component definition. oCompDef.UserCoordinateSystems.Add(oUCSDef); foreach (SurfaceBody body in doc.ComponentDefinition.SurfaceBodies) { // Here is where I need help: how can I perform a coordinate system to coordinate system trans formation for all the bodies? } }