Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Edit Start/End Of Constraint Rebar Stirrupt

1 REPLY 1
SOLVED
Reply
Message 1 of 2
mr.engineer.aec
445 Views, 1 Reply

Edit Start/End Of Constraint Rebar Stirrupt

 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.

 

mrengineeraec_0-1644980054232.png

 

1 REPLY 1
Message 2 of 2

Hi @mr.engineer.aec 

 

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:

  • In your code, I saw that you only specifically target the StartOfBar and EndOfBar handles of the stirrup tie, but what about the Edge type handles? Based on the current shape of your stirrup, I would presume that the Edge type handles in your case has already been assigned to the Cover, leaving only the StartOfBar and EndOfBar handles.
  • The next thing I saw from your code is that you were trying to collect all of the ToCover constraints of each handle and making sure that the TargetElement of the constraint is the same as the host element of your stirrup, which I think is already correct. However, when you were calculating the distance to the cover, you were comparing two ToCover constraints only (the first and the last element of the newConstraints list). I don't know whether this is always the case in your case, but I remember that there should have been multiple ToCover constraint candidates for each handle, thus I think it would be better if you first make sure whether there's only two constraint candidates in your newConstraints list. If not, then I would suggest that you use another algorithm to find the constraint candidate with most minimal distance to the handle which signifies the cover it should attach to.
  • The third thing I want to point out which I think is a mistake on your part (CMIIW) is that after you have compared d1 and d2, the nearestRebarConstraint is derived from the rebarConstraints list. However, wasn't the rebarConstraints a list of ToCover constraint candidates whose TargetElements were the ones before you compare them to the Host element? This means that the rebarConstraints list contains ALL of the ToCover constraints, including the ones OUTSIDE of the Host element. What I think you should have probably put over here is the newConstraints which is probably something like this:

 

 

 

 

RebarConstraint nearestRebarConstraint = null;
                                        if (Math.Abs(d1) > Math.Abs(d2))
                                        {
                                            nearestRebarConstraint = newConstraints.LastOrDefault();
                                        }
                                        else
                                        {
                                            nearestRebarConstraint = newConstraints.FirstOrDefault();
                                        }

 

 

 

 

  • The last thing I want to point out is that the distance that you set to the target cover is 10? What is your goal? do you want to attach the StartOfBar and EndOfBar handles exactly to the cover? then use 0. If 10 is indeed the intended number, pay attention to the measurement units. Last thing to make sure that the handle will use the nearest ToCover constraint handle, you will need to assign the nearestRebarConstraint as the preferred constraint handle (use the SetPreferredConstraintForHandle method of the RebarConstraintsManager)

 

Hope this helps

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report