- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
How to Move and Rotate Bodies?
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? } }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I don't understand the purpose of this feature. Can you post some screenshot what do you expect?
But in general. There are limited possibilities of manipulating surface bodies in part. Much easier can be to create new assembly and parts from bodies and place them to this assembly. Or you can create new part where you can create copy of original bodies with given transformation. Here is the sample in VBA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thank you for your response! The NonParametricBaseFeatures function creates independent surfaces after running, but what I'm aiming for is more similar to the native Inventor functionality: moving solid bodies.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
This is represented in API as MoveFeature. There is no problem to translate part in space, but it is hard to define its rotation.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Yes, I have discovered no other means to wrap a function for the automatic matrix transformation of the entity.
Thanks for reply