public void MoveLinearBound()
{
Document doc = m_revitApp.ActiveUIDocument.Document;
// TBD: this usually produces a bunch of errors unless you pick one simple element
// by itself, like a single Wall in isolation.
int moveCount = 0;
int rejectedCount = 0;
//foreach( Element elem in m_revitApp.ActiveUIDocument.Selection.Elements ) // 2015, jeremy: 'Autodesk.Revit.UI.Selection.Selection.Elements' is obsolete: 'This property is deprecated in Revit 2015. Use GetElementIds() and SetElementIds instead.'
foreach( ElementId id in m_revitApp.ActiveUIDocument.Selection.GetElementIds() ) // 2016, jeremy
{
Element elem = doc.GetElement( id );
Location loc = elem.Location;
LocationCurve lineLoc = loc as LocationCurve;
if( lineLoc != null )
{
Line line;
XYZ newStart;
XYZ newEnd;
newStart = lineLoc.Curve.GetEndPoint( 0 );
newEnd = lineLoc.Curve.GetEndPoint( 1 );
newStart = new XYZ( newStart.X + 100, newStart.Y + 100, newStart.Z );
newEnd = new XYZ( newEnd.X + 75, newEnd.Y + 75, newEnd.Z );
line = Line.CreateBound( newStart, newEnd );
lineLoc.Curve = line;
moveCount++;
}
else
{
rejectedCount++;
}
}
string msgStr = string.Format( "Moved {0} elements. {1} were not Linear-bound.", moveCount, rejectedCount );
MessageBox.Show( msgStr );
}