Place doors & windows

Hi,

 

I’m trying to place doors and windows in a wall, at a given level.

I’ve tried using Family.InstanceByPointAndLevel, but it doesn’t seem to work for doors or windows.

I’m guessing that I’d need to specify a wall host of the family with a python node. I have found the code below on the Github forum, for placing windows, but I’m having trouble getting it to work either.

Do you have any ideas how can I make it work?

I’m using Revit 2015 and Dynamo 0.7.2

# Default imports
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.DB import *
import Autodesk
import sys
import clr
path = r'C:\Autodesk\Dynamo\Core'
exec_path = r'C:\Autodesk\Dynamo\Core\dll'
sys.path.append(path)
sys.path.append(exec_path)
clr.AddReference('LibGNet')
from Autodesk.LibG import *

#The input to this node will be stored in the IN0...INX variable(s).
wall = IN0[0]
windowfamily = IN1
doc = IN2
uParam = 0.5
bottomToBottom = 3

locCurve = wall.Location
wallLength =  locCurve.Curve.Length

start = locCurve.Curve.get_EndPoint(0)
direction = locCurve.Curve.get_EndPoint(1) - start

location = start + direction.Normalize() * wallLength * uParam

#deletes the existing windows on the wall
elList = wall.FindInserts(True, False, False, False)
for elemId in elList:
    doc.Delete(elemId)

famInst = doc.Create.NewFamilyInstance(location, windowfamily, wall, wall.Level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
famInst.get_Parameter("Sill Height").Set(bottomToBottom);

#Assign your output to the OUT variable
OUT = famInst
1 Like

this code was written for .63, checkout this document: https://github.com/DynamoDS/Dynamo/wiki/Python-0.6.3-to-0.7.x-Migration

Thank you. I’ll give that a go.

Let me know if you have trouble converting…

Hi,

I was testing the Python’s Revit API features on Version 7.2 and modified this code a little bit to put more than one window on a wall. Bellow please find the Python script.

import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *

Import RevitAPI

clr.AddReference(“RevitAPI”)
import Autodesk

Import DocumentManager and TransactionManager

clr.AddReference(“RevitServices”)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

Import ToDSType(bool) extension method

clr.AddReference(“RevitNodes”)
import Revit
clr.ImportExtensions(Revit.Elements)

Unwrap

wall = UnwrapElement(IN[0])
windowfamily = UnwrapElement(IN[1])
uParams = IN[2] #a list of parameters between 0 and 1
SillHeight = IN[3]

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
TransactionManager.Instance.EnsureInTransaction(doc)

locCurve = wall.Location
wallLength = locCurve.Curve.Length<!–more–>

start = locCurve.Curve.get_EndPoint(0)
direction = locCurve.Curve.get_EndPoint(1) - start

#deletes the existing windows on the wall
elList = wall.FindInserts(True, False, False, False)
for elemId in elList:
doc.Delete(elemId)

for i in range (0, len(uParams)):
location = start + direction.Normalize() * wallLength * uParams[i]
famInst = doc.Create.NewFamilyInstance(location, windowfamily, wall, wall.Level, Autodesk.Revit.DB.Structure.StructuralType.NonStructural)
famInst.get_Parameter(“Sill Height”).Set(SillHeight)

End Transaction

TransactionManager.Instance.TransactionTaskDone()

 

hi mohammad, hi maciej!

read your posts, found out that mohammads solution is not valid for revit starting from 2014 release.

here is my code - based on mohammads. it is working with python 0.7x and revit 2014+

i changed the code so that

the input in IN[0] is a list of walls

the object ist placed in the middlepoint of the wall.

i removed the functionality of adding parameters as i didn’t understand the syntax mohammad had in mind.

regards peter

 

import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *

Import RevitAPI

clr.AddReference(‘RevitAPI’)
import Autodesk

Import DocumentManager and TransactionManager

clr.AddReference(‘RevitServices’)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

Import ToDSType(bool) extension method

clr.AddReference(‘RevitNodes’)
import Revit
clr.ImportExtensions(Revit.Elements)

walls = UnwrapElement(IN[0])
windowfamily = UnwrapElement(IN[1])
SillHeight = IN[2]

wall = []
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
TransactionManager.Instance.EnsureInTransaction(doc)

for i in range (0,len(walls)):

wall = walls[i]
#search for existing windows and delete
elList = wall.FindInserts(True, False, False, False)
for elemId in elList:
doc.Delete(elemId)

extract wall geometry and calculate middlepoint

locCurve = wall.Location
wallLength = locCurve.Curve.Length

start = locCurve.Curve.GetEndPoint(0)
end = locCurve.Curve.GetEndPoint(1)

mittex = (start.X + end.X)/2
mittey = (start.Y + end.Y)/2

location = Autodesk.Revit.DB.XYZ(mittex,mittey,start.Z)

famInst = doc.Create.NewFamilyInstance(location, windowfamily, wall, Autodesk.Revit.DB.Structure.StructuralType.NonStructural)
famInst.get_Parameter(‘Sill Height’).Set(SillHeight)

End Transaction

TransactionManager.Instance.TransactionTaskDone()

I know it’s a bit more work, but throwing this code on the package manager would be great :)… also you’ll be Dynamo famous.

Thanks Peter. I just migrated to 2015 and will try your code.

Michael, actually I was thinking about it. I may get some time during the weekend to create a general code and make a package for it.

@Michael and Mohammad

published the package “Place.Windows.Doors.InWalls”

you select a set of walls

you select a windows / door family type (actually the node should be working with other family types too)

you define the sill height. take care i am metric! in the python node the parameter IN[3] does the imperial - metric conversion.

 

published another package “Place.Element.InWalls”

with his package you should be able to place elements of a type in a list of walls.

insertion point is the midpoint of the wall

Wow!

I went off the grid for a few days and I didn’t anticipated so many responses. Thanks for all of these.

Peter, thanks for your hard work. I’ve just tried the code and it works great!

CADdesigner, I’ve found the original code in this thread https://github.com/DynamoDS/Dynamo/issues/1120

Kind Regards,

 

Maciej

 

Hi Peter,

I’m trying to use your packages to place windows in walls on multiple levels, but it seems that the code is working if all the walls are on the same level. I’ve tried “Place.Windows.Doors.InWalls” and “Place.Element.InWalls”. It looks like the window family ignores the Z value of the wall location curve and it’s placed on Z=0. I’ve tried to use the “Place.Windows.Doors.InWalls” Sill Height value to adjust the height, but I have a problem to make it work with list of heights.

Any ideas why it doesn’t work?

 

Kind Regards,

Maciej

Hi guys.
Can you help me to Unwrap WallType Material? i want to take a list of All materials of All Custom Walls in my project, thanks.

 

Hello, I have been attempting to get Peter’s node “Place.Elements.InWalls” to place a receptacle in a list of walls that I have selected. Before I completely disregard this node, I wanted to see if anyone else has had luck with it.Capture1

Hi Ethan,

If your family is hosted, you could also try the solution proposed here:

http://dynamobim.org/forums/topic/placing-windows/#post-38349