C# Revit API - Duplicate door not showing correctly.

C# Revit API - Duplicate door not showing correctly.

Maltezc
Advocate Advocate
1,137 Views
2 Replies
Message 1 of 3

C# Revit API - Duplicate door not showing correctly.

Maltezc
Advocate
Advocate

Hi all, I'm trying to duplicate a door type and then place the new door type on a wall however, when it is placed, the door shows as if it is not hosted correctly and there is no break in the wall. The original door type shows up correctly.

 

I am using the .Duplicate() method to create a new type and then creating a new instance.

 

Does anyone know how I can resolve this? I haven't found anything online on how to resolve the issue yet.

 

image of what it looks like. Screen Shot 2020-09-16 at 7.44.43 PM.png

here is my code: 

 

[Transaction(TransactionMode.Manual)]
    public class Command : IExternalCommand
    {
        public Result Execute(
          ExternalCommandData commandData,
          ref string message,
          ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument uidoc = uiapp.ActiveUIDocument;
            Application app = uiapp.Application;
            Document doc = uidoc.Document;


            FilteredElementCollector colDoors = new FilteredElementCollector(doc)
                .OfCategory(BuiltInCategory.OST_Doors);

            FamilySymbol door = colDoors.First() as FamilySymbol;

            // Build a location line for the wall creation
            XYZ start = new XYZ(-10, 0, 0);
            XYZ end = new XYZ(20, 0, 0);
            
            Line geomLine = Line.CreateBound(start, end);

            XYZ duplicateDoorLocation = new XYZ(-5, 0, 0);
            XYZ doorLocation = new XYZ(5, 0, 0);
            

            // grab levels in project
            FilteredElementCollector colLevels
                = new FilteredElementCollector(doc)
                .WhereElementIsNotElementType()
                .OfCategory(BuiltInCategory.INVALID)
                .OfClass(typeof(Level));

            Level firstLevel = colLevels.First() as Level;

            // Modify document within a transaction
            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("Transaction Name");


                if (firstLevel.ProjectElevation == 0)
                {
                    // Create a wall using the location line
                    Wall newWall = Wall.Create(doc, geomLine, firstLevel.Id, true);


                    if (!door.IsActive)
                    {
                        // Ensure the family symbol is activated.
                        door.Activate();
                        doc.Regenerate();
                    }

                    // original door
                    FamilyInstance doorInstance = doc.Create.NewFamilyInstance(doorLocation, door, newWall, StructuralType.NonStructural);
                    FamilySymbol doorFamilySymbol = doorInstance.Symbol;
                    doorFamilySymbol.get_Parameter(BuiltInParameter.DOOR_WIDTH).Set(3.3);

                    // duplicate door
                    FamilySymbol duplicatedoorFamilySymbol = doorFamilySymbol.Duplicate("duplicated Door") as FamilySymbol;

                    if (!duplicatedoorFamilySymbol.IsActive)
                    {
                        // Ensure the family symbol is activated.
                        door.Activate();
                        doc.Regenerate();
                    }
                    FamilyInstance duplicateDoorInstance = doc.Create.NewFamilyInstance(duplicateDoorLocation, duplicatedoorFamilySymbol, newWall, firstLevel, StructuralType.NonStructural);
                    
                }

                tx.Commit();
            }

            return Result.Succeeded;
        }
    }

 

 

0 Likes
Accepted solutions (1)
1,138 Views
2 Replies
Replies (2)
Message 2 of 3

naveen.kumar.t
Autodesk Support
Autodesk Support
Accepted solution

Hi @Maltezc ,

After creating the duplicate door instance,Use doc. Regenerate();

I think this will solve your issue.

Check out this below link

https://forums.autodesk.com/t5/revit-api-forum/create-doors-but-not-cutting-through-wall/td-p/556433... 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 3

Maltezc
Advocate
Advocate

that did it. thanks! 

 

I had to add in another filpface and doc.regenerate() for a total of 3. Its a bit odd. but it works.

0 Likes