Creating a 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 via the RebarShapeDefinitionBySegments class, but I cannot get it to work.
When created via the UI a definition with 3 segments with the following constraints are created:
0: Length, FixedDir
1: Length, FixedDir, 180DegreeDefaultBend
2: Length, FixedDir
I have replicated this structure in the following code, and Revit reports the shape as beeing complete, however when I try to edit it afterwards via the UI, it fails to open. This usually means there is something wrong with either the default parameter values or the constraints, but I cannot figure out where the error is, or if this is actually possible, given that, I have found no code examples covering this part of the API.
To run this code 3 length parameters called a, b and c must exist. Otherwise it should run.
private static RebarShapeDefinition CreateShapeDefinitionTest_U_shape(Document document)
{
var definition = new RebarShapeDefinitionBySegments(document, 3);
definition.AddParameter(document.GetParameterId("a"), 0.65d);
definition.AddParameter(document.GetParameterId("b"), 0.65d);
definition.AddParameter(document.GetParameterId("c"), 0.65d);
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;
}
Create the shape via:
private static void CreateShapeTest(Document document, RebarShapeDefinition shapeDefinition, string shapeName)
{
using (Transaction transaction = new Transaction(document, "Create shape"))
{
transaction.Start();
var rebarShape = RebarShape.Create(
document,
shapeDefinition,
null,
RebarStyle.Standard,
StirrupTieAttachmentType.InteriorFace,
0,
new RebarShapeTerminationsData(document)
);
rebarShape.Name = shapeName;
transaction.Commit();
}
}