Set distance methods of rebar constraints not working

Set distance methods of rebar constraints not working

YarUnderoaker
Collaborator Collaborator
1,266 Views
4 Replies
Message 1 of 5

Set distance methods of rebar constraints not working

YarUnderoaker
Collaborator
Collaborator

Hello.

I am trying to change distance value for rebar constraints, but method SetDistanceToTargetCover / SetDistanceToTargetHostFace  has no effect.

 

Is here need some special additional action to make it work or this part of API is broken?

0 Likes
Accepted solutions (1)
1,267 Views
4 Replies
Replies (4)
Message 2 of 5

YarUnderoaker
Collaborator
Collaborator

My code to test:

 

public void RebarStrongSpacing()
{
  Document doc = this.ActiveUIDocument.Document;
  ICollection<ElementId> elementSet = this.ActiveUIDocument.Selection.GetElementIds();
            
  Transaction t1 = new Transaction(doc, "Align rebar spacing" );
  t1.Start();
  RebarConstraintsManager.IsRebarConstrainedPlacementEnabled = true;
      
   foreach(ElementId id in elementSet)
   {
     Element e = doc.GetElement(id);
     Rebar rbr = e as Rebar;
     if (rbr != null)
     { 
       RebarConstraintsManager rebman = rbr.GetRebarConstraintsManager();
            		
       IList<RebarConstrainedHandle> hnds = rebman.GetAllConstrainedHandles();
            		
       double sp = rbr.MaxSpacing;
       double oldlen = rbr.ArrayLength;
       int posNum = Convert.ToInt32( Math.Floor(oldlen / sp) ) ;
       double newlen = sp * posNum;
       double halfshift = 0.5*(oldlen - newlen);
            			
       foreach(RebarConstrainedHandle hnd in hnds)
       {
         if (hnd.GetHandleType() == RebarHandleType.RebarPlane || hnd.GetHandleType() == RebarHandleType.OutOfPlaneExtent)
         {
           RebarConstraint constr = rebman.GetCurrentConstraintOnHandle(hnd);
            				
           if (constr.GetConstraintType() == RebarConstraintType.ToCover)
           {
            	double dis = constr.GetDistanceToTargetCover();
            	constr.SetDistanceToTargetCover(dis - halfshift);
           }
           else if (constr.GetConstraintType() == RebarConstraintType.FixedDistanceToHostFace)
           {
            	double dis = constr.GetDistanceToTargetHostFace();
            	constr.SetDistanceToTargetHostFace(dis - halfshift);
           }
         }
            			
       }  		
     }
   }
            
   RebarConstraintsManager.IsRebarConstrainedPlacementEnabled = false;
   t1.Commit();
}

 

Message 3 of 5

YarUnderoaker
Collaborator
Collaborator

up

Message 4 of 5

YarUnderoaker
Collaborator
Collaborator
Accepted solution

Me need to add  rebman.SetPreferredConstraintForHandle(hnd, constr); after SetDistance and its work.

Also changing RebarConstraintsManager.IsRebarConstrainedPlacementEnabled is not necessary.

Message 5 of 5

190027864
Participant
Participant

vvvvvvvvvvvvvvvery nice  !

0 Likes