Message 1 of 5
Internal error with CreateFixedReferenceSweptGeometry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I have problem with CreateFixedReferenceSweptGeometry on specific path curve. I can make normal sweep - but I need fixed reference to prevent any rotation of profile during sweep. As I try CreateFixedReferenceSweptGeometry I got internal error, that I cannot debug.
Here is my code:
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
internal class AnyNameCommand : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiApp = commandData.Application;
UIDocument uiDoc = uiApp.ActiveUIDocument;
Document doc = uiDoc.Document;
XYZ LocationOfProfile = new XYZ();
XYZ DirectionOfProfile = XYZ.BasisZ;
List<double[]> currentElementPoints = new List<double[]>() {
new double[3] { -5008.xxx-xxxxxxxx, -302.09227382119667, -1703.1366619788882 },
new double[3] { -5003.0693458393216, -301.50354724377394,-1701.6964321025907 },
new double[3] { -4970.4699811181054, -297.80591807700694, -1692.575069298653 },
new double[3] { -4937.8706163968891, -294.10828891210258, -1683.3231420115799 },
new double[3] { -4905.2712516761385, -290.41065974533558, -1673.9406502413376 },
new double[3] { -4872.6718869549222, -286.71303057856858, -1664.4275939879253 },
new double[3] { -4856.3722045924515, -284.86421601101756, -1659.6221041800509 },
new double[3] { -4840.072522233706, -283.01540140993893, -1654.7839732513767 },
new double[3] { -4807.xxx-xxxxxxxx, -279.31777224503458, -1645.0097880316589 },
new double[3] { -4774.8737927912734, -275.62014307826757, -1635.1050383287711 },
new double[3] { -4742.2744280705228, -271.92251391150057, -1625.0697241427479 },
new double[3] { -4709.6750633493066, -268.22488474473357, -1614.9038454735546 },
new double[3] { -4695.5594823596248, -266.623804973539, -1610.4614954046099}};
CurveLoop sweepPath = new CurveLoop();
IList<XYZ> rpa = new List<XYZ>();
foreach (double[] point in currentElementPoints)
{
XYZ revitPoint = new XYZ(point[0], point[1], point[2]);
rpa.Add(revitPoint);
}
HermiteSpline hermiteCurve = HermiteSpline.Create(rpa, false);
sweepPath.Append(hermiteCurve);
Transform tangentsToSweepPath = sweepPath.ElementAt(0).ComputeDerivatives(0, false);
Transform rotateProfileToPreserveDirectionZ, rotateProfileToAlignmentPlan, getProfileAtOrigin;
XYZ AlignmentVectorProjectionOnXY = new XYZ(tangentsToSweepPath.BasisX.X, tangentsToSweepPath.BasisX.Y, 0);
double preserveRotationAngle = (Math.PI / 2 - XYZ.BasisX.AngleTo(AlignmentVectorProjectionOnXY));
rotateProfileToPreserveDirectionZ = Transform.CreateRotation(XYZ.BasisZ, preserveRotationAngle);
XYZ axis = DirectionOfProfile.CrossProduct(tangentsToSweepPath.BasisX.Normalize());
double angle = Math.Acos(tangentsToSweepPath.BasisX.Normalize().DotProduct(DirectionOfProfile));
rotateProfileToAlignmentPlan = Transform.CreateRotation(axis, angle);
getProfileAtOrigin = Transform.CreateTranslation(tangentsToSweepPath.Origin.Subtract(LocationOfProfile));
IList<CurveLoop> profile = new List<CurveLoop>();
CurveLoop curveLoopExternal = new CurveLoop();
Line line1 = Line.CreateBound(new XYZ(-50, 0, 0), new XYZ(50, 0, 0));
Line line2 = Line.CreateBound(new XYZ(50, 0, 0), new XYZ(0, 75, 0));
Line line3 = Line.CreateBound(new XYZ(0, 75, 0), new XYZ(-50, 0, 0));
curveLoopExternal.Append(line1);
curveLoopExternal.Append(line2);
curveLoopExternal.Append(line3);
profile.Add(curveLoopExternal);
foreach (CurveLoop part in profile)
{
part.Transform(rotateProfileToPreserveDirectionZ);
}
foreach (CurveLoop part in profile)
{
part.Transform(rotateProfileToAlignmentPlan);
part.Transform(getProfileAtOrigin);
}
Solid solid = GeometryCreationUtilities.CreateFixedReferenceSweptGeometry(sweepPath, 0, sweepPath.ElementAt(0).GetEndParameter(0), profile, XYZ.BasisZ);
// Solid solid = GeometryCreationUtilities.CreateSweptGeometry(sweepPath, 0, sweepPath.ElementAt(0).GetEndParameter(0), profile);
return Autodesk.Revit.UI.Result.Succeeded;
}
}