Question

i'm trying to make Instance of Selected object entered by the user in Revit Api 2012 c#,I discovered that the third input to ElementTransformUtils.CopyElement is the translation vector not the new place so i'm trying to pick fixed point from the element selected then substract the new place location from it and put the result as translation vector. the problem is : i use pickobject.globalPoint to obtain point from the selected object which changes every time i ran the code so the Question : how to obtain the same point every time i select the Element Entered by the user? Thanks In Advance

Was it helpful?

Solution

Select the original element as explained here: create Instances of Selected object Revit Api

Retrieve the element's location as follows:

Location location = originalElement.Location;

LocationPoint locationPoint = location as LocationPoint;

if (locationPoint != null)
{
  XYZ originalPoint = location.Point;
}

Select a location for the new element as follows:

UIDocument uidoc = this.ActiveUIDocument;

XYZ newPoint = uidoc.Selection.PickPoint("Select a location for the element");

Create the translation vector:

XYZ translationVector = newPoint - originalPoint;

Copy the element:

Document doc = uidoc.Document;

ICollection<ElementId> copiedElementIds = ElementTransformUtils.CopyElement(doc, originalElement.Id, translationVector);

According to the API docs, the reason an ICollection is returned as opposed to a single ElementId is: "More than one element may be created due to dependencies."

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top