Message 1 of 4

Not applicable
11-30-2021
01:23 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The below code runs without error. However, the tags are not rotated via the below code.
ElementTransformUtils.RotateElement(doc, tag.Id, rotationLine, rotateValue);
foundation tags not matching footing rotation
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
namespace RevitMcLaren
{
[TransactionAttribute(TransactionMode.Manual)]
public class FootingTagIsolated : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
//Get UIDocument
UIDocument uidoc = commandData.Application.ActiveUIDocument;
//Get Document
Document doc = uidoc.Document;
//Tag Parameters
TagMode tmode = TagMode.TM_ADDBY_CATEGORY;
TagOrientation tOrient = TagOrientation.Horizontal;
List<BuiltInCategory> cats = new List<BuiltInCategory>();
cats.Add(BuiltInCategory.OST_StructuralFoundation);
ElementMulticategoryFilter filter = new ElementMulticategoryFilter(cats);
IList<Element> tElements = new FilteredElementCollector(doc, doc.ActiveView.Id)
.WherePasses(filter)
.WhereElementIsNotElementType()
.ToElements();
try
{
using (Transaction trans = new Transaction(doc, "Tag Elements"))
{
trans.Start();
//Tag Elements
foreach (Element ele in tElements)
{
//Retrieve Element
ElementId eleId = ele.Id; //element Id is a value not an object
Element eleNDoc = doc.GetElement(eleId); //element in document is a selected selement by value(Id)
//Get Parameter
//Parameter pWidth = eleNDoc.LookupParameter("Width"); //Get parameter of Foundation
string pWidth = eleNDoc.LookupParameter("Width").AsValueString(); //Get parameter's value as a string of Foundation
string pLength = eleNDoc.LookupParameter("Length").AsValueString(); //Get parameter of Foundation
//Use of external class ConvertFeetInches to get sum of feet plus inches as inches
var pWidthOut = ConvertFeetToInches.ToInches(pWidth);
var pLengthOut = ConvertFeetToInches.ToInches(pLength);
//Get Foundation LocationPoint (center of footing)
Reference refe = new Reference(ele);
LocationPoint loc = ele.Location as LocationPoint;
XYZ point = loc.Point;
var pointX = loc.Point.X;
var pointY = loc.Point.Y;
var pointZ = loc.Point.Z;
//Create new variables for later use out of "if" scope
double newpointX;
double newpointY;
//If point is negitive add, if positive subtract (to achive bottom right orientation)
//The divide by 2 is half of the original Width and Length parameter
if (pointX < 0)
{
newpointX = pointX + ((pWidthOut / 12)/2);
}
else
{
newpointX = pointX - ((pWidthOut / 12) / 2);
}
if (pointY < 0)
{
newpointY = pointY + ((pLengthOut / 12) / 2);
}
else
{
newpointY = pointY - ((pLengthOut / 12) / 2);
}
//Create new point to place tag at (bottom right of footing)
XYZ updatedPoint = new XYZ(newpointX, newpointY, pointZ);
//create new point same as previous but with a increased Z. use the two points to create a line to use as an axis of rotation
XYZ updatedZ = new XYZ(newpointX, newpointY, (updatedPoint.Z+1));
Line rotationLine = Line.CreateBound(updatedPoint, updatedZ);
//Get the foundations locationPoint rotation, for use in rotating tag to match
var rotateValue = (ele.Location as LocationPoint).Rotation;
//Create new tag
IndependentTag tag = IndependentTag.Create(doc, doc.ActiveView.Id, refe, false, tmode, tOrient, updatedPoint);
//Rotate Tag
ElementTransformUtils.RotateElement(doc, tag.Id, rotationLine, rotateValue);
//Delete when done, use as a visual check
TaskDialog.Show("Values", "" + updatedPoint + ", " + updatedZ);
}
trans.Commit();
}
return Result.Succeeded;
}
catch (Exception e)
{
message = e.Message;
return Result.Failed;
}
}
}
}
Thanks for taking the time!
Reference:
https://www.revitapidocs.com/2019/3968f4e8-759c-f975-6c1f-7de42be633ed.htm
public static void RotateElement(
Document document,
ElementId elementToRotate,
Line axis,
double angle
)
Solved! Go to Solution.