Brett,
Your help with this has been outstanding. thank you so much for taking the time to work with me on this.
After running the program I realized that I needed to add 90 degrees to the angle, (family at zero degrees is actually pointed 90 degrees) as well as remebering Revit deals with feet. So of course the tags were being moved over 20 feet and not 20 inches.
Everything works for this.
A couple of minor questions I have though. The importance of answering these are not important as I already got the program to work.
1. When selecting items separatly, nothing gets hightlighted even though it is selected. Need some sort of highlight mode?
2. Is there some sort of C# Revit function for "Tag all not tagged" that can be used to tag the fixtures and then I can use that as a selection to run this program?
Anyway here is the complete code that I got to work:
public void MoveFixtureTags()
{
Document doc= this.ActiveUIDocument.Document;
int sc = ActiveUIDocument.ActiveView.Scale;
IList<Reference> refs = null;
Selection sel = ActiveUIDocument.Selection;
refs = sel.PickObjects(ObjectType.Element, new selFilter(), "Select Electrical fixture tags");
using (Transaction rvtTransaction = new Transaction(doc))
{
rvtTransaction.Start("Move Tag");
foreach (Reference ckt in refs)
{
//Get the family object that the tag is referencing
IndependentTag tag = doc.GetElement(ckt.ElementId) as IndependentTag;
Element host = doc.GetElement(tag.TaggedLocalElementId);
//get the host rotation
LocationPoint hostLocation = host.Location as LocationPoint;
double hostRotation = hostLocation.Rotation + Math.PI/2; //+90 degrees
//calcualte translation components
double distanceToMove = sc / 57.6; //move 20 inches for 1/8" scale, 10 for 1/4", etc.
double x = distanceToMove * Math.Cos(hostRotation);
double y = distanceToMove * Math.Sin(hostRotation);
double z = 0;
//move tag set distance
XYZ translation = new XYZ(x, y, z);
ElementTransformUtils.MoveElement(doc, tag.Id, translation);
}
rvtTransaction.Commit();
}
}
/// Filter to constrain picking to model groups. Only model groups
/// are highlighted and can be selected when cursor is hovering.
class selFilter : ISelectionFilter
{
public bool AllowElement (Element e)
{
if (e.Category.Id.IntegerValue == (int)BuiltInCategory.OST_ElectricalFixtureTags) return true;
//if (e.Category.Id.IntegerValue == (int)BuiltInCategory.OST_ElectricalFixtures) return true;
return false;
}
public bool AllowReference(Reference r, XYZ p)
{
return false;
}
}