<?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: having trouble programmatically placing doors and windows in walls, via an a in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6325653#M65632</link>
    <description>&lt;P&gt;Oh, how unfortunate and confusing! &amp;nbsp;Here's a quick way to get Ids of all door family symbols.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace Revit.Examples
{
    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    public class TestCommand : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            var collector = new FilteredElementCollector(commandData.Application.ActiveUIDocument.Document);

            var doorFamilySymbolIds = collector.
                OfClass(typeof (FamilySymbol)).
                OfCategory(BuiltInCategory.OST_Doors).
                ToElementIds();

            return Result.Succeeded;
        }
    }
}&lt;/PRE&gt;</description>
    <pubDate>Fri, 13 May 2016 18:36:51 GMT</pubDate>
    <dc:creator>BobbyC.Jones</dc:creator>
    <dc:date>2016-05-13T18:36:51Z</dc:date>
    <item>
      <title>having trouble programmatically placing doors and windows in walls, via an addin</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6325377#M65628</link>
      <description>&lt;P&gt;I am attemtping to programmatically place walls, and then place doors and windows in those walls.&lt;/P&gt;&lt;P&gt;I am getting confused about how to generate a FamilySymbol for a door.&amp;nbsp; I am assuming that window insertion into walls is similar in technique.&lt;/P&gt;&lt;P&gt;code is below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.DB;
using Autodesk.Revit.Creation;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;

[TransactionAttribute( TransactionMode.Manual )]
[RegenerationAttribute( RegenerationOption.Manual )]
public class RevitDataPlugin : IExternalCommand {
    public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements ) {
        //Get application and document objects
        UIApplication uiApp = commandData.Application;
        var doc = uiApp.ActiveUIDocument.Document;

        using ( Transaction trans = new Transaction( doc ) ) {
            trans.Start( "WallDataParser" );

            Level level = Level.Create( doc, 0.0 );
            XYZ start = new XYZ( 0.0, 0.0, 0.0 );
            XYZ end = new XYZ( 10.0, 0.0, 0.0 );
            Line wallLine = Line.CreateBound( start, end );
            Wall wall = Wall.Create( doc, wallLine as Line, level.Id, true );

            XYZ doorPoint = new XYZ( 5.0 , 0.0, 0.0 );

            ElementId doorCategoryId = new ElementId( BuiltInCategory.OST_Doors );
          
            FamilySymbol doorSymbol = null; // TODO: how?

            doc.Create.NewFamilyInstance( doorPoint, doorSymbol, wall, Autodesk.Revit.DB.Structure.StructuralType.NonStru​ctural );

            doc.Regenerate();

            trans.Commit();
        }

        return Result.Succeeded;
    }
}

&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 May 2016 16:07:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6325377#M65628</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-05-13T16:07:45Z</dc:date>
    </item>
    <item>
      <title>Re: having trouble programmatically placing doors and windows in walls, via an a</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6325473#M65629</link>
      <description>&lt;P&gt;Are you familiar with the concept of the FilteredElementCollector? &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2016 16:49:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6325473#M65629</guid>
      <dc:creator>BobbyC.Jones</dc:creator>
      <dc:date>2016-05-13T16:49:35Z</dc:date>
    </item>
    <item>
      <title>Re: having trouble programmatically placing doors and windows in walls, via an a</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6325618#M65630</link>
      <description>&lt;P&gt;I was&amp;nbsp;not, but I think I understand it's use now. the following code is what I have come up with so far, however it fails with a symbol not active.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using System;
using System.Collections.Generic;
//using System.IO;
//using System.Linq;

using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.Creation;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;

[TransactionAttribute( TransactionMode.Manual )]
[RegenerationAttribute( RegenerationOption.Manual )]
public class RevitDataPlugin : IExternalCommand {
    private List&amp;lt;FamilySymbol&amp;gt; doorFamilies = new List&amp;lt;FamilySymbol&amp;gt;();

    public Result Execute( ExternalCommandData commandData, ref string message, ElementSet elements ) {
        //Get application and document objects
        UIApplication uiApp = commandData.Application;
        var doc = uiApp.ActiveUIDocument.Document;

        using ( Transaction trans = new Transaction( doc ) ) {
            trans.Start( "WallDataParser" );

            PrepareDoorFamilies( commandData );

            Level level = Level.Create( doc, 0.0 );
            XYZ start = new XYZ( 0.0, 0.0, 0.0 );
            XYZ end = new XYZ( 10.0, 0.0, 0.0 );
            Line wallLine = Line.CreateBound( start, end );
            Wall wall = Wall.Create( doc, wallLine as Line, level.Id, false );

            XYZ doorPoint = new XYZ( 5.0 , 0.0, 0.0 );

            ElementId doorCategoryId = new ElementId( BuiltInCategory.OST_Doors );
            //Opening opening = wall.Document.Create.NewOpening( wall, pntStart, pntEnd );

            FamilySymbol doorSymbol = doorFamilies[0]; // TODO: how?

            doc.Create.NewFamilyInstance( doorPoint, doorSymbol, wall, Autodesk.Revit.DB.Structure.StructuralType.NonStru​ctural );

            doc.Regenerate();

            trans.Commit();
        }

        return Result.Succeeded;
    }

    private void PrepareDoorFamilies( ExternalCommandData commandData ) {
        UIApplication uiApp = commandData.Application;
        var doc = uiApp.ActiveUIDocument.Document;

        // prepare families
        FilteredElementIterator familyIter = new FilteredElementCollector( doc ).OfClass( typeof( Family ) ).GetElementIterator();

        while ( familyIter.MoveNext() ) {

            Family doorFamily = familyIter.Current as Family;

            if ( null == doorFamily.FamilyCategory ) { // some family.FamilyCategory is null
                continue;
            }

            if ( doorFamily.FamilyCategory.Name != doc.Settings.Categories.get_Item( BuiltInCategory.OST_Doors ).Name ) { // FamilyCategory.Name is not 'Doors'
                continue;
            }

            foreach ( ElementId elementId in doorFamily.GetFamilySymbolIds() ) {
                // store the created family
                doorFamilies.Add( ( FamilySymbol )( doc.GetElement( elementId ) ) );
            }

        }
    }
}

&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 May 2016 18:12:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6325618#M65630</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-05-13T18:12:05Z</dc:date>
    </item>
    <item>
      <title>Re: having trouble programmatically placing doors and windows in walls, via an a</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6325621#M65631</link>
      <description>mind you a good but of the code in PrepareDoorFamilies was pulled from the demos of the api</description>
      <pubDate>Fri, 13 May 2016 18:13:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6325621#M65631</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-05-13T18:13:35Z</dc:date>
    </item>
    <item>
      <title>Re: having trouble programmatically placing doors and windows in walls, via an a</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6325653#M65632</link>
      <description>&lt;P&gt;Oh, how unfortunate and confusing! &amp;nbsp;Here's a quick way to get Ids of all door family symbols.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace Revit.Examples
{
    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    public class TestCommand : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            var collector = new FilteredElementCollector(commandData.Application.ActiveUIDocument.Document);

            var doorFamilySymbolIds = collector.
                OfClass(typeof (FamilySymbol)).
                OfCategory(BuiltInCategory.OST_Doors).
                ToElementIds();

            return Result.Succeeded;
        }
    }
}&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 May 2016 18:36:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6325653#M65632</guid>
      <dc:creator>BobbyC.Jones</dc:creator>
      <dc:date>2016-05-13T18:36:51Z</dc:date>
    </item>
    <item>
      <title>Re: having trouble programmatically placing doors and windows in walls, via an a</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6325672#M65633</link>
      <description>&lt;P&gt;but of course, after reading a little closer, you don't give a crap about family symbol Ids, and you need to keep from crashing with the symbol not active exception.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using System.Linq;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace DWH.Revit.Schedules.Commands
{
    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    public class TestCommand : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            var collector = new FilteredElementCollector(commandData.Application.ActiveUIDocument.Document);

            var doorFamilySymbols = collector.
                OfClass(typeof (FamilySymbol)).
                OfCategory(BuiltInCategory.OST_Doors).
                OfType&amp;lt;FamilySymbol&amp;gt;();

            var firstDoorSymbol = doorFamilySymbols.FirstOrDefault();

            if (firstDoorSymbol == null)
            {
                message = "No door families loaded.";

                return Result.Failed;
            }

            if (!firstDoorSymbol.IsActive)
            {
                firstDoorSymbol.Activate();
            }

            //Do your thing with the door symbol.

            return Result.Succeeded;
        }
    }
}&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 May 2016 18:51:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6325672#M65633</guid>
      <dc:creator>BobbyC.Jones</dc:creator>
      <dc:date>2016-05-13T18:51:19Z</dc:date>
    </item>
    <item>
      <title>Re: having trouble programmatically placing doors and windows in walls, via an a</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6325706#M65634</link>
      <description>&lt;P&gt;thanks! this little project is my first real foray into C#, so it's been a bit rough, though I have been learning a lot! much appreciated!&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2016 19:00:36 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6325706#M65634</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-05-13T19:00:36Z</dc:date>
    </item>
    <item>
      <title>Re: having trouble programmatically placing doors and windows in walls, via an a</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6325741#M65635</link>
      <description>I thought it might be and I despise those examples that obfuscate the use of the Revit API in unnecessary language constructs. I'm glad I could help and I hope things are a little clearer. Scour the SDK docs and the www to learn all you can about Filters and the FilteredElementCollector; you'll use them a lot. Good luck and come back when you get stuck!</description>
      <pubDate>Fri, 13 May 2016 19:16:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6325741#M65635</guid>
      <dc:creator>BobbyC.Jones</dc:creator>
      <dc:date>2016-05-13T19:16:56Z</dc:date>
    </item>
    <item>
      <title>Re: having trouble programmatically placing doors and windows in walls, via an a</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6325754#M65636</link>
      <description>&lt;P&gt;though I do have one issuse with your solution: all doors are null! instead of&lt;/P&gt;&lt;PRE&gt;FamilySymbol doorSymbol = doorFamilySymbols.FirstOrDefault();&lt;/PRE&gt;&lt;P&gt;I replaced it with&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;FamilySymbol doorSymbol = null, window = null;
foreach ( FamilySymbol door in doorFamilySymbols ) {
    if ( door == null ) {
        continue;
    } else {
        doorSymbol = door ;

        if ( !doorSymbol.IsActive ) {
            doorSymbol.Activate();
        }

        break;
     }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;but the null-ness persists!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2016 19:22:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6325754#M65636</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-05-13T19:22:07Z</dc:date>
    </item>
    <item>
      <title>Re: having trouble programmatically placing doors and windows in walls, via an a</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6326010#M65637</link>
      <description>Does your project have any door families loaded?</description>
      <pubDate>Fri, 13 May 2016 21:51:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6326010#M65637</guid>
      <dc:creator>BobbyC.Jones</dc:creator>
      <dc:date>2016-05-13T21:51:43Z</dc:date>
    </item>
    <item>
      <title>Re: having trouble programmatically placing doors and windows in walls, via an a</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6326062#M65638</link>
      <description>&lt;P&gt;no I do not, how would I do so?&lt;/P&gt;</description>
      <pubDate>Fri, 13 May 2016 22:50:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6326062#M65638</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-05-13T22:50:51Z</dc:date>
    </item>
    <item>
      <title>Re: having trouble programmatically placing doors and windows in walls, via an a</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6328406#M65639</link>
      <description>&lt;P&gt;no it doesn't I'm trying to place one &lt;span class="lia-unicode-emoji" title=":face_with_tongue:"&gt;😛&lt;/span&gt; how would I load it? using loadFamily?&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2016 14:41:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6328406#M65639</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-05-16T14:41:44Z</dc:date>
    </item>
    <item>
      <title>Re: having trouble programmatically placing doors and windows in walls, via an a</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6328848#M65640</link>
      <description>Yes, if the family you want isn't loaded, then LoadFamily will load it. Also note that LoadFamily provides you a Family object which has a very convenient GetFamilySymbolIds() method.</description>
      <pubDate>Mon, 16 May 2016 18:16:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6328848#M65640</guid>
      <dc:creator>BobbyC.Jones</dc:creator>
      <dc:date>2016-05-16T18:16:44Z</dc:date>
    </item>
    <item>
      <title>Re: having trouble programmatically placing doors and windows in walls, via an a</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6328857#M65641</link>
      <description>And alternatively, if you only want to load a single type instead of them all, you can use LoadFamilySymbol().</description>
      <pubDate>Mon, 16 May 2016 18:20:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6328857#M65641</guid>
      <dc:creator>BobbyC.Jones</dc:creator>
      <dc:date>2016-05-16T18:20:44Z</dc:date>
    </item>
    <item>
      <title>Re: having trouble programmatically placing doors and windows in walls, via an a</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6328948#M65642</link>
      <description>&lt;P&gt;any ideas on how to load the default families in the arch-template? I cannot find them in the filesystem, so i assume they are in the document itself.&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2016 19:03:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6328948#M65642</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-05-16T19:03:47Z</dc:date>
    </item>
    <item>
      <title>Re: having trouble programmatically placing doors and windows in walls, via an a</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6329270#M65643</link>
      <description>&lt;P&gt;Well, two things come to mind immediately. First, you can right click on the Families node in the Project Browser and save families from inside a project to individual .rfa family files, or right click on any single non-system family to save a single file. Second, if you're **** bent on doing all via code, you could look into the ElementTransformUtils.CopyElements() method to copy families from one project to another.&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2016 22:04:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/having-trouble-programmatically-placing-doors-and-windows-in/m-p/6329270#M65643</guid>
      <dc:creator>BobbyC.Jones</dc:creator>
      <dc:date>2016-05-16T22:04:48Z</dc:date>
    </item>
  </channel>
</rss>

