Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
We create family instances in Revit using coordinates from an Excel file.
The values of these coordinates are relative to the project base point.
The project base point in Revit is not at 0,0,0 and has an angle.
Unfortunately, when we create the family instances using Revit API, they are always placed relative to Revit's internal origin, which is wrong.
How can we use the Revit API to create new family instances relative to the project base point instead of the internal origin?
I'm sure I'm missing something, and using trigonometric functions can't be the solution in my opinion.
This is the relevant part of the code:
// get the Revit app and the active document
UIApplication uiApplication = commandData.Application;
UIDocument uiDocument = uiApplication.ActiveUIDocument;
Document doc = uiDocument.Document;
// get the level
FilteredElementCollector levels = new FilteredElementCollector(doc).WhereElementIsNotElementType().OfCategory(BuiltInCategory.INVALID).OfClass(typeof(Level));
Level projectBasePointLevel = levels.FirstElement() as Level;
// convert the Excel coordinates from metric to internal Revit units
double pointX = UnitUtils.ConvertToInternalUnits(excelPointX, UnitTypeId.Meters);
double pointY = UnitUtils.ConvertToInternalUnits(excelPointY, UnitTypeId.Meters);
double pointZ = UnitUtils.ConvertToInternalUnits(excelPointZ, UnitTypeId.Meters);
// create Revit coordinates for the family instance location
XYZ instanceLocation = new XYZ(pointX, pointY, pointZ);
using (Transaction transaction = new Transaction(doc, transactionName))
{
_ = transaction.Start(transactionName);
// get the family symbol
FamilySymbol familySymbol = doc.GetElement(familyId) as FamilySymbol;
if (!familySymbol.IsActive)
{
familySymbol.Activate();
}
// create a new family instance
familyInstance = doc.Create.NewFamilyInstance(instanceLocation, familySymbol, projectBasePointLevel, Autodesk.Revit.DB.Structure.StructuralType.UnknownFraming);
}
Solved! Go to Solution.