<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: doc.Create.NewFamilyInstance() creates null in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/doc-create-newfamilyinstance-creates-null/m-p/7743710#M52833</link>
    <description>&lt;P&gt;You are using the wrong overload, meseems.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, I recommend that you check out The Building Coder discussion on this exact topic from 2010:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H3 class="entry-header"&gt;Insert Face-Hosted Sprinkler&lt;/H3&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://thebuildingcoder.typepad.com/blog/2010/01/insert-facehosted-sprinkler.html" target="_blank"&gt;http://thebuildingcoder.typepad.com/blog/2010/01/insert-facehosted-sprinkler.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It may be somewhat out of date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An up-to-date version of the&amp;nbsp;&lt;SPAN&gt;CmdNewSprinkler command is available from The Building Coder samples GitHub repo:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://github.com/jeremytammik/the_building_coder_samples" target="_blank"&gt;https://github.com/jeremytammik/the_building_coder_samples&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/BuildingCoder/CmdNewSprinkler.cs" target="_blank"&gt;https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/BuildingCoder/CmdNewSprinkler.cs&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;It uses this overload:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;  NewFamilyInstance( 
    Face face, 
    XYZ location, 
    XYZ referenceDirection, 
    FamilySymbol symbol )
&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;I seem to remember other later discussions on inserting sprinklers that might also be worth checking out.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Jeremy&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 01 Feb 2018 16:23:16 GMT</pubDate>
    <dc:creator>jeremytammik</dc:creator>
    <dc:date>2018-02-01T16:23:16Z</dc:date>
    <item>
      <title>doc.Create.NewFamilyInstance() creates null</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/doc-create-newfamilyinstance-creates-null/m-p/7741190#M52830</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the code bits.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;//Sprinkler Declarations
					FamilySymbol activeSprinkler = null;
					string desiredType = "15 mm Pendent";
					var sprinklerPoints = new List&amp;lt;XYZ&amp;gt;();
					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&amp;lt;Reference&amp;gt; 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 &amp;lt; 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;&lt;/PRE&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2018 21:17:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/doc-create-newfamilyinstance-creates-null/m-p/7741190#M52830</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-01-31T21:17:24Z</dc:date>
    </item>
    <item>
      <title>Re: doc.Create.NewFamilyInstance() creates null</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/doc-create-newfamilyinstance-creates-null/m-p/7741728#M52831</link>
      <description>&lt;P&gt;Please provide a sample Revit project with the used Family.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 03:31:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/doc-create-newfamilyinstance-creates-null/m-p/7741728#M52831</guid>
      <dc:creator>Mustafa.Salaheldin</dc:creator>
      <dc:date>2018-02-01T03:31:11Z</dc:date>
    </item>
    <item>
      <title>Re: doc.Create.NewFamilyInstance() creates null</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/doc-create-newfamilyinstance-creates-null/m-p/7743230#M52832</link>
      <description>&lt;P&gt;I can post a test file tonight, but any face based family should work. For the file itself, my test case is literally a box with a room and ceiling defined.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the reply.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 14:34:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/doc-create-newfamilyinstance-creates-null/m-p/7743230#M52832</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-02-01T14:34:25Z</dc:date>
    </item>
    <item>
      <title>Re: doc.Create.NewFamilyInstance() creates null</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/doc-create-newfamilyinstance-creates-null/m-p/7743710#M52833</link>
      <description>&lt;P&gt;You are using the wrong overload, meseems.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, I recommend that you check out The Building Coder discussion on this exact topic from 2010:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H3 class="entry-header"&gt;Insert Face-Hosted Sprinkler&lt;/H3&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://thebuildingcoder.typepad.com/blog/2010/01/insert-facehosted-sprinkler.html" target="_blank"&gt;http://thebuildingcoder.typepad.com/blog/2010/01/insert-facehosted-sprinkler.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It may be somewhat out of date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An up-to-date version of the&amp;nbsp;&lt;SPAN&gt;CmdNewSprinkler command is available from The Building Coder samples GitHub repo:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://github.com/jeremytammik/the_building_coder_samples" target="_blank"&gt;https://github.com/jeremytammik/the_building_coder_samples&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;A href="https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/BuildingCoder/CmdNewSprinkler.cs" target="_blank"&gt;https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/BuildingCoder/CmdNewSprinkler.cs&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;It uses this overload:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;  NewFamilyInstance( 
    Face face, 
    XYZ location, 
    XYZ referenceDirection, 
    FamilySymbol symbol )
&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;I seem to remember other later discussions on inserting sprinklers that might also be worth checking out.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Jeremy&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 16:23:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/doc-create-newfamilyinstance-creates-null/m-p/7743710#M52833</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2018-02-01T16:23:16Z</dc:date>
    </item>
    <item>
      <title>Re: doc.Create.NewFamilyInstance() creates null</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/doc-create-newfamilyinstance-creates-null/m-p/7743923#M52834</link>
      <description>&lt;P&gt;Thanks Jeremy, I will check out those links.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I made a simplified version that lets you grab a family from a placed family instance and then place it. The script uses the face based overload, and it gives me a null reference for the ceiling face.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The Reference of the input face is null. If the face was obtained from Element.Geometry, make sure to turn on the option 'ComputeReferences'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Debugging, I can see that the face is not null, but it's Reference field is. Is this something that needs to be set? If any/all of this is answered in the article, feel free to let the link speak for itself.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;PRE&gt;public class SimplePlace : IExternalCommand
{

	public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
	{
		//Get application and document Objects
		UIApplication uiApp = commandData.Application;
		Document doc = uiApp.ActiveUIDocument.Document;

		using (Transaction transaction = new Transaction(doc))
		{
			if (transaction.Start("Place Sprinklers") == TransactionStatus.Started)
			{

				//Sprinkler Declarations
				XYZ referenceDirection = new XYZ(0, 0, 0);
				XYZ placePoint = null;
				Instance instance = null;

				//Define a Reference object to accept the room and ceiling selection results
				Selection sel = uiApp.ActiveUIDocument.Selection;

				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&amp;lt;Reference&amp;gt; faces = HostObjectUtils.GetBottomFaces(selectedCeiling);
				Element myFace = doc.GetElement(faces[0]);
				Face ceilingFace = (Face)myFace.GetGeometryObjectFromReference(faces[0]);

				Reference sprinklerRef = sel.PickObject(ObjectType.Element, "Please Select a family");
				FamilyInstance sprinklerInstance = doc.GetElement(sprinklerRef) as FamilyInstance;
				FamilySymbol activeSprinkler = sprinklerInstance.Symbol; 

				placePoint = sel.PickPoint("Please pick a point to place your family");

				//SPAWN Sprinklers
				if (!activeSprinkler.IsActive)
				{
					activeSprinkler.Activate();
					doc.Regenerate();

				}

				instance = doc.Create.NewFamilyInstance(ceilingFace, placePoint, referenceDirection, activeSprinkler);
				if (instance != null)
					return Result.Succeeded;
			}
			return Result.Failed;
		}
	}
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 17:22:09 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/doc-create-newfamilyinstance-creates-null/m-p/7743923#M52834</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-02-01T17:22:09Z</dc:date>
    </item>
    <item>
      <title>Re: doc.Create.NewFamilyInstance() creates null</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/doc-create-newfamilyinstance-creates-null/m-p/7752255#M52835</link>
      <description>&lt;P&gt;So I've read through the post, and I downloaded the building coder samples. I got the place new sprinkler command working, but I'm still having nulls appear when I run my own command. Some notable changes:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I changed the way I'm getting the ceiling face. I was using&amp;nbsp;HostObjectUtils.GetTopFaces() and then iterating through the results. This doesn't work because we can't get a valid host reference using this method. I'm now grabbing the object geometry with compute references on.&lt;/LI&gt;&lt;LI&gt;The ceiling only seems to have one face, and it points up. I'm not sure if that's the issue or not, can you host a sprinkler family on an upwards facing&amp;nbsp; ceiling?&lt;/LI&gt;&lt;LI&gt;The point is calculated using pickpoint and then projecting that point onto a face. It seems valid.&lt;/LI&gt;&lt;LI&gt;The family seems legitamate&lt;/LI&gt;&lt;LI&gt;My orientation is (0,0,0)&lt;/LI&gt;&lt;LI&gt;I changed the overload used so I'm referencing the face itself, not the face reference.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;After that I'm still getting nothing spawning. If it would give an error in the instance creation I could track it down, but with little feedback it's very frustrating.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm thinking about going through Jeremy's script, which works, and substituting parts of my implementation until something breaks. Other than that I'm not sure how&amp;nbsp;to know what I'm doing wrong at this point.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2018 16:26:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/doc-create-newfamilyinstance-creates-null/m-p/7752255#M52835</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-02-05T16:26:06Z</dc:date>
    </item>
    <item>
      <title>Re: doc.Create.NewFamilyInstance() creates null</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/doc-create-newfamilyinstance-creates-null/m-p/7752377#M52836</link>
      <description>&lt;P&gt;Just debugging again and I'm noticing that on the NewFamilyInstance call on the new instance/HostParameter I'm getting an exception that says the following "Only hosted instances whose family is not work plane based can support this functionality."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any insight would be appreciated. My family is work plane based family, as I thought all sprinklers were. Anyone have any experience with this issue?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2018 16:53:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/doc-create-newfamilyinstance-creates-null/m-p/7752377#M52836</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-02-05T16:53:28Z</dc:date>
    </item>
    <item>
      <title>Re: doc.Create.NewFamilyInstance() creates null</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/doc-create-newfamilyinstance-creates-null/m-p/7755865#M52837</link>
      <description>&lt;P&gt;I was able to solve the problem, but have a couple of follow up questions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Firstly, one of my issues was event handling. I had a try/catch situation which would return result succeeded in both branches, which I think hid the issue. Once I got rid of it I started getting a null reference on the face of my create new family instance call. On debugging the command again, I noticed that none of the faces in the ceiling were passing the normal test which checks to see if Normal.Z is &amp;lt; 0. Looking at the results of the get geometry, it only returned one face with a normal.Z of +1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not sure why a ceiling would be facing upwards (maybe I created it incorrectly?) but when I changed that&amp;nbsp;comparison I was finally able to spawn the family on the host face. Feels good! The sprinklers look like they're facing the correct direction, despite the face being the wrong way around. So for now, I'm happy.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 16:51:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/doc-create-newfamilyinstance-creates-null/m-p/7755865#M52837</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-02-06T16:51:50Z</dc:date>
    </item>
  </channel>
</rss>

