Still zipping around in Pattaya with my brother Marcus, and still blogging a bit now and then as well ...
Here is a suggestion for a workaround to specify the start and end tangents of a flex duct or pipe that evolved through a recent exchange of comments with Zhu XiaoMeng:
Question: In the Revit application UI, I can create a FlexDuct properly with the start tangent of the Hermite curve in a reasonable direction. But when I create a flex duct in the API, the start tangent is always horizontal. How can I do the same thing in API as in the UI?
The initial code is as follows:
FlexDuct flexDuct = doc.Create.NewFlexDuct( points, flexducttype );
Answer: One thing to note regarding this is that it does not seem to be related to the Hermite spline issue that we recently discussed.
Here is a suggestion for a possible workaround:
Response: I did as what you say, but I get confused with the second step. I placed a fitting with two side connectors in the right place, and then placed the flex duct in the right position, but they did not join. So the tangent did not change. So the point is: how can I get them joined?
Here is my current code:
Family fittingFamily = lstElem.Where( e => e.Name == "M_xyz" ) .Select( e => e as Family ) .FirstOrDefault(); FamilySymbol fittingType = fittingFamily .Symbols .ToList() .First(); const double fitLen = 1.5; var vectDown = ( samplePoints - samplePoints ) .Normalize(); var fittPos = ptA - vectDown * fitLen; // vectAb is the vector pointing from // ptA(samplePoints[First]) to // ptB(samplePoints[Last]) // remove the z values (as the // flexDuct first tangent do) var vectAbHoriz = new XYZ( vectAb.X, vectAb.Y, 0 ); FamilyInstance fittingInstance = _doc.Create.NewFamilyInstance( fittPos, fittingType, StructuralType.NonStructural ); Line axis2 = _app.Create.NewLine( fittPos, vectDown.CrossProduct( XYZ.BasisZ ), false ); // rotate the fitting to the desired angle bool success = _doc.Rotate( fittingInstance, axis2, -vectDown.AngleTo( vectAbHoriz ) ); SortedList valuePairs = new SortedList(); valuePairs["xyz 01"] = fitLen; ChangeParametersValue( fittingInstance, valuePairs ); FlexDuct flexDuct2 = CreateDuct( samplePoints, flexDuctType );
Answer: You probably have to explicitly connect them with each other as demonstrated in the AutoRoute and AvoidObstruction SDK samples.
Response: Thank you, it's solved!
Here is my way in case some one else encounters the same problem:
Find the right connector of the fitting as well as the right connector of flexDuct, and call the connector ConnectTo method to join them.
Before deleting the temporary fitting, call the document Regenerate method, otherwise the tangent will not change!
Very many thanks to Zhu XiaoMeng for this discussion and sharing the successful result!