Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Trying to translate Sweep Profile to Sweep Start Path in Family document location wrong.

FrankHolidaytoiling
Advocate

Trying to translate Sweep Profile to Sweep Start Path in Family document location wrong.

FrankHolidaytoiling
Advocate
Advocate

As you can see from the below code, I can get the sweep into the 1.) XY plane and 2.) rotate the sweep to the correct angle however any attempts to 3.) translate the sweep profile back to the original location of the sweep start path fails. I have gotten it closer by subtracting abitrary distances from the start path and applying a transform to all my arrays curves. 

Do I need to do a better job of rotating the Sweep Profile into the XY plane in the first instance or is my translation just not working because I am not working in the correct plane? Does xvec or yvec have anything todo with this? Why am i doing all this work when I have the Sweep Profile from the project document in the first place? 

 

 

private static CurveArrArray CreateTransformedProfile(Document doc, CurveArrArray curveArrArrayProfile, XYZ sweepPlaneOrigin, XYZ sweepPlaneNormal, XYZ sweepPathStart)
{
using (Transaction t = new Transaction(doc, "Create Transformed Profile"))
{
t.Start();

//This part is successful, sweep profile is rotated in XY plane and then rotated within XY plane so up orientation is correct
Transform transform1 = GetTransformToZ(sweepPlaneNormal, sweepPlaneOrigin);
Transform transform2 = Transform.CreateRotation(sweepPlaneNormal, 1.5 * Math.PI);
Transform transform = transform1.Multiply(transform2);

CurveArrArray transformedProfile = new CurveArrArray();

foreach (CurveArray curveArray in curveArrArrayProfile)
{
CurveArray transformedCurveArray = new CurveArray();
foreach (Curve curve in curveArray)
{
transformedCurveArray.Append(curve.CreateTransformed(transform));
}
transformedProfile.Append(transformedCurveArray);
}


//Attempt to move the Sweep Profile to the path start point Fails here!
//Draw model lines for visualization of problem.
ConvertMIPFamilySolids.LinePathToCentre = Line.CreateBound(sweepPlaneOrigin, sweepPlaneNormal);
XYZ vector = new XYZ(1, 1, 0);
XYZ pathEnd = sweepPlaneNormal.Add(vector);
ConvertMIPFamilySolids.LinePathToEnd = Line.CreateBound(sweepPlaneNormal, pathEnd);


t.Commit();

return transformedProfile;
}
}

private static Transform GetTransformToZ(XYZ normal, XYZ origin)
{
Transform transform;

double angle = XYZ.BasisZ.AngleTo(normal);

if (IsZero(angle))
{
transform = Transform.Identity;
}
else
{
XYZ axis = IsEqual(angle, Math.PI) ? XYZ.BasisX : normal.CrossProduct(XYZ.BasisZ);
transform = Transform.CreateRotationAtPoint(axis, angle, origin);
}
return transform;
}
private static bool IsZero(double value)
{
return Math.Abs(value) < 1e-6;
}
private static bool IsEqual(double value1, double value2)
{
return IsZero(value1 - value2);
}

0 Likes
Reply
154 Views
0 Replies
Replies (0)