Copying annotation elements between assembly views

Copying annotation elements between assembly views

steven_ortiz
Explorer Explorer
410 Views
0 Replies
Message 1 of 1

Copying annotation elements between assembly views

steven_ortiz
Explorer
Explorer

I am working on a routine that uses 

 

ElementTransformUtils.CopyElements(Document sourceDocument, ICollection<ElementId> elementsToCopy, Document destinationDocument, Transform transform, CopyPasteOptions options)

 

to copy items from one assembly view to others.  The assemblies I am working with are not parallel to each other in the model and they are not orthogonal to the X, Y, or Z axis.  The assemblies and views are created by a 3rd-party plugin.  I have determined how to get the detail items to be properly rotated in the destination view but I am having a hard time finding a method to determine the translation to move the elements into the right location with

 

MoveElements(Document document, ICollection<ElementId> elementsToMove, XYZ translation);

 

 The code below works when both "Elevation Top" views are created using OOTB Revit

 

 // Get the right direction of the view this should be the same as the assembly basis x
                            XYZ rightdirection = new XYZ();
                            rightdirection = viewIds.ElementAt(i).RightDirection;

                            //get the angle to for the right direction and calculate the paste rotation required
                            XYZ xAxis = new XYZ(1, 0, 0);  // This could have been done by creating an XYZ and getting BasisX
                            double angle;
                            double viewrotation, rotation;
                            angle = xAxis.AngleTo(rightdirection);
                            viewrotation = -angle;
                            rotation = 2 * Math.PI - viewrotation;  // Not tested exhaustively for various orientations.  I think this is having to be done because AngleTo is using Atan2???
                           //create the transform to be used and perform copy
                            Transform trans = Transform.CreateRotationAtPoint(XYZ.BasisZ, rotation, viewIds.ElementAt(i).Origin);
                            ICollection<ElementId> copyResult = ElementTransformUtils.CopyElements(doc.ActiveView, elementsToCopy, viewIds.ElementAt(i), trans, null);

 

For some reason not all of the "Elevation Top" views created by the third-party plugin have the same origin as the same view created using OOTB tools.  I thought I would be able to calculate a vector from the source assembly origin using GetCenter() to its view origin then use that vector to determine the distance from the pasted element location to the desired pasted element location by subtracting the vector from the destination assembly origin and then subtracting the source assembly view origin from the resulting XYZ.  That did not work.

Another thought that I had was to reset the destination view's origin prior to the paste operation.  Unfortunately, and maybe I just missed it, I cannot find a method that allows me to change the view origin.  I'm at a loss as to why I haven't been able to calculate the translation and I've hit that wall where I just keep trying the same things it seems like.  Are there any methods to find a translation in a situation like this or maybe just a way to reset the origin of the view?

0 Likes
411 Views
0 Replies
Replies (0)