Hi guys,
I'm trying create rebar for structural column.
But after create stirrupt tie, start/end rebar contraint have distance != 0 to cover => segment dimensions incorrect.
I tried edit but nothing happen.
I have consulted 1 helpful article here but still can't solve it.
https://forums.autodesk.com/t5/revit-api-forum/problem-with-constraining-stirrups-to-the-cover-of-th...
using (Transaction tran = new Transaction(doc, "Create Rebar"))
{
tran.Start();
RebarConstraintsManager rebarConstraintsManager
= stirruptRebar.GetRebarConstraintsManager();
IList<RebarConstrainedHandle> rebarConstrainedHandles
= rebarConstraintsManager.GetAllHandles();
IList<RebarConstrainedHandle> newConstrainedHandles = new List<RebarConstrainedHandle>();
foreach (RebarConstrainedHandle handle in rebarConstrainedHandles)
{
RebarHandleType rebarHandleType = handle.GetHandleType();
if ( rebarHandleType == RebarHandleType.StartOfBar
|| rebarHandleType == RebarHandleType.EndOfBar)
{
newConstrainedHandles.Add(handle);
}
}
foreach (RebarConstrainedHandle handle in newConstrainedHandles)
{
RebarHandleType rebarHandleType = handle.GetHandleType();
if (rebarHandleType == RebarHandleType.EndOfBar
|| rebarHandleType == RebarHandleType.StartOfBar)
{
List<RebarConstraint> constraintCandidates
= rebarConstraintsManager
.GetConstraintCandidatesForHandle(handle).ToList();
List<RebarConstraint> rebarConstraints = constraintCandidates.FindAll(
c => c.IsToCover());
List<RebarConstraint> newConstraints = new List<RebarConstraint>();
foreach (RebarConstraint rebarConstraint in rebarConstraints)
{
Element targetElement = rebarConstraint.GetTargetElement();
if (targetElement.Id == strColumn.Id)
{
newConstraints.Add(rebarConstraint);
}
}
double d1 = newConstraints.FirstOrDefault().GetDistanceToTargetCover();
double d2 = newConstraints.LastOrDefault().GetDistanceToTargetCover();
RebarConstraint nearestRebarConstraint = null;
if (Math.Abs(d1) > Math.Abs(d2))
{
nearestRebarConstraint = rebarConstraints.LastOrDefault();
}
else
{
nearestRebarConstraint = rebarConstraints.FirstOrDefault();
}
nearestRebarConstraint.SetDistanceToTargetCover(10);
}
}
tran.Commit();
}
Hope for a help.
Solved! Go to Solution.
Solved by kevin.anggrek. Go to Solution.
I am the original poster of the thread that you mentioned in your post.
I haven't tested your code, but just comparing it with my working code, I would like to point out several things:
RebarConstraint nearestRebarConstraint = null;
if (Math.Abs(d1) > Math.Abs(d2))
{
nearestRebarConstraint = newConstraints.LastOrDefault();
}
else
{
nearestRebarConstraint = newConstraints.FirstOrDefault();
}
Hope this helps
Can't find what you're looking for? Ask the community or share your knowledge.