Advertisement

Sunday, August 27, 2017

Using the API to Move Items Inside a Detail Group

From the The Building Coder blog:

Moving Items Inside a Detail Group

August 17, 2017
By Jeremy Tammik

Fair59 solved another issue in the Revit API discussion forum thread on moving detail group only moves its location point, not detail items inside:

Question: I'm trying to move Detail Group element to a point that was picked, but only the Location of the group moves, not the detail items inside.

Answer: To move the entire group, you can use:

  XYZ moveVector = new XYZ( 500 );

  using( Transaction t = new Transaction( doc ) )
  {
    List<ElementId> toMove = new List<ElementId>() {
      group.Id };

    toMove.AddRange( group.GetMemberIds() );
    t.Start( "MoveGroup" );
    ElementTransformUtils.MoveElements( doc, 
      toMove, moveVector );
    t.Commit();
  }

In the creation of the (extra) list, I added the group.Id. So I move the group.Id and the member.Ids.
You can set the translation vector from the old point to the picked point like this:

  XYZ locPoint = ( group.Location as LocationPoint ).Point;
  XYZ pickedPoint;
  moveVector = pickedPoint.Subtract( locPoint );

Thank you, Fair59, for yet another succinct and accurate solution!



There's more information available on the The Building Coder blog.

No comments: