本文整理汇总了C#中FilteredElementCollector.Count方法的典型用法代码示例。如果您正苦于以下问题:C# FilteredElementCollector.Count方法的具体用法?C# FilteredElementCollector.Count怎么用?C# FilteredElementCollector.Count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FilteredElementCollector
的用法示例。
在下文中一共展示了FilteredElementCollector.Count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: deleteLinePatterns
public void deleteLinePatterns(Document doc)
{
var collector = new FilteredElementCollector(doc)
.OfClass(typeof(LinePatternElement)).Where(i => i.Name.StartsWith("IMPORT")).ToList();
List<ElementId> ids = new List<ElementId>();
for (int i = 0; i < collector.Count(); i++)
{
ids.Add(collector[i].Id);
}
using (Transaction t = new Transaction(doc, "Remove Pattern"))
{
t.Start();
try
{
doc.Delete(ids);
}
catch (Exception)
{
t.RollBack();
return;
}
t.Commit();
}
}
示例2: DFS
private static int DFS(IList<ElementId> columnIds, IList<ElementId> beamIds, out int num_IndividualColumn)
{
num_IndividualColumn = 0;
List<Element> columns = (new FilteredElementCollector(_doc, columnIds)).OfClass(typeof(FamilyInstance)).ToList();
List<Element> beams = (new FilteredElementCollector(_doc, beamIds)).OfClass(typeof(FamilyInstance)).ToList();
int k = 0;
LinkedList<Element> open = new LinkedList<Element>();
HashSet<ElementId> discovered = new HashSet<ElementId>();
foreach(Element column in columns)
{
if (!discovered.Contains(column.Id))
{
++k;
open.AddFirst(column);
discovered.Add(column.Id);
while (open.Count != 0)
{
Element e = open.First();
open.RemoveFirst();
BoundingBoxXYZ bbXYZ = e.get_BoundingBox(_doc.ActiveView);
XYZ deltaXYZ = new XYZ(ErrorCTRL_BB, ErrorCTRL_BB, _maxBB.Max.Z);
BoundingBoxIntersectsFilter bbFilter = new BoundingBoxIntersectsFilter(new Outline(bbXYZ.Min - deltaXYZ, bbXYZ.Max + deltaXYZ));
FilteredElementCollector fec = null;
if (((FamilyInstance)e).StructuralUsage == StructuralInstanceUsage.Column)
{
fec = new FilteredElementCollector(_doc, beamIds);
fec.WherePasses(bbFilter);
if (fec.Count() == 0)
{
++num_IndividualColumn;
--k;
}
}
else
{
fec = new FilteredElementCollector(_doc, columnIds);
fec.WherePasses(bbFilter);
}
foreach (Element intersectedEle in fec)
{
if (!discovered.Contains(intersectedEle.Id))
{
open.AddFirst(intersectedEle);
discovered.Add(intersectedEle.Id);
}
}
}
}
}
return k;
}
示例3: PurgeGraphicStyles
/// <summary>
/// Purge all graphic styles whose name contains
/// the given substring. Watch out what you do!
/// If your substring is empty, this might delete
/// all graphic styles in the entire project!
/// </summary>
void PurgeGraphicStyles(
Document doc,
string name_substring)
{
FilteredElementCollector graphic_styles
= new FilteredElementCollector( doc )
.OfClass( typeof( GraphicsStyle ) );
int n1 = graphic_styles.Count<Element>();
IEnumerable<Element> red_line_styles
= graphic_styles.Where<Element>( e
=> e.Name.Contains( name_substring ) );
int n2 = red_line_styles.Count<Element>();
if( 0 < n2 )
{
using( Transaction tx = new Transaction( doc ) )
{
tx.Start( "Delete Line Styles" );
doc.Delete( red_line_styles
.Select<Element, ElementId>( e => e.Id )
.ToArray<ElementId>() );
tx.Commit();
TaskDialog.Show( "Purge line styles",
string.Format(
"Deleted {0} graphic style{1} named '*{2}*' "
+ "from {3} total graohic styles.",
n2, ( 1 == n2 ? "" : "s" ),
name_substring, n1 ) );
}
}
}
示例4: ExportBatch
public static Result ExportBatch(
FilteredElementCollector doors,
Guid paramGuid,
string project_id,
uint timestamp,
ref string message )
{
// Loop through the selected doors and export
// their shared parameter value in one single
// batch call.
int n = doors.Count<Element>();
List<FireRating.DoorData> doorData
= new List<FireRating.DoorData>( n );
HttpStatusCode sc;
string jsonResponse, errorMessage;
Result rc = Result.Succeeded;
foreach( Element e in doors )
{
//Util.Log( e.Id.IntegerValue.ToString() );
doorData.Add( new DoorData( e,
project_id, paramGuid, timestamp ) );
//Util.Log( jsonResponse );
}
string query = "doors/project/" + project_id;
string content = Util.Delete( query );
sc = Util.PostBatch( out jsonResponse,
out errorMessage, "doors", doorData );
if( 0 == (int) sc )
{
message = errorMessage;
rc = Result.Failed;
}
return rc;
}
示例5: Execute
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication uiapp = commandData.Application;
Application app = uiapp.Application;
Document doc = uiapp.ActiveUIDocument.Document;
Categories categories = doc.Settings.Categories;
int nCategories = categories.Size;
Debug.Print(
"{0} categories and their parents obtained "
+ "from the Categories collection:",
nCategories );
foreach( Category c in categories )
{
Category p = c.Parent;
Debug.Print( " {0} ({1}), parent {2}",
c.Name, c.Id.IntegerValue,
( null == p ? "<none>" : p.Name ) );
}
Array bics = Enum.GetValues(
typeof( BuiltInCategory ) );
int nBics = bics.Length;
Debug.Print( "{0} built-in categories and the "
+ "corresponding document ones:", nBics );
Category cat;
string s;
List<BuiltInCategory> bics_null
= new List<BuiltInCategory>();
List<BuiltInCategory> bics_exception
= new List<BuiltInCategory>();
foreach( BuiltInCategory bic in bics )
{
try
{
cat = categories.get_Item( bic );
if( null == cat )
{
bics_null.Add( bic );
s = "<null>";
}
else
{
s = string.Format( "{0} ({1})",
cat.Name, cat.Id.IntegerValue );
}
}
catch( Exception ex )
{
bics_exception.Add( bic );
s = ex.GetType().Name + " " + ex.Message;
}
Debug.Print( " {0} --> {1}",
bic.ToString(), s );
}
int nBicsNull = bics_null.Count;
int nBicsException = bics_exception.Count;
#if ACCESS_HIDDEN_CATEGORIES_THROUGH_FILTERED_ELEMENT_COLLECTOR
// Trying to use OfClass( typeof( Category ) )
// throws an ArgumentException exception saying
// "Input type Category is not a recognized
// Revit API type".
IEnumerable<Category> cats
= new FilteredElementCollector( doc )
.WhereElementIsNotElementType()
.WhereElementIsViewIndependent()
.Cast<Category>();
// Unable to cast object of type
// 'Autodesk.Revit.DB.Element' to type
// 'Autodesk.Revit.DB.Category':
int nCategoriesFiltered = cats.Count<Category>();
Debug.Print(
"{0} categories obtained from a filtered "
+ "element collector:",
nCategoriesFiltered );
foreach( Category c in cats )
{
Debug.Print( " {0}", c.Name );
}
//.........这里部分代码省略.........
示例6: GenerateViewpoint
//.........这里部分代码省略.........
ViewOrientation3D t = RevitUtils.ConvertBasePoint(doc, viewCenter, uidoc.ActiveView.ViewDirection,
uidoc.ActiveView.UpDirection, false);
XYZ c = t.EyePosition;
XYZ vi = t.ForwardDirection;
XYZ up = t.UpDirection;
v.PerspectiveCamera = new PerspectiveCamera
{
CameraViewPoint =
{
X = c.X.ToMeters(),
Y = c.Y.ToMeters(),
Z = c.Z.ToMeters()
},
CameraUpVector =
{
X = up.X.ToMeters(),
Y = up.Y.ToMeters(),
Z = up.Z.ToMeters()
},
CameraDirection =
{
X = vi.X.ToMeters() * -1,
Y = vi.Y.ToMeters() * -1,
Z = vi.Z.ToMeters() * -1
},
FieldOfView = zoomValue
};
}
}
//COMPONENTS PART
string versionName = doc.Application.VersionName;
v.Components = new List<Component>();
var visibleElems = new FilteredElementCollector(doc, doc.ActiveView.Id)
.WhereElementIsNotElementType()
.WhereElementIsViewIndependent()
.ToElementIds();
var hiddenElems = new FilteredElementCollector(doc)
.WhereElementIsNotElementType()
.WhereElementIsViewIndependent()
.Where(x => x.IsHidden(doc.ActiveView)
|| !doc.ActiveView.IsElementVisibleInTemporaryViewMode(TemporaryViewMode.TemporaryHideIsolate, x.Id)).ToList();//would need to check how much this is affecting performance
var selectedElems = uidoc.Selection.GetElementIds();
//include only hidden elements and selected in the BCF
if (visibleElems.Count() > hiddenElems.Count())
{
foreach (var elem in hiddenElems)
{
v.Components.Add(new Component
{
OriginatingSystem = versionName,
IfcGuid = IfcGuid.ToIfcGuid(ExportUtils.GetExportId(doc, elem.Id)),
Visible = false,
Selected = false,
AuthoringToolId = elem.Id.IntegerValue.ToString()
});
}
foreach (var elem in selectedElems)
{
v.Components.Add(new Component
{
OriginatingSystem = versionName,
IfcGuid = IfcGuid.ToIfcGuid(ExportUtils.GetExportId(doc, elem)),
Visible = true,
Selected = true,
AuthoringToolId = elem.IntegerValue.ToString()
});
}
}
//include only visigle elements
//all the others are hidden
else
{
foreach (var elem in visibleElems)
{
v.Components.Add(new Component
{
OriginatingSystem = versionName,
IfcGuid = IfcGuid.ToIfcGuid(ExportUtils.GetExportId(doc, elem)),
Visible = true,
Selected = selectedElems.Contains(elem),
AuthoringToolId = elem.IntegerValue.ToString()
});
}
}
return v;
}
catch (System.Exception ex1)
{
TaskDialog.Show("Error generating viewpoint", "exception: " + ex1);
}
return null;
}
示例7: Create
public static Element Create(this Grevit.Types.Filter filter)
{
List<ElementId> categories = new List<ElementId>();
Dictionary<string,ElementId> parameters = new Dictionary<string,ElementId>();
foreach (Category category in GrevitBuildModel.document.Settings.Categories)
{
if (filter.categories.Contains(category.Name) || filter.categories.Count == 0) categories.Add(category.Id);
FilteredElementCollector collector = new FilteredElementCollector(GrevitBuildModel.document).OfCategoryId(category.Id);
if (collector.Count() > 0)
{
foreach (Autodesk.Revit.DB.Parameter parameter in collector.FirstElement().Parameters)
if (!parameters.ContainsKey(parameter.Definition.Name)) parameters.Add(parameter.Definition.Name, parameter.Id);
}
}
ParameterFilterElement parameterFilter = null;
FilteredElementCollector collect = new FilteredElementCollector(GrevitBuildModel.document).OfClass(typeof(ParameterFilterElement));
foreach (ParameterFilterElement existingFilter in collect.ToElements())
{
if (existingFilter.Name == filter.name)
{
existingFilter.ClearRules();
parameterFilter = existingFilter;
}
}
if (parameterFilter == null) parameterFilter = ParameterFilterElement.Create(GrevitBuildModel.document, filter.name, categories);
View view = (View)Utilities.GetElementByName(GrevitBuildModel.document, typeof(View), filter.view);
view.AddFilter(parameterFilter.Id);
#region Apply Rules
List<FilterRule> filterRules = new List<FilterRule>();
foreach (Grevit.Types.Rule rule in filter.Rules)
{
if (parameters.ContainsKey(rule.name))
{
FilterRule filterRule = rule.ToRevitRule(parameters[rule.name]);
if (filterRule != null) filterRules.Add(filterRule);
}
}
parameterFilter.SetRules(filterRules);
#endregion
#region Apply Overrides
OverrideGraphicSettings filterSettings = new OverrideGraphicSettings();
// Apply Colors
if (filter.CutFillColor != null) filterSettings.SetCutFillColor(filter.CutFillColor.ToRevitColor());
if (filter.ProjectionFillColor != null) filterSettings.SetProjectionFillColor(filter.ProjectionFillColor.ToRevitColor());
if (filter.CutLineColor != null) filterSettings.SetCutLineColor(filter.CutLineColor.ToRevitColor());
if (filter.ProjectionLineColor != null) filterSettings.SetProjectionLineColor(filter.ProjectionLineColor.ToRevitColor());
// Apply Lineweight
if (filter.CutLineWeight != -1) filterSettings.SetCutLineWeight(filter.CutLineWeight);
if (filter.ProjectionLineWeight != -1) filterSettings.SetProjectionLineWeight(filter.ProjectionLineWeight);
// Apply Patterns
if (filter.CutFillPattern != null)
{
FillPatternElement pattern = (FillPatternElement)Utilities.GetElementByName(GrevitBuildModel.document, typeof(FillPatternElement), filter.CutFillPattern);
filterSettings.SetCutFillPatternId(pattern.Id);
}
if (filter.ProjectionFillPattern != null)
{
FillPatternElement pattern = (FillPatternElement)Utilities.GetElementByName(GrevitBuildModel.document, typeof(FillPatternElement), filter.ProjectionFillPattern);
filterSettings.SetProjectionFillPatternId(pattern.Id);
}
if (filter.CutLinePattern != null)
{
LinePatternElement pattern = (LinePatternElement)Utilities.GetElementByName(GrevitBuildModel.document, typeof(LinePatternElement), filter.CutLinePattern);
filterSettings.SetCutLinePatternId(pattern.Id);
}
if (filter.ProjectionLinePattern != null)
{
LinePatternElement pattern = (LinePatternElement)Utilities.GetElementByName(GrevitBuildModel.document, typeof(LinePatternElement), filter.ProjectionLinePattern);
filterSettings.SetProjectionLinePatternId(pattern.Id);
}
view.SetFilterOverrides(parameterFilter.Id, filterSettings);
#endregion
//.........这里部分代码省略.........
示例8: Process
private static void Process()
{
if (_StruColumns.Count() * _StruBeams.Count() == 0) return;
string FGCode;
if (!TryGetFGCode(out FGCode)) return;
int floorNum = MyLevel.GetLevelNum() - 1;
int[] num = new int[floorNum];
int totalNum = 0;
for (int i = 0; i < floorNum; ++i)
{
int n, m, k;
double lowerLevel = _myLevel.GetElevation(i);
double upperLevel = _myLevel.GetElevation(i + 1);
double deltaHi = upperLevel - lowerLevel;
double columnLL = lowerLevel + deltaHi * 0.3;
double columnUL = upperLevel - deltaHi * 0.3;
XYZ columnBottom = new XYZ(_maxBB.Min.X, _maxBB.Min.Y, columnLL);
XYZ columnTop = new XYZ(_maxBB.Max.X, _maxBB.Max.Y, columnUL);
BoundingBoxIntersectsFilter columnBBFilter = new BoundingBoxIntersectsFilter(new Outline(columnBottom, columnTop));
FilteredElementCollector columnFec = new FilteredElementCollector(_doc, _StruColumns);
columnFec.WherePasses(columnBBFilter);
double beamLL = lowerLevel + deltaHi * 0.7;
double beamUL = upperLevel + deltaHi * 0.3;
XYZ beamBottom = new XYZ(_maxBB.Min.X, _maxBB.Min.Y, beamLL);
XYZ beamTop = new XYZ(_maxBB.Max.X, _maxBB.Max.Y, beamUL);
BoundingBoxIntersectsFilter beamBBFilter = new BoundingBoxIntersectsFilter(new Outline(beamBottom, beamTop));
FilteredElementCollector beamFec = new FilteredElementCollector(_doc, _StruBeams);
beamFec.WherePasses(beamBBFilter);
if (columnFec.Count() * beamFec.Count() == 0) continue;
GetNMK(columnFec.ToElementIds().ToList(), beamFec.ToElementIds().ToList(), out n, out m, out k);
num[i] = m - n + k;
totalNum += num[i];
}
if (totalNum != 0)
{
PGItem pgItem = new PGItem();
pgItem.Code = FGCode;
pgItem.direction = Direction.Undefined;
pgItem.PGName = "支撑刚架";
pgItem.PinYinSuffix = "ZhiChengGangJia";
pgItem.Price = _addiInfo.prices[(byte)PGComponents.BracedFrame];
if (pgItem.Price == 0.0) pgItem.IfDefinePrice = false;
else pgItem.IfDefinePrice = true;
for (int i = 0; i < floorNum; ++i)
{
pgItem.Num[i] = num[i];
}
_PGItems.Add(pgItem);
}
}
示例9: Execute
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
FilteredElementCollector rooms
= new FilteredElementCollector( doc );
//
// this is one way of obtaining rooms ... but see below for a better solution:
//
//rooms.OfClass( typeof( Room ) ); // Input type is of an element type that exists in the API, but not in Revit's native object model. Try using Autodesk.Revit.DB.Enclosure instead, and then postprocessing the results to find the elements of interest.
//rooms.OfClass( typeof( Enclosure ) ); // this works but returns all Enclosure elements
RoomFilter filter = new RoomFilter();
rooms.WherePasses( filter );
if( 0 == rooms.Count() )
{
LabUtils.InfoMsg( "There are no rooms in this model." );
}
else
{
List<string> a = new List<string>();
/*
foreach( Enclosure e in rooms ) // todo: remove this
{
Room room = e as Room; // todo: remove this
if( null != room ) // todo: remove this
{
*/
foreach( Room room in rooms )
{
string roomName = room.Name;
string roomNumber = room.Number;
string s = "Room Id=" + room.Id.IntegerValue.ToString()
+ " Name=" + roomName + " Number=" + roomNumber + "\n";
// Loop all boundaries of this room
//BoundarySegmentArrayArray boundaries = room.Boundary; // 2011
IList<IList<BoundarySegment>> boundaries // 2012
= room.GetBoundarySegments( // 2012
new SpatialElementBoundaryOptions() ); // 2012; passing in a null value throws an exception
// Check to ensure room has boundary
if( null != boundaries )
{
int iB = 0;
//foreach( BoundarySegmentArray boundary in boundaries ) // 2011
foreach( IList<BoundarySegment> boundary in boundaries ) // 2012
{
++iB;
s += " Boundary " + iB + ":\n";
int iSeg = 0;
foreach( BoundarySegment segment in boundary )
{
++iSeg;
// Segment's curve
Curve crv = segment.GetCurve();
if( crv is Line )
{
Line line = crv as Line;
XYZ ptS = line.GetEndPoint( 0 );
XYZ ptE = line.GetEndPoint( 1 );
s += " Segment " + iSeg + " is a LINE: "
+ LabUtils.PointString( ptS ) + " ; "
+ LabUtils.PointString( ptE ) + "\n";
}
else if( crv is Arc )
{
Arc arc = crv as Arc;
XYZ ptS = arc.GetEndPoint( 0 );
XYZ ptE = arc.GetEndPoint( 1 );
double r = arc.Radius;
s += " Segment " + iSeg + " is an ARC:"
+ LabUtils.PointString( ptS ) + " ; "
+ LabUtils.PointString( ptE ) + " ; R="
+ LabUtils.RealString( r ) + "\n";
}
}
}
a.Add( s );
}
LabUtils.InfoMsg( "{0} room{1} in the model{2}", a );
}
}
return Result.Failed;
}
示例10: Execute
public Result Execute(
ExternalCommandData commandData,
ref string messages,
ElementSet elements)
{
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
Transaction tx = new Transaction( doc, "Test" );
tx.Start();
// use the view filter
FilteredElementCollector collector
= new FilteredElementCollector(
doc, doc.ActiveView.Id );
// use the parameter filter.
// get the phase id "New construction"
ElementId idPhase = GetPhaseId(
"New Construction", doc );
ParameterValueProvider provider
= new ParameterValueProvider(
new ElementId( (int)
BuiltInParameter.PHASE_CREATED ) );
FilterNumericRuleEvaluator evaluator
= new FilterNumericEquals();
FilterElementIdRule rule
= new FilterElementIdRule(
provider, evaluator, idPhase );
ElementParameterFilter parafilter
= new ElementParameterFilter( rule );
collector.WherePasses( parafilter );
TaskDialog.Show( "Element Count",
"There are " + collector.Count().ToString()
+ " elements in the current view created"
+ " with phase New Construction" );
tx.Commit();
return Result.Succeeded;
}
示例11: GetBeamsIntersectingTwoColumns
/// <summary>
/// Retrieve all beam family instances
/// intersecting two columns, cf.
/// http://forums.autodesk.com/t5/revit-api/check-to-see-if-beam-exists/m-p/6223562
/// </summary>
FilteredElementCollector GetBeamsIntersectingTwoColumns(
Element column1,
Element column2)
{
Document doc = column1.Document;
if( column2.Document.GetHashCode() != doc.GetHashCode() )
{
throw new ArgumentException(
"Expected two columns from same document." );
}
FilteredElementCollector intersectingStructuralFramingElements
= new FilteredElementCollector( doc )
.OfClass( typeof( FamilyInstance ) )
.OfCategory( BuiltInCategory.OST_StructuralFraming )
.WherePasses( new ElementIntersectsElementFilter( column1 ) )
.WherePasses( new ElementIntersectsElementFilter( column2 ) );
int n = intersectingStructuralFramingElements.Count<Element>();
string result = string.Format(
"{0} structural framing family instance{1} "
+ "intersect{2} the two beams{3}",
n, Util.PluralSuffix( n ),
( 1 == n ? "s" : "" ),
Util.DotOrColon( n ) );
string id_list = 0 == n
? string.Empty
: string.Join( ", ",
intersectingStructuralFramingElements
.Select<Element, string>(
x => x.Id.IntegerValue.ToString() ) )
+ ".";
Util.InfoMsg2( result, id_list );
return intersectingStructuralFramingElements;
}
示例12: findColumnsInWall
/// <summary>
/// Find columns in wall
/// </summary>
/// <param name="walls">The walls to be detected</param>
/// <returns>The detection result</returns>
public XElement findColumnsInWall(IEnumerable<Wall> walls)
{
// create a node that place all walls.
XElement wallsNode = new XElement("Walls", new XAttribute("Name", "Walls"));
try
{
foreach (Wall wall in walls)
{
XElement wallNode = new XElement("Wall", new XAttribute("Name", wall.Name));
// Iterate to find columns and structural columns
FilteredElementCollector collector = new FilteredElementCollector(m_doc);
List<BuiltInCategory> columnCategories = new List<BuiltInCategory>();
columnCategories.Add(BuiltInCategory.OST_Columns);
columnCategories.Add(BuiltInCategory.OST_StructuralColumns);
collector.WherePasses(new ElementMulticategoryFilter(columnCategories));
// Apply element intersection filter
ElementIntersectsElementFilter testElementIntersectsElementFilter =
new ElementIntersectsElementFilter(wall);
collector.WherePasses(testElementIntersectsElementFilter);
XElement columnsNode = new XElement("columns",
new XAttribute("Count", collector.Count().ToString()));
foreach (Element column in collector)
{
columnsNode.Add(new XElement("column", new XAttribute("Name", column.Name)));
}
wallNode.Add(columnsNode);
wallsNode.Add(wallNode);
}
}
catch (Exception ex)
{
wallsNode.Add(new XElement("Error", new XAttribute("Exception", ex.ToString())));
}
// return the whole walls Node
return wallsNode;
}
示例13: TryGetFGCode
private static bool TryGetFGCode(out string FGCode)
{
FGCode = "";
int ds_type = _addiInfo.defaultSet[(byte)DefaultSet.BracedFrame_FrameType];
int ds_crossSection = _addiInfo.defaultSet[(byte)DefaultSet.BracedFrame_CrossSection];
if((ds_type == 0 && 5 <= ds_crossSection) || (ds_type == 1 && ds_crossSection <= 4))
{
_abandonWriter.WriteAbandonment(null, AbandonmentTable.BracedFrame_TypeCrossConflict);
return false;
}
else
{
int ds_brace = 0;
int ds_plf = 0;
if (_Braces.Count != 0)
{
int numOverlap = 0;
int numColumn = 0;
FamilyInstance brace = (FamilyInstance)_Braces.First();
Curve curve = (brace.Location as LocationCurve).Curve;
XYZ p0 = curve.GetEndPoint(0);
XYZ p1 = curve.GetEndPoint(1);
XYZ deltaXYZ = new XYZ(ErrorCTRL_Overlap, ErrorCTRL_Overlap, ErrorCTRL_Overlap);
BoundingBoxIntersectsFilter bbFilter = new BoundingBoxIntersectsFilter(
new Outline(brace.get_BoundingBox(_doc.ActiveView).Min - deltaXYZ, brace.get_BoundingBox(_doc.ActiveView).Max + deltaXYZ));
FilteredElementCollector fec = new FilteredElementCollector(_doc);
fec.WherePasses(bbFilter).WherePasses(new ElementStructuralTypeFilter(StructuralType.Brace));
foreach (Element brace2 in fec)
{
if (brace2.Id != brace.Id)
{
Curve curve2 = (brace2.Location as LocationCurve).Curve;
XYZ p2_0 = curve2.GetEndPoint(0);
XYZ p2_1 = curve2.GetEndPoint(1);
if (IsTheSamePoint(p2_0, p0) || IsTheSamePoint(p2_0, p1)) ++numOverlap;
if (IsTheSamePoint(p2_1, p0) || IsTheSamePoint(p2_1, p1)) ++numOverlap;
break;
}
}
fec = new FilteredElementCollector(_doc);
fec.WherePasses(bbFilter).WherePasses(new ElementStructuralTypeFilter(StructuralType.Column));
numColumn = fec.Count();
if (numOverlap == 1 && numColumn == 1) ds_brace = 1; //Chevron
else if (numOverlap == 2) ds_brace = 3; //X
else ds_brace = 2; //single
try
{
IList<Parameter> paras = brace.Symbol.GetParameters("A");
double area = paras.First().AsDouble();
if (area == 0.0) throw new Exception();
else
{
double plf = area * density_steel;
if (plf <= 40.0) ds_plf = 0;
else if (100.0 <= plf) ds_plf = 2;
else ds_plf = 1;
}
}
catch
{
ds_plf = _addiInfo.defaultSet[(byte)DefaultSet.BracedFrame_PLF];
}
}
else
{
ds_brace = _addiInfo.defaultSet[(byte)DefaultSet.BracedFrame_Brace];
ds_plf = _addiInfo.defaultSet[(byte)DefaultSet.BracedFrame_PLF];
}
if (ds_crossSection != 8)
{
FGCode = "B1033.0";
FGCode += ds_crossSection.ToString() + ds_brace.ToString() + ConstSet.Alphabet[ds_plf];
}
else
{
FGCode = "B1033.1";
if (ds_brace == 3)
{
_abandonWriter.WriteAbandonment(null, AbandonmentTable.BracedFrame_BRBwXBrace);
return false;
}
else
{
FGCode += (ds_brace - 1).ToString() + "1" + ConstSet.Alphabet[ds_plf];
}
}
return true;
}
}
示例14: ExportMain
public static Result ExportMain(
bool useBatch,
ExternalCommandData commandData,
ref string message )
{
UIApplication uiapp = commandData.Application;
Application app = uiapp.Application;
Document doc = uiapp.ActiveUIDocument.Document;
// Get shared parameter GUID.
Guid paramGuid;
if( !Util.GetSharedParamGuid( app, out paramGuid ) )
{
message = "Shared parameter GUID not found.";
return Result.Failed;
}
// Determine custom project identifier.
string project_id = Util.GetProjectIdentifier( doc );
// Determine timestamp.
uint timestamp = Util.UnixTimestamp();
// Loop through all elements of the given target
// category and export the shared parameter value
// specified by paramGuid for each.
//FilteredElementCollector collector
// = Util.GetTargetInstances( doc,
// Cmd_1_CreateAndBindSharedParameter.Target );
FilteredElementCollector collector
= new FilteredElementCollector( doc )
.OfClass( typeof( FamilyInstance ) )
.OfCategory( BuiltInCategory.OST_Doors );
int n = collector.Count<Element>();
Util.Log( string.Format(
"Exporting {0} element{1} {2}.",
n, Util.PluralSuffix( n ),
(useBatch ? "in batch" : "one by one" ) ) );
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
Result rc = useBatch
? ExportBatch( collector, paramGuid,
project_id, timestamp, ref message )
: ExportOneByOne( collector, paramGuid,
project_id, timestamp, ref message );
stopwatch.Stop();
Util.Log( string.Format(
"{0} milliseconds to export {1} element{2}: {3}.",
stopwatch.ElapsedMilliseconds,
n, Util.PluralSuffix( n ), rc ) );
return rc;
}
示例15: GetInstancesIntersectingElement
/// <summary>
/// Retrieve all family instances intersecting a
/// given BIM element, e.g. all columns
/// intersecting a wall.
/// </summary>
void GetInstancesIntersectingElement( Element e )
{
#region Joe's code
#if JOE_CODE
// Find intersections between family instances and a selected element
Reference Reference = uidoc.Selection.PickObject(
ObjectType.Element, "Select element that will "
+ "be checked for intersection with all family "
+ "instances" );
Element e = doc.GetElement( reference );
GeometryElement geomElement = e.get_Geometry(
new Options() );
Solid solid = null;
foreach( GeometryObject geomObj in geomElement )
{
solid = geomObj as Solid;
if( solid = !null ) break;
}
FilteredElementCollector collector
= new FilteredElementCollector( doc )
.OfClass( typeof( FamilyInstance ) )
.WherePasses( new ElementIntersectsSolidFilter(
solid ) );
TaskDialog.Show( "Revit", collector.Count() +
"Family instances intersect with selected element ("
+ element.Category.Name + "ID:" + element.Id + ")" );
#endif // JOE_CODE
#endregion // Joe's code
// Test this in these SDK sample models:
// C:\a\lib\revit\2015\SDK\Samples\FindReferencesByDirection\FindColumns\FindColumns-Basic.rvt
// C:\a\lib\revit\2015\SDK\Samples\FindReferencesByDirection\FindColumns\FindColumns-TestCases.rvt
Document doc = e.Document;
Solid solid = e.get_Geometry( new Options() )
.OfType<Solid>()
.Where<Solid>( s => null != s && !s.Edges.IsEmpty )
.FirstOrDefault();
FilteredElementCollector intersectingInstances
= new FilteredElementCollector( doc )
.OfClass( typeof( FamilyInstance ) )
.WherePasses( new ElementIntersectsSolidFilter(
solid ) );
int n1 = intersectingInstances.Count<Element>();
intersectingInstances
= new FilteredElementCollector( doc )
.OfClass( typeof( FamilyInstance ) )
.WherePasses( new ElementIntersectsElementFilter(
e ) );
int n = intersectingInstances.Count<Element>();
Debug.Assert( n.Equals( n1 ),
"expected solid intersection to equal element intersection" );
string result = string.Format(
"{0} family instance{1} intersect{2} the "
+ "selected element {3}{4}",
n, Util.PluralSuffix( n ),
( 1 == n ? "s" : "" ),
Util.ElementDescription( e ),
Util.DotOrColon( n ) );
string id_list = 0 == n
? string.Empty
: string.Join( ", ",
intersectingInstances
.Select<Element, string>(
x => x.Id.IntegerValue.ToString() ) )
+ ".";
Util.InfoMsg2( result, id_list );
}