Revit API

Reply
Active Contributor
grahamcook
Posts: 42
Registered: ‎06-18-2012
Message 1 of 6 (495 Views)
Accepted Solution

Create Mass From Room

495 Views, 5 Replies
10-25-2012 01:02 PM

Hi

I'm a bit out of my comfort zone here.  I am creating an addin which involves creating a mass for each instance of room.  I cobbled together the code below from examples on other blogs / sites (mostly here).  This works but only if the room hasn't got any internal boundaries (holes, islands, etc).  If a room has an internal boundary the actual NewExtrution line fails with the error "One of the conditions for the inputs was not satisfied. Consult the documentation for requirements for each argument.".  I'm guessing this is because the profile array has more than one profile (like internal boundaries in this case).  The boundaries don't overlap though, just some are entirely consumed by others.

 

Anyone know of a better approach here?  Or how to amend the code below to deal with the internal boundaries (holes) in the room?

 

// Create family doc from template
Autodesk.Revit.DB.Document familyDoc = app.NewFamilyDocument(@"C:\ProgramData\Autodesk\RVT 2013\Family Templates\English\Metric Generic Model.rft");

// Save the new Family - room is Room Element not defined in this sample code
string fileName = @"C:\Temp\" + room.UniqueId.ToString() + ".rfa";
familyDoc.SaveAs(fileName);

Transaction transaction = new Transaction(familyDoc, "RoomToMass");
transaction.Start();

// Get the room boundary
SpatialElementBoundaryOptions opt = new SpatialElementBoundaryOptions();

IList<IList<Autodesk.Revit.DB.BoundarySegment>> segArray = room.GetBoundarySegments(opt);

CurveArray curveArray = new CurveArray();

// Iterate to gather the curve objects
foreach (IList<Autodesk.Revit.DB.BoundarySegment> bSegments in segArray)
{
    foreach (Autodesk.Revit.DB.BoundarySegment bSegment in bSegments)
    {
        curveArray.Append(bSegment.Curve);
    }
}

// Origin point and normal point that gives the extrusion direction
XYZ ptOrigin = new XYZ(0, 0, 0);
XYZ ptNormal = new XYZ(0, 0, 1);

// The plane to extrude the mass from
Plane plane = app.Create.NewPlane(ptNormal, ptOrigin);
SketchPlane sketchPlane = familyDoc.FamilyCreate.NewSketchPlane(plane);

// Add the CurveArray to a CurveArrArray
CurveArrArray curveArrArray = new CurveArrArray();
curveArrArray.Append(curveArray);

// Extrude the form 10 feet as test
Extrusion extrusion = familyDoc.FamilyCreate.NewExtrusion(true, curveArrArray, sketchPlane, 10);

transaction.Commit();

familyDoc.Save();

// now need to place the family...

 

Employee
saikat
Posts: 185
Registered: ‎08-16-2007
Message 2 of 6 (493 Views)

Re: Create Mass From Room

10-25-2012 02:01 PM in reply to: grahamcook

Hello Graham

 

Is it an option to create new model lines that outline the outer periphery/shell of the room using the room's boundary segments (instead of directly using the curves of the room boundary segments) and then use this set of curves in a curvearray to create the mass element.

 

cheers

 

 



Saikat Bhattacharya

Active Contributor
grahamcook
Posts: 42
Registered: ‎06-18-2012
Message 3 of 6 (490 Views)

Re: Create Mass From Room

10-25-2012 02:27 PM in reply to: saikat

Saikat

 

Thanks for looking at my post.

Yes that would be an option i could look at.  If i knew how to just get the boundary of the OUTER edge only - ignoring all the inner boundaries.  Any Pointers?

 

Cheers

 

Graham

Employee
saikat
Posts: 185
Registered: ‎08-16-2007
Message 4 of 6 (482 Views)

Re: Create Mass From Room

10-26-2012 01:19 PM in reply to: grahamcook

Hello Graham

 

Would an approach similar to what is being discussed here be of help/use:

http://thebuildingcoder.typepad.com/blog/2008/12/2d-polygon-areas-and-outer-loop.html

 

Do let us know if this worked out or not. Or if you found any other approach, better still.

 

cheers



Saikat Bhattacharya

Active Contributor
grahamcook
Posts: 42
Registered: ‎06-18-2012
Message 5 of 6 (469 Views)

Re: Create Mass From Room

10-28-2012 12:27 PM in reply to: saikat

Thank you Saikat.  In this case i went with assuming the first segment set in the collection was the outer boundary and inserted a break in the first foreach loop to force a break after first loop.  I've tested on hundreds of rooms and the first segment set has always been the outer edge (so far).  I would like to eventually include holes within the mass but for this particular problem just the outer edge will suffice.

 

Cheers

 

Graham

Employee
saikat
Posts: 185
Registered: ‎08-16-2007
Message 6 of 6 (461 Views)

Re: Create Mass From Room

10-29-2012 10:58 AM in reply to: grahamcook

Great! Thanks for the update.

 

kind regards



Saikat Bhattacharya

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.