Message 1 of 8
Not applicable
01-31-2018
01:17 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi Everyone,
I just want to thank everybody first off for all the content and the support. I've started working with the Revit API recently, and it's useful to have this backlog of information.
I'm having an issue with a plugin that's suppose to generate a bunch of face based families. As far as I can tell all the information I've gathered is solid. I'm using the doc.Create.NewFamilyInstance(Face Reference, Spawn Point, FamilySymbol) overload and I don't get any compile errors, and it doesn't seem to throw any exceptions when I'm debugging from VS. So, my question is, why the method doesn't seem to produce anything? I get no instantiation whatsoever.
Here's the code bits.
//Sprinkler Declarations
FamilySymbol activeSprinkler = null;
string desiredType = "15 mm Pendent";
var sprinklerPoints = new List<XYZ>();
XYZ referenceDirection = new XYZ(0, 0, 0);
//Find the relevant sprinkler types
FilteredElementCollector sprinklerTypes = new FilteredElementCollector(doc).OfClass(typeof(FamilySymbol)).OfCategory(BuiltInCategory.OST_Sprinklers);
if (sprinklerTypes.Count() != 0)
{
foreach (Element e in sprinklerTypes)
{
if (e.Name.Contains(desiredType))
{
activeSprinkler = (FamilySymbol)e;
}
}
}
//Define a Reference object to accept the room and ceiling selection results
Selection sel = uiApp.ActiveUIDocument.Selection;
RoomPickFilter roomFilter = new RoomPickFilter();
Reference roomRef = sel.PickObject(ObjectType.Element, roomFilter, "Please Select a Room");
Room selectedRoom = doc.GetElement(roomRef) as Room;
CeilingPickFilter ceilingFilter = new CeilingPickFilter();
Reference ceilingRef = sel.PickObject(ObjectType.Element, ceilingFilter, "Please Select the Ceiling");
Ceiling selectedCeiling = doc.GetElement(ceilingRef) as Ceiling;
//Get Bottom face of ceiling to host our family
IList<Reference> faces = HostObjectUtils.GetTopFaces(selectedCeiling);
//Element myFace = doc.GetElement(faces[0]);
Ceiling myFace = selectedCeiling;
Face ceilingFace = (Face)myFace.GetGeometryObjectFromReference(faces[0]);
sprinklerPoints = SetSprinklerPoints(selectedRoom, ceilingFace, 1);
//SPAWN Sprinklers
if (!activeSprinkler.IsActive)
{
activeSprinkler.Activate();
doc.Regenerate();
}
//for (int i = 0; i < sprinklerPoints.Count(); i++)
//{
doc.Create.NewFamilyInstance(faces[0], sprinklerPoints[0], referenceDirection, activeSprinkler);
//}
}
catch (Autodesk.Revit.Exceptions.OperationCanceledException)
{
string title = "Operation Cancelled";
string body = "The operation was cancelled before it could be completed.";
TaskDialog.Show(title, body);
return Result.Cancelled;
}
}
return Result.Succeeded;Thanks,
Solved! Go to Solution.
