Hello Frode,
You can get the shape centerlines (without hooks) in order (from start to end) with the following method :
IList<Curve> curvesForBrowser = rebarShape.GetCurvesForBrowser();
Note: You should be able to retrieve the RebarShape element from the family document.
Hook information can be retrieved through methods:
int hookangle0 = rebarShape.GetDefaultHookAngle(0);
RebarHookOrientation orient0 = rebarShape.GetDefaultHookOrientation(0);
int hookangle1 = rebarShape.GetDefaultHookAngle(1);
RebarHookOrientation orient1 = rebarShape.GetDefaultHookOrientation(1);
Hook position should be as follows:
Start hook origin point should be : curvesForBrowser[0].GetEndPoint(0);
End hook origin point should be : curvesForBrowser[curveSize -1].GetEndPoint(1);
And the connection between the curvesForBrowser and the dimensions in the family can be retrieved like this:
1. Map the dimensions to their label parameter ids.
IDictionary<ElementId, ElementId> labelParamIdToDimId = new Dictionary<ElementId, ElementId>();
foreach (Dimension dim in familyDimensions)
{
try
{
FamilyParameter famParam = dim.FamilyLabel;
if (null == famParam)
continue;
labelParamIdToDimId[famParam.Id] = dim.Id;
}
catch (Autodesk.Revit.Exceptions.InvalidOperationException)
{
continue;
}
}
2.Get the constraint information from the shape definition.
// Get the shape definition : constraints should be available for every definition.
// Get all the shape segments (indexes of segments) and their corresponding constraint parameter ids
// The RebarShapeSegment should be in the same order as the curvesForBrowser.
// The constraint param ids should correspond to the dimension label param ids.
RebarShapeDefinitionBySegments defBySeg = rebarShape.GetRebarShapeDefinition() as RebarShapeDefinitionBySegments;
IDictionary<int, string> segmentPosToLabel = new Dictionary<int, string>();
for (int ii = 0; ii < defBySeg.NumberOfSegments; ii++)
{
RebarShapeSegment seg = defBySeg.GetSegment(ii);
IList<RebarShapeConstraint> constraints = seg.GetConstraints();
foreach (RebarShapeConstraint constraint in constraints)
{
ElementId paramID = constraint.GetParamId();
if ((paramID == ElementId.InvalidElementId) || !labelParamIdToDimId.ContainsKey(paramID))
continue;
string labelName = "";
foreach (Parameter param in rebarShape.Parameters)
{
if (param.Id == paramID)
{
labelName = param.Definition.Name;
break;
}
}
segmentPosToLabel.Add(ii, labelName);
}
}
Finally you should be able to retrieve/create all the curves and their corresponding dimensions:
IList<Curve> curvesForPicture = new List<Curve>();
for (int ii = 0; ii < defBySeg.NumberOfSegments; ii++)
{
Curve curve = curvesForBrowser[ii];
string label = "";
if (!segmentPosToLabel.TryGetValue(ii, out label))
continue;
}
Please let me know if this works for you.
Regards,
Tiberiu