Creating a rebar U-shape definition by RebarShapeDefinitionBySegments
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to create a simple u-shape definition of a rebar using the
RebarShapeDefinitionBySegments class, however I cannot get it to work even though I set it up exactly like Revit does when the same shape is created in the UI and then inspected. The shape has complete = true and creates it, however it cannot be opened for editing afterwards, which indicates something is wrong with either the default value of the parameters or the constraints. I am wondering what exactly I am doing wrong.
To make a u-shape, I define 3 segments with the following constraints:
0: Length, FixedDir (1,0)
1: Length, FixedDir (0,1), 180degreeDefaultBend
2: Length, FixedDir (-1,0)
(To use 3 length parameters named a, b and c must exist but otherwise code should be able to be used as is )
private static RebarShapeDefinition CreateShapeDefinitionTest_U_shape(Document document)
{
var definition = new RebarShapeDefinitionBySegments(document, 3);
definition.AddParameter(document.GetParameterId("a"), 200d.FromMillimeters());
definition.AddParameter(document.GetParameterId("b"), 200d.FromMillimeters());
definition.AddParameter(document.GetParameterId("c"), 200d.FromMillimeters());
var segment0 = definition.GetSegment(0);
List<RebarShapeConstraint> segment0constraints = new List<RebarShapeConstraint>()
{
new RebarShapeConstraintSegmentLength(
document.GetParameterId("a"),
RebarShapeSegmentEndReferenceType.Exterior,
RebarShapeSegmentEndReferenceType.Exterior),
new RebarShapeConstraintFixedSegmentDir(new UV(1,0))
};
segment0.SetConstraints(segment0constraints);
var segment1 = definition.GetSegment(1);
List<RebarShapeConstraint> segment1constraints = new List<RebarShapeConstraint>()
{
new RebarShapeConstraintSegmentLength(
document.GetParameterId("b"),
RebarShapeSegmentEndReferenceType.Exterior,
RebarShapeSegmentEndReferenceType.Exterior),
new RebarShapeConstraint180DegreeDefaultBend(),
new RebarShapeConstraintFixedSegmentDir(new UV(0,1)),
};
segment1.SetConstraints(segment1constraints);
//Segment 2.
var segment2 = definition.GetSegment(2);
List<RebarShapeConstraint> segment2constraints = new List<RebarShapeConstraint>()
{
new RebarShapeConstraintSegmentLength(
document.GetParameterId("c"),
RebarShapeSegmentEndReferenceType.Exterior,
RebarShapeSegmentEndReferenceType.Exterior),
new RebarShapeConstraintFixedSegmentDir(new UV(-1,0))
};
segment2.SetConstraints(segment2constraints);
definition.AddBendDefaultRadius(0, RebarShapeVertexTurn.Default, RebarShapeBendAngle.Obtuse);
definition.AddBendDefaultRadius(1, RebarShapeVertexTurn.Left, RebarShapeBendAngle.Right);
definition.AddBendDefaultRadius(2, RebarShapeVertexTurn.Left, RebarShapeBendAngle.Right);
definition.AddBendDefaultRadius(3, RebarShapeVertexTurn.Default, RebarShapeBendAngle.Obtuse);
return definition;
}
and to use:
private static void CreateShapeTest(Document document, RebarShapeDefinition shapeDefinition, string shapeName)
{
using (Transaction transaction = new Transaction(document, "Create shape"))
{
transaction.Start();
var rebarShape2 = RebarShape.Create(
document,
shapeDefinition,
null,
RebarStyle.Standard,
StirrupTieAttachmentType.InteriorFace,
0,
new RebarShapeTerminationsData(document)
);
rebarShape2.Name = shapeName;
transaction.Commit();
}
}