Dimension are resized when copied using API

Dimension are resized when copied using API

Anonymous
Not applicable
599 Views
4 Replies
Message 1 of 5

Dimension are resized when copied using API

Anonymous
Not applicable

 Hello all,

 

We were trying to copy a dimension from a view in a document to same view in other document using `ElementTransformUtils.CopyElements` API, and the dimension that we are trying to copy is between two walls. However after copying, we see that the dimension is getting snapped to a different side of the wall. And we also observed this issue while manually copying the dimension through Revit UI. Please find below image to get better understanding

 

Source dimensionSource dimensionDimension after copyingDimension after copying

 

 

 

 

 

 

 

 

 

 

 

 

Please find the code that we used:

 

public void CopyDimensions(Document sourceDocument, Document destinationDocument, Transaction transaction) {
  var dimensions = new FilteredElementCollector(sourceDocument)
                  .OfClass(typeof(Dimension))
                  .Cast<Dimension>().ToList();

  foreach (var dimension in dimensions)
  {
    if (!dimension.ViewSpecific)
        continue;
    var targetView = GetViewWithName(destinationDocument, dimension.View.Name);

    var transform = Transform.CreateTranslation(new XYZ(0, 0, 0));
    var copyPasteOptions = GetDefaultCopyPasteOptions();

    transaction.Start();
    ElementTransformUtils.CopyElements(dimension.View, dimension.Id, targetView, transform,
        copyPasteOptions);
    transaction.Commit(_failureHandlingOptions);
  }
}

 

 

Thank you!

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

BardiaJahan
Advocate
Advocate

I think when you copy the dimension, since it needs to have references at both ends, it tries to grab the nearest reference and it seems those walls in your views are not the same ones or are not at the same location.

Message 3 of 5

Anonymous
Not applicable

Hello BardiaJahan,

 

Those are the same walls but just that it snaps to the other side of the wall, however as you said while copying it might not be using the same references. How can we copy the dimension along with the references?

0 Likes
Message 4 of 5

BardiaJahan
Advocate
Advocate
Accepted solution

You can retrieve the references as a ReferenceArray from the existing dimension - Dimension.References

And then, in the other view, create a new dimension using  Document.NewDimension method and the retrieved references.

Message 5 of 5

Anonymous
Not applicable

Hello BardiaJahan,

 

Thank you very much for your time. The approach of creating a new dimension with existing references is working fine 🙂

 

However, I still want to know If there is a way I can accomplish this using copy API?

 

Thanks,

Nagesh

0 Likes