Re: Create Filled Regions

410 views
Skip to first unread message

Daren Thomas

unread,
Aug 24, 2012, 3:28:38 AM8/24/12
to revitpyt...@googlegroups.com
Erick,

Can you post a sample of the code you're trying?

Regards,
Daren

On Friday, August 24, 2012 2:40:14 AM UTC+2, Erick Katzenstein wrote:
Daren,

Thanks for updating the Revit 2013 RPS.  It wasn't working for me yesterday but is working well today.  

Regarding the new release, you mentioned that you weren't sure if it supported new Revit commands.  Are you aware of its ability to run the FilledRegion.Create() syntax?  I'm new to the Revit API so I'm not sure if the problem is with the Beta version or my incompetence :D

Erick Katzenstein

unread,
Aug 24, 2012, 3:51:40 AM8/24/12
to revitpyt...@googlegroups.com
Right now, I'm trying to create a filled region square while in an elevation view (from the right side). The code is at the bottom...I'm getting snagged on some of the parameters:

The RevitAPI.chm file lists these as the parameters for FilledRegion.Create:

document
Type: Autodesk.Revit.DB..::..Document
The document in which to create the filled region.

typeId
Type: Autodesk.Revit.DB..::..ElementId
The filled region type Id.

viewId
Type: Autodesk.Revit.DB..::..ElementId
The view Id.

boundaries
Type: System.Collections.Generic..::..IList<(Of <(<'CurveLoop>)>)>
The boundaries. 

I think I have the active document figured out, and maybe the boundaries and viewID, but the getTypeID is what I'm having trouble with (how to retrieve the TypeId from a filled region).  I'll figure this out soon, but I just wanted to check and see if the FilledRegion.Create works with the Beta version before going further.  Thanks for any help.

Erick





import clr
import math
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.DB import *

doc = __revit__.ActiveUIDocument.Document
app = __revit__.Application

t = Transaction(doc, 'Create FilledRegion')

t.Start()
collector = FilteredElementCollector(doc)
collector.OfCategory(BuiltInCategory.OST_FilledRegion)
 
famtypeitr = collector.GetElementIdIterator()
famtypeitr.Reset()
 
for item in famtypeitr:
    typeID = item
    srfObj = doc.get_Element(typeID)
#Create a sketch plane
origin = XYZ.Zero
normal = XYZ.BasisX 

plane = app.Create.NewPlane(normal, origin)
skplane = doc.Create.NewSketchPlane(plane)

for i in range (0,4):
    xp=0,0,0,0,0
    yp=0,0,10,10,0
    zp=0,10,10,0,0
    x=xp[i]
    y=yp[i]
    z=zp[i]
    a=xp[i+1]
    b=yp[i+1]
    c=zp[i+1]

    #Create line vertices
    lnStart = XYZ(x,y,z)
    lnEnd = XYZ(a,b,c)
    
    #create NewLine()
    line = app.Create.NewLine(lnStart, lnEnd, True)
    
    #create NewModelCurve()
    crv = doc.Create.NewModelCurve(line, skplane)
    activeViewId = doc.ActiveView.Id
    FilledRegion.Create(doc, ???, activeViewId, crv)
t.Commit() 

Daren Thomas

unread,
Aug 24, 2012, 5:07:08 AM8/24/12
to revitpyt...@googlegroups.com
If you have a filled region type in your document, you can obtain it's
typeid like this:

collector = FilteredElementCollector(doc).OfClass(FilledRegionType)
filledRegionType = list(collector)[0] # get the first
typeId = filledRegionType.Id

Does that help?

The RevitPythonShell only exposes the API - being beta doesn't mean
the new features aren't available for scripting, it just means I
haven't got around to enhancing the interface (Ribbon etc.) to make
use of the new features.

Regards,
Daren

On Fri, Aug 24, 2012 at 9:51 AM, Erick Katzenstein
<erick.ka...@gmail.com> wrote:
> Right now, I'm trying to create a filled region square while in an elevation
> view (from the right side). The code is at the bottom...I'm getting snagged
> on some of the parameters:
>
> The RevitAPI.chm file lists these as the parameters for FilledRegion.Create:
>
> document Type: Autodesk.Revit.DB..::..Document
> The document in which to create the filled region.
> typeIdType: Autodesk.Revit.DB..::..ElementId
> The filled region type Id.
> viewIdType: Autodesk.Revit.DB..::..ElementId
> The view Id.
> boundariesType: System.Collections.Generic..::..IList<(Of <(<'CurveLoop>)>)>
Message has been deleted

Erick Katzenstein

unread,
Aug 24, 2012, 12:27:04 PM8/24/12
to revitpyt...@googlegroups.com
Thanks for your help and the quick response.  I'm getting this error now with the updated code:

Traceback (most recent call last):
  File "<string>", line 48in <module>
Exception: The boundaries collection contains open loops.
Parameter name: boundaries
>>> 

When the model lines are drawn, it creates a closed loop, but the boundaries are not reading as a closed loop.  Any ideas?

import clr
import math
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.DB import *

doc = __revit__.ActiveUIDocument.Document
app = __revit__.Application

t = Transaction(doc, 'Create FilledRegion')

t.Start()
collector = FilteredElementCollector(doc).OfClass(FilledRegionType) 

filledRegionType = list(collector)[0# get the first 
typeId = filledRegionType.Id 


#Create a sketch plane
origin = XYZ.Zero
normal = XYZ.BasisX 

plane = app.Create.NewPlane(normal, origin)
skplane = doc.Create.NewSketchPlane(plane)

for i in range (0,4):
    xp=0,0,0,0,0
    yp=0,0,10,10,0
    zp=0,10,10,0,0
    x=xp[i]
    y=yp[i]
    z=zp[i]
    a=xp[i+1]
    b=yp[i+1]
    c=zp[i+1]
    
    #Create line vertices
    lnStart = XYZ(x,y,z)
    lnEnd = XYZ(a,b,c)
    
    #create NewLine()
    line = app.Create.NewLine(lnStart, lnEnd, True)
    profile=CurveLoop()
    profile.Append(line)
    profiles=[]
    profiles.Add(profile)
    
activeViewId = doc.ActiveView.Id
FilledRegion.Create(doc, typeId, activeViewId, profiles)
t.Commit() 

Daren Thomas

unread,
Aug 27, 2012, 2:40:04 AM8/27/12
to revitpyt...@googlegroups.com
Your problem might be in the "profiles=[]" line - That resets your
list of boundaries (profiles) before each adding a boundary (profile)
in your loop. Try moving that line to before the for loop...

Regards,
Daren

Erick Katzenstein

unread,
Aug 27, 2012, 3:19:18 AM8/27/12
to revitpyt...@googlegroups.com
Brilliant.  Thanks so much for your help.

Erick Katzenstein

unread,
Sep 6, 2012, 7:56:47 PM9/6/12
to revitpyt...@googlegroups.com
Thanks again Daren.  Here's a post of the progress:  http://lmnts.lmnarchitects.com/featured/filled-regions-for-thermal-assemblies/ 

Daren Thomas

unread,
Sep 7, 2012, 9:20:48 AM9/7/12
to revitpyt...@googlegroups.com
hey erick,

thank you for mentioning my work :D

also, i'm sure we all agree that nathan miller rocks!

regards,
daren

Erick Katzenstein

unread,
Sep 7, 2012, 9:40:00 PM9/7/12
to revitpyt...@googlegroups.com
agreed!
Reply all
Reply to author
Forward
0 new messages