I am off in the mountains again today, after a long break due to bad weather and too many other activities.
Meanwhile, here is a pretty old item that has been hanging around in my to-do list for much too long, so let's get it out there to you:
Question: How can I programmatically create a masked region?
Answer: I am sorry to say you currently cannot.
Hoewever, one of the API features added in Revit 2013 was the abiility to create a filled region.
The FilledRegion class was extended to offer the ability to create a new filled region, get its boundaries, and apply a linestyle to all its boundary segments.
So, while there is no straightforward method to create a mask region, the closest we can get is by creating a filled region using the FilledRegion.Create method. However, a filled region is not the same object as a mask region. A filled region has a fill pattern, and its type can be changed. The mask region type cannot be changed. If you set a filled region's fill pattern to a solid blank pattern, it will look like a mask region.
Here is a sample code fragment showing how to create a FilledRegion object:
FilteredElementCollector fillRegionTypes = new FilteredElementCollector( doc ) .OfClass( typeof( FilledRegionType ) ); IEnumerable<FilledRegionType> myPatterns = from pattern in fillRegionTypes.Cast<FilledRegionType>() where pattern.Name.Equals( "Diagonal Crosshatch" ) select pattern; foreach( FilledRegionType frt in fillRegionTypes ) { List<CurveLoop> profileloops = new List<CurveLoop>(); XYZ[] points = new XYZ[5]; points[0] = new XYZ( 0.0, 0.0, 0.0 ); points[1] = new XYZ( 10.0, 0.0, 0.0 ); points[2] = new XYZ( 10.0, 10.0, 0.0 ); points[3] = new XYZ( 0.0, 10.0, 0.0 ); points[4] = new XYZ( 0.0, 0.0, 0.0 ); CurveLoop profileloop = new CurveLoop(); for( int i = 0; i < 4; i++ ) { Line line = Line.CreateBound( points[i], points[i + 1] ); profileloop.Append( line ); } profileloops.Add( profileloop ); ElementId activeViewId = doc.ActiveView.Id; FilledRegion filledRegion = FilledRegion.Create( doc, frt.Id, activeViewId, profileloops ); break; }
You could simulate the creation of a mask region by modifying this to find a filled region type whose fill pattern is blank.
This line is not working with revit 2014 ,Do you have any suggestion to solve this ?
Cheers,
Posted by: Ahmed | February 15, 2014 at 12:21
Dear Ahmed,
Not really. My only suggestion to start off with would be to specify what line you mean, and the exact behaviour that you observe.
Cheers, Jeremy.
Posted by: Jeremy Tammik | February 18, 2014 at 06:42
Really thanks for replying :) ,
The problem coming from this 5th line above :
from pattern in fillRegionTypes.Cast()
The error is :
'Autodesk.Revit.DB.FilteredElementCollector' does not contain a definition for 'Cast' and no extension method 'Cast' accepting a first argument of type 'Autodesk.Revit.DB.FilteredElementCollector' could be found (are you missing a using directive or an assembly reference?) C:\Users\Ahmad\documents\visual studio 2013\Projects\Create Fill pattern\Create Fill pattern\Command.cs 37 49 Create Fill pattern
Posted by: Ahmed | February 19, 2014 at 13:58
Also How I can add transparency assuming to solid black for grey scale purpose because all I knew is this :
OverrideGraphicSettings ogs = new OverrideGraphicSettings();
ogs.SetSurfaceTransparency(80);
How I can make it reflect on above filled region to be 80% along with the created filled region ?
Thanks
Posted by: Ahmed | February 19, 2014 at 16:04
Dear Ahmed,
You seem to be lacking the Linq namespace.
Add the following line at the top of the module:
using System.Linq;
Cheers, Jeremy.
Posted by: Jeremy Tammik | February 21, 2014 at 04:45
Dear Ahmed,
This is basically all I know about transparency:
http://thebuildingcoder.typepad.com/blog/2012/07/obj-model-exporter-with-transparency-support.html
Cheers, Jeremy.
Posted by: Jeremy Tammik | February 21, 2014 at 04:49
Could you use this technique to change a filled region to an area boundary? Using revit conventionally (copy and paste) it seems you can't make the transition between the 2, revit takes your boundary from your filled region and converts it to lines in the area plan.
Posted by: Ryan | March 17, 2014 at 20:14
Jeremy,
Is there any way to determine the line styles used for the boundary lines in a filled region? Or better yet, is there an easier way to manipulate these line styles within a filled region (other than deleting and recreating the filled region)?
Posted by: Nick Kovach | September 05, 2014 at 11:41