Can't assign hermite spline to a LocationCurve.Curve

Can't assign hermite spline to a LocationCurve.Curve

alexander.tomkeyev
Participant Participant
479 Views
2 Replies
Message 1 of 3

Can't assign hermite spline to a LocationCurve.Curve

alexander.tomkeyev
Participant
Participant

I'm trying to modify the geometry of a FlexDuct and move the endpoints. It does work with line based families by simply assigning a new Line instance to the LocationCurve.Curve.

However, for flex ducts the same action throws an exception

Here is the sample code to reproduce the issue in Revit 2020:

            using var tx = new Transaction(doc, "Change Flex");
            tx.Start();
            var flx = selection.OfType<FlexDuct>().FirstOrDefault();

            var flexCurve = flx.Location as LocationCurve;
            var flexSpline = flexCurve.Curve as HermiteSpline;

            var clone = flexSpline.Clone();
            flexCurve.Curve = clone;

            tx.Commit();

The exception is thrown on the last line before committing the transaction. It won't even work if assigning the same hermite spline back to the .Curve property.

Exception's message is empty and there is no inner exception. Exception's function ID points to this file:

"d:\\ship\\2020_px64\\source\\api\\revitapi\\objects\\location\\apilocationcurve.cpp"

 Again, this works with line based families such as Conduit. Is there a workaround for Flex ?

Thanks!

@Anonymous @Revitalizer 

0 Likes
Accepted solutions (1)
480 Views
2 Replies
Replies (2)
Message 2 of 3

RPTHOMAS108
Mentor
Mentor
Accepted solution

If FlexDuct is always a HermiteSpline (which it seems to be) can you extract the points and set them via FlexDuct.Points along with StartTangent/EndTangent properties? These properties are all ReadWrite.

 

Would assume the first and last points along with the tangents need to be the same to maintain the connection.

 

HermiteSplines are quite simplistic compared to other types of spline i.e. they don't have knots and weights etc.

0 Likes
Message 3 of 3

alexander.tomkeyev
Participant
Participant

Thank you, that works!

It's worth mentioning that setting HermiteSpline.ControlPoints will throw an exception if the spline is used as a location curve for FlexDuct, but works fine otherwise.

 

Appreciate your help, @RPTHOMAS108 

0 Likes