Dear Danny,
Congratulations on solving this and thank you for your appreciation and sharing your solution.
That looks viable to me. I discussed this technique in the past:
http://thebuildingcoder.typepad.com/blog/2011/07/refresh-element-graphics-display.html
As explained there, it might be safer if you move the region by a smaller amount than a full foot.
I have several other best practivce coding enhancements to suggest, if you don't mind:
- Using foreach instead of an explicit iterator saves you a lot of typing.
- The best way to handle transactions is to encapsulate them in a 'using' statement.
- You can encapsulate all your calls to MoveElement in one single transaction, instead of opening a new one for each call.
- You can use the static XYZ.BasisX member instead of explicitly instantiating your own X unit vector.
Regarding the using statement, please refer to
http://thebuildingcoder.typepad.com/blog/2012/04/using-using-automagically-disposes-and-rolls-back.h...
That discussion was followed by many more posts on handling transactions and transaction groups.
The resultting code looks like this:
public void EditFilledRegion( Document doc )
{
FilteredElementCollector fillRegions
= new FilteredElementCollector( doc )
.OfClass( typeof( FilledRegion ) );
using( Transaction tx = new Transaction( doc ) )
{
tx.Start( "Move all Filled Regions" );
foreach( FilledRegion filledRegion in fillRegions )
{
XYZ v = XYZ.BasisX;
ElementTransformUtils.MoveElement( doc, filledRegion.Id, v );
ElementTransformUtils.MoveElement( doc, filledRegion.Id, -v );
}
tx.Commit();
}
}
Once you see it like that, it also becomes obvious that it would be more effective to move all the regions at once using the MoveElements method, instead of one by one, leading to this:
public void EditFilledRegion( Document doc )
{
ICollection<ElementId> fillRegionIds
= new FilteredElementCollector( doc )
.OfClass( typeof( FilledRegion ) )
.ToElementIds();
using( Transaction tx = new Transaction( doc ) )
{
tx.Start( "Move all Filled Regions" );
XYZ v = XYZ.BasisX;
ElementTransformUtils.MoveElements( doc, fillRegionIds, v );
ElementTransformUtils.MoveElements( doc, fillRegionIds, -v );
tx.Commit();
}
}
Would you like to try that out?
And reduce the offset a bit, e.g by using something like
XYZ v = 0.01 * XYZ.BasisX;
Thank you!
Cheers,
Jeremy