Internal error with CreateFixedReferenceSweptGeometry

Internal error with CreateFixedReferenceSweptGeometry

mateuszac
Participant Participant
506 Views
4 Replies
Message 1 of 5

Internal error with CreateFixedReferenceSweptGeometry

mateuszac
Participant
Participant

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;
        }
    }
0 Likes
507 Views
4 Replies
Replies (4)
Message 2 of 5

jeremy_tammik
Alumni
Alumni

Sorry to hear about this. Is your code completely self-contained? Can it be executed in any RVT file whatsoever? Can you please provide exact detailed step-by-step instructions to reproduce the internal exception? If it requires a specific model or anything that is not already created by your code snippet, please provide a complete, minimal, reproducible case for the development team to analyse and debug locally:

  

https://thebuildingcoder.typepad.com/blog/about-the-author.html#1b

  

Thank you!

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 5

mateuszac
Participant
Participant

Hi Jeremy,

 

Yes, as I am not creating any Revit element in document, but just pure geometry swept solid it can be run in any RVT file as external command. The only thing is to replace XXX.XXXXX in the coordinates which forum auto-changed  (mistakenly taken by phone numer) by any numbers 🙂 - it should not have any impact on result. 

 

If the developer uncomment the line with normal sweep and comment out the line with CreateFixedReferenceSweptGeometry - the script will work and solid will be created, otherwise there will appear internal error exception.

0 Likes
Message 4 of 5

mhannonQ65N2
Collaborator
Collaborator

I don't have any experience with CreateFixedReferenceSweptGeometry but I suspect that your last argument, the fixed direction, is incorrect, though I'm not sure if that's the cause of the exception. Based on my reading of the documentation for CreateFixedReferenceSweptGeometry, a value of BasisZ makes sense for your profile before it is transformed. However, since you transform the profile, perhaps you should also transform the fixed direction the same way (based on my understanding of your geometric calculations, I think that would result in tangentsToSweepPath.BasisX).

 

Also, if someone wants to test this in an empty model, I'd recommend that they transform the currentElementPoints so it is roughly centered on the origin. Though it doesn't matter unless they actually create the geometry in the model (e.g. via a direct shape).

0 Likes
Message 5 of 5

mateuszac
Participant
Participant

I tried both - using Basis.Z vector as last argument and using vector that represents vertical axis in plane after setting profile perpendicular to path at starting point. Also the code I pased works for some paths (for other it doesn't - returning internal error).  As I need to get that solid, I developed workaround using Loft method - but still cannot debug the CreateFixedReferenceSweptGeometry code.

0 Likes