MoveElement silently projects translation vector onto sketch plane

I was trying to use  ElementTransformUtils.MoveElement to move a model line. The line would move, but not in the direction specified by the vector I was using for MoveElement. WHY?!

It happens because the line can only move in its sketch plane. This makes perfect sense now, but it can be strange when you tell the API to move the line by (10, 10, 0) and it moves somewhere else without any error.

Advertisements

3 thoughts on “MoveElement silently projects translation vector onto sketch plane

  1. Hi,
    is there something that I have not figured out in MoveElement function because I can´t change familyinstance location trought .NET API. I send some code below this row:
    Using tr As New Transaction(doc, “Replace family instances”)
    tr.Start()
    For Each tempFamInstanceItem As TempElementIdAndLocation In colTempFamilyInstances
    ‘Try to modify elevation
    ElementTransformUtils.MoveElement(doc, tempFamInstanceItem.elemId, tempFamInstanceItem.location)

    ‘Other try out to modify elevation
    Dim locPnt As LocationPoint = DirectCast(tempFamInstanceItem.famInstance.Location, LocationPoint)
    Debug.WriteLine(“OldLocation: ” + locPnt.Point.ToString)
    Dim newLoc As New XYZ(tempFamInstanceItem.location.X, tempFamInstanceItem.location.Y, tempFamInstanceItem.location.Z)
    locPnt.Point = newLoc
    Debug.WriteLine(“NewLocation: ” + locPnt.Point.ToString)
    Next
    doc.Regenerate()
    tr.Commit()
    End Using

    Cheers
    Veli V.

    • Hi,

      Have you tried something like this? It will move every family instance up by 10 feet. To move them vertically, you can also try modifying the INSTANCE_FREE_HOST_OFFSET_PARAM built-in parameter (known in the UI as “Offset”)

      public void moveElement()
      {
      Document doc = this.ActiveUIDocument.Document;
      using (Transaction t = new Transaction(doc, "move"))
      {
      t.Start();
      foreach (Element e in new FilteredElementCollector(doc).OfClass(typeof(FamilyInstance)))
      {
      ElementTransformUtils.MoveElement(doc, e.Id, new XYZ(0,0,10));
      }
      t.Commit();
      }
      }

      • Thank you for answer. I have tried that and only difference is that I try to change FamilyInstance elevation in Family context. I´m not really sure is it possible to do that in family context. I try to compose one family from multiple rfa files and set FamilyInstances ín different elevations.
        -Veli

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s