/***************************************************/ private static FamilyInstance FamilyInstance_WorkPlaneBased(Document document, FamilySymbol familySymbol, Curve curve, Element host, RevitSettings settings) { Line line = curve as Line; if (line == null) { familySymbol.LinearOnlyError(); return(null); } Line location; Reference reference; if (host != null) { location = host.ClosestLineOn(line, out reference); } else { location = line; Level level = document.LevelBelow(line, settings); if (level == null) { return(null); } reference = level.GetPlaneReference(); } if (location == null || reference == null) { return(null); } FamilyInstance familyInstance = document.Create.NewFamilyInstance(reference, location, familySymbol); if (familyInstance == null) { return(null); } if (host == null) { familyInstance.CurveBasedNonHostedWarning(); } else { familyInstance.CurveBasedHostedWarning(); } return(familyInstance); }
/***************************************************/ private static FamilyInstance FamilyInstance_CurveBased(Document document, FamilySymbol familySymbol, Curve curve, Element host, RevitSettings settings) { Line line = curve as Line; if (line == null) { familySymbol.LinearOnlyError(); return(null); } Level level = document.LevelBelow(line, settings); if (level == null) { return(null); } FamilyInstance familyInstance = null; if (host == null) { familyInstance = document.Create.NewFamilyInstance(line, familySymbol, level, StructuralType.NonStructural); if (familyInstance == null) { return(null); } familyInstance.CurveBasedNonHostedWarning(); } else { Reference reference; Line location = host.ClosestLineOn(line, out reference); if (location != null && reference != null) { familyInstance = document.Create.NewFamilyInstance(reference, location, familySymbol); } if (familyInstance != null && location.GetEndPoint(0).DistanceTo(line.GetEndPoint(0)) > settings.DistanceTolerance || location.GetEndPoint(1).DistanceTo(line.GetEndPoint(1)) > settings.DistanceTolerance) { BH.Engine.Reflection.Compute.RecordWarning($"The location line of the created family instance has been snapped to the closest face of the host element. ElementId: {familyInstance.Id.IntegerValue}"); } } return(familyInstance); }