Foundation Tag Rotate to match footing ElementTransformUtils.RotateElement(doc, tag.Id, rotationLine, rotateValue);

Foundation Tag Rotate to match footing ElementTransformUtils.RotateElement(doc, tag.Id, rotationLine, rotateValue);

Anonymous
Not applicable
1,101 Views
3 Replies
Message 1 of 4

Foundation Tag Rotate to match footing ElementTransformUtils.RotateElement(doc, tag.Id, rotationLine, rotateValue);

Anonymous
Not applicable

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 rotationfoundation 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
)
0 Likes
Accepted solutions (3)
1,102 Views
3 Replies
Replies (3)
Message 2 of 4

StephenSmith-WPM
Explorer
Explorer
Accepted solution

Foundation Tags do not rotate with the components prior to Revit 2022 (although I haven't tested it in Revit 2022). To get around this, you would have to create a custom tag with the label already rotated. Or you can just keep the tags horizontal and use an arrow to point to the element you're tagging.

Message 3 of 4

so-chong
Advocate
Advocate
Accepted solution

Hi, before running the code try go to the family editor (edit family) of Structural Foundation Tags and go to the "Family Category and Parameters" window.

Try to check the setting "Rotate with component".

Save or load the family back into in the project document and then run the code.

 

sochong_1-1638311963355.pngsochong_0-1638312863925.png

 

 

Message 4 of 4

Anonymous
Not applicable
Accepted solution

I tried this, and either way, it has no effect in 19 & 20?  In Revit 21 & 22 it works well. I had hoped the API could get the job done. Maybe not. Thanks for the reply @StephenSmith-WPM & @so-chong .