本文整理汇总了C#中FilteredElementCollector.FirstElement方法的典型用法代码示例。如果您正苦于以下问题:C# FilteredElementCollector.FirstElement方法的具体用法?C# FilteredElementCollector.FirstElement怎么用?C# FilteredElementCollector.FirstElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FilteredElementCollector
的用法示例。
在下文中一共展示了FilteredElementCollector.FirstElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Create
/// <summary>
/// Set a Revit Curtain Panel
/// </summary>
/// <param name="setCurtainPanel"></param>
/// <returns></returns>
public static Element Create(this Grevit.Types.SetCurtainPanel setCurtainPanel)
{
// If there arent any valid properties return null
if (setCurtainPanel.panelID == 0 || setCurtainPanel.panelType == "") return null;
// Get the panel to change
Panel panel = (Panel)GrevitCommand.document.GetElement(new ElementId(setCurtainPanel.panelID));
// get its host wall
Element wallElement = panel.Host;
if (wallElement.GetType() == typeof(Autodesk.Revit.DB.Wall))
{
// Cast the Wall
Autodesk.Revit.DB.Wall wall = (Autodesk.Revit.DB.Wall)wallElement;
// Try to get the curtain panel type
FilteredElementCollector collector = new FilteredElementCollector(GrevitCommand.document).OfClass(typeof(PanelType));
Element paneltype = collector.FirstElement();
foreach (Element em in collector.ToElements()) if (em.Name == setCurtainPanel.panelType) paneltype = em;
// Cast the Element type
ElementType type = (ElementType)paneltype;
// Change the panel type
wall.CurtainGrid.ChangePanelType(panel, type);
}
return panel;
}
示例2: Execute
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
Document doc = commandData.Application
.ActiveUIDocument.Document;
FilteredElementCollector collector
= new FilteredElementCollector( doc );
collector.OfClass( typeof( Level ) );
Level level = collector.FirstElement() as Level;
Transaction t = new Transaction( doc );
t.Start( "Create unbounded room" );
FailureHandlingOptions failOpt
= t.GetFailureHandlingOptions();
failOpt.SetFailuresPreprocessor(
new RoomWarningSwallower() );
t.SetFailureHandlingOptions( failOpt );
doc.Create.NewRoom( level, new UV( 0, 0 ) );
t.Commit();
return Result.Succeeded;
}
示例3: Execute
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
_revit_window
= new JtWindowHandle(
ComponentManager.ApplicationWindow );
UIApplication uiapp = commandData.Application;
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;
FilteredElementCollector collector
= new FilteredElementCollector( doc );
collector.OfCategory( BuiltInCategory.OST_Doors );
collector.OfClass( typeof( FamilySymbol ) );
FamilySymbol symbol = collector.FirstElement()
as FamilySymbol;
_added_element_ids.Clear();
app.DocumentChanged
+= new EventHandler<DocumentChangedEventArgs>(
OnDocumentChanged );
//PromptForFamilyInstancePlacementOptions opt
// = new PromptForFamilyInstancePlacementOptions();
uidoc.PromptForFamilyInstancePlacement( symbol );
app.DocumentChanged
-= new EventHandler<DocumentChangedEventArgs>(
OnDocumentChanged );
int n = _added_element_ids.Count;
TaskDialog.Show(
"Place Family Instance",
string.Format(
"{0} element{1} added.", n,
( ( 1 == n ) ? "" : "s" ) ) );
return Result.Succeeded;
}
示例4: GetFirstWallUsingType
/// <summary>
/// Return the first wall found that
/// uses the given wall type.
/// </summary>
static Wall GetFirstWallUsingType(
Document doc,
WallType wallType)
{
// built-in parameter storing this
// wall's wall type element id:
BuiltInParameter bip
= BuiltInParameter.ELEM_TYPE_PARAM;
ParameterValueProvider provider
= new ParameterValueProvider(
new ElementId( bip ) );
FilterNumericRuleEvaluator evaluator
= new FilterNumericEquals();
FilterRule rule = new FilterElementIdRule(
provider, evaluator, wallType.Id );
ElementParameterFilter filter
= new ElementParameterFilter( rule );
FilteredElementCollector collector
= new FilteredElementCollector( doc )
.OfClass( typeof( Wall ) )
.WherePasses( filter );
return collector.FirstElement() as Wall;
}
示例5: GetFirstWallTypeNamed
/// <summary>
/// Return the first wall type with the given name.
/// </summary>
static WallType GetFirstWallTypeNamed(
Document doc,
string name)
{
// built-in parameter storing this
// wall type's name:
BuiltInParameter bip
= BuiltInParameter.SYMBOL_NAME_PARAM;
ParameterValueProvider provider
= new ParameterValueProvider(
new ElementId( bip ) );
FilterStringRuleEvaluator evaluator
= new FilterStringEquals();
FilterRule rule = new FilterStringRule(
provider, evaluator, name, false );
ElementParameterFilter filter
= new ElementParameterFilter( rule );
FilteredElementCollector collector
= new FilteredElementCollector( doc )
.OfClass( typeof( WallType ) )
.WherePasses( filter );
return collector.FirstElement() as WallType;
}
示例6: RevitObject
List<RevitObject> ILyrebirdService.GetFamilyNames()
{
familyNames.Add(new RevitObject("NULL", -1, "NULL"));
lock (_locker)
{
try
{
UIApplication uiApp = RevitServerApp.UIApp;
familyNames = new List<RevitObject>();
// Get all standard wall families
FilteredElementCollector familyCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document);
familyCollector.OfClass(typeof(Family));
List<RevitObject> families = new List<RevitObject>();
foreach (Family f in familyCollector)
{
RevitObject ro = new RevitObject(f.FamilyCategory.Name, f.FamilyCategory.Id.IntegerValue, f.Name);
families.Add(ro);
}
// Add System families
FilteredElementCollector wallTypeCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document);
wallTypeCollector.OfClass(typeof(WallType));
WallType wt = wallTypeCollector.FirstElement() as WallType;
if (wt != null)
{
RevitObject wallObj = new RevitObject(wt.Category.Name, wt.Category.Id.IntegerValue, wt.Category.Name);
families.Add(wallObj);
}
//RevitObject curtainObj = new RevitObject("Walls", "Curtain Wall");
//families.Add(curtainObj);
//RevitObject stackedObj = new RevitObject("Walls", "Stacked Wall");
//families.Add(stackedObj);
FilteredElementCollector floorTypeCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document);
floorTypeCollector.OfClass(typeof(FloorType));
FloorType ft = floorTypeCollector.FirstElement() as FloorType;
if (ft != null)
{
RevitObject floorObj = new RevitObject(ft.Category.Name, ft.Category.Id.IntegerValue, ft.Category.Name);
families.Add(floorObj);
}
FilteredElementCollector roofTypeCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document);
roofTypeCollector.OfClass(typeof(RoofType));
RoofType rt = roofTypeCollector.FirstElement() as RoofType;
if (rt != null)
{
RevitObject roofObj = new RevitObject(rt.Category.Name, rt.Category.Id.IntegerValue, rt.Category.Name);
families.Add(roofObj);
}
FilteredElementCollector levelTypeCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document);
levelTypeCollector.OfClass(typeof(LevelType));
LevelType lt = levelTypeCollector.FirstElement() as LevelType;
if (lt != null)
{
RevitObject levelObj = new RevitObject(lt.Category.Name, lt.Category.Id.IntegerValue, lt.Category.Name);
families.Add(levelObj);
}
FilteredElementCollector gridTypeCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document);
gridTypeCollector.OfClass(typeof(GridType));
GridType gt = gridTypeCollector.FirstElement() as GridType;
if (gt != null)
{
RevitObject gridObj = new RevitObject(gt.Category.Name, gt.Category.Id.IntegerValue, gt.Category.Name);
families.Add(gridObj);
}
FilteredElementCollector lineTypeCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document);
lineTypeCollector.OfCategory(BuiltInCategory.OST_Lines);
try
{
CurveElement ce = lineTypeCollector.FirstElement() as CurveElement;
RevitObject modelLineObj = new RevitObject(ce.Category.Name, ce.Category.Id.IntegerValue, "Model Lines");
RevitObject detailLineObj = new RevitObject(ce.Category.Name, ce.Category.Id.IntegerValue, "Detail Lines");
families.Add(modelLineObj);
families.Add(detailLineObj);
}
catch
{
RevitObject modelLineObj = new RevitObject("Lines", -2000051, "Model Lines");
RevitObject detailLineObj = new RevitObject("Lines", -2000051, "Detail Lines");
families.Add(modelLineObj);
families.Add(detailLineObj);
}
families.Sort((x, y) => String.CompareOrdinal(x.FamilyName.ToUpper(), y.FamilyName.ToUpper()));
familyNames = families;
}
catch (Exception exception)
{
Debug.WriteLine(exception.Message);
}
Monitor.Wait(_locker, Properties.Settings.Default.infoTimeout);
}
return familyNames;
}
示例7: GetProjectInfoElem
public static Element GetProjectInfoElem(Document doc)
{
FilteredElementCollector col = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_ProjectInformation);
Element e = col.FirstElement();
return e;
}
示例8: Create
/// <summary>
/// Create Hatch
/// </summary>
/// <param name="hatch"></param>
/// <returns></returns>
public static Element Create(this Grevit.Types.Hatch hatch)
{
// Get all Filled region types
FilteredElementCollector collector = new FilteredElementCollector(GrevitBuildModel.document).OfClass(typeof(Autodesk.Revit.DB.FilledRegionType));
// Get the View to place the hatch on
Element viewElement = GrevitBuildModel.document.GetElementByName(typeof(Autodesk.Revit.DB.View), hatch.view);
// Get the hatch pattern name and set it to solid if the hatch pattern name is invalid
string patternname = (hatch.pattern == null || hatch.pattern == string.Empty) ? patternname = "Solid fill" : hatch.pattern;
// Get the fill pattern element and filled region type
FillPatternElement fillPatternElement = FillPatternElement.GetFillPatternElementByName(GrevitBuildModel.document, FillPatternTarget.Drafting, patternname);
FilledRegionType filledRegionType = collector.FirstElement() as FilledRegionType;
// Setup a new curveloop for the outline
CurveLoop curveLoop = new CurveLoop();
List<CurveLoop> listOfCurves = new List<CurveLoop>();
// Get a closed loop from the grevit points
for (int i = 0; i < hatch.outline.Count; i++)
{
int j = i + 1;
Grevit.Types.Point p1 = hatch.outline[i];
if (j == hatch.outline.Count) j = 0;
Grevit.Types.Point p2 = hatch.outline[j];
Curve cn = Autodesk.Revit.DB.Line.CreateBound(p1.ToXYZ(), p2.ToXYZ());
curveLoop.Append(cn);
}
listOfCurves.Add(curveLoop);
// Create a filled region from the loop
return FilledRegion.Create(GrevitBuildModel.document, filledRegionType.Id, viewElement.Id, listOfCurves);
}
示例9: GetFamilyNames
public List<RevitObject> GetFamilyNames()
{
familyNames.Add(new RevitObject("NULL", -1, "NULL"));
lock (_locker)
{
try
{
UIApplication uiApp = RevitServerApp.UIApp;
familyNames = new List<RevitObject>();
// Get all standard wall families
FilteredElementCollector familyCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document);
familyCollector.OfClass(typeof(Family));
List<RevitObject> families = new List<RevitObject>();
foreach (Family f in familyCollector)
{
RevitObject ro = new RevitObject(f.FamilyCategory.Name, f.FamilyCategory.Id.IntegerValue, f.Name);
families.Add(ro);
}
// Add System families
FilteredElementCollector wallTypeCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document);
wallTypeCollector.OfClass(typeof(WallType));
WallType wt = wallTypeCollector.FirstElement() as WallType;
if (wt != null)
{
RevitObject wallObj = new RevitObject(wt.Category.Name, wt.Category.Id.IntegerValue, wt.Category.Name);
families.Add(wallObj);
}
//RevitObject curtainObj = new RevitObject("Walls", "Curtain Wall");
//families.Add(curtainObj);
//RevitObject stackedObj = new RevitObject("Walls", "Stacked Wall");
//families.Add(stackedObj);
FilteredElementCollector floorTypeCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document);
floorTypeCollector.OfClass(typeof(FloorType));
FloorType ft = floorTypeCollector.FirstElement() as FloorType;
if (ft != null)
{
RevitObject floorObj = new RevitObject(ft.Category.Name, ft.Category.Id.IntegerValue, ft.Category.Name);
families.Add(floorObj);
}
FilteredElementCollector roofTypeCollector = new FilteredElementCollector(uiApp.ActiveUIDocument.Document);
roofTypeCollector.OfClass(typeof(RoofType));
RoofType rt = roofTypeCollector.FirstElement() as RoofType;
if (rt != null)
{
RevitObject roofObj = new RevitObject(rt.Category.Name, rt.Category.Id.IntegerValue, rt.Category.Name);
families.Add(roofObj);
}
families.Sort((x, y) => String.CompareOrdinal(x.FamilyName.ToUpper(), y.FamilyName.ToUpper()));
familyNames = families;
}
catch (Exception exception)
{
Debug.WriteLine(exception.Message);
}
Monitor.Wait(_locker, Properties.Settings.Default.infoTimeout);
}
return familyNames;
}
示例10: GetElementByName
/// <summary>
/// Gets a Family by its Category, Family name and Type Name
/// </summary>
/// <param name="document"></param>
/// <param name="category">Category</param>
/// <param name="family">Family Name</param>
/// <param name="type">Type Name</param>
/// <returns></returns>
public static Element GetElementByName(this Document document, BuiltInCategory category, string family, string type)
{
FilteredElementCollector collector = new FilteredElementCollector(document).OfCategory(category);
foreach (Element e in collector.ToElements())
{
string familyName = "";
string typeName = "";
if (e.GetType() == typeof(FamilyInstance))
{
FamilyInstance fi = (FamilyInstance)e;
familyName = fi.Symbol.Family.Name;
typeName = fi.Symbol.Name;
}
else if (e.GetType() == typeof(FamilySymbol))
{
FamilySymbol fs = (FamilySymbol)e;
familyName = fs.Family.Name;
typeName = fs.Name;
}
if (familyName == family && typeName == type) return e;
}
return collector.FirstElement();
}
示例11: GetElementByName
/// <summary>
/// Gets a Family by its Type, Family name and Type Name
/// </summary>
/// <param name="document"></param>
/// <param name="type">Element Class</param>
/// <param name="family">Family Name</param>
/// <param name="familyType">Type Name</param>
/// <returns></returns>
public static Element GetElementByName(this Document document, Type type, string family, string familyType, out bool found)
{
FilteredElementCollector collector = new FilteredElementCollector(document).OfClass(type);
foreach (Element e in collector.ToElements())
{
string familyName = "";
string typeName = "";
if (e.GetType() == typeof(FamilyInstance))
{
FamilyInstance fi = (FamilyInstance)e;
familyName = fi.Symbol.Family.Name;
typeName = fi.Symbol.Name;
}
else if (e.GetType() == typeof(FamilySymbol))
{
FamilySymbol fs = (FamilySymbol)e;
familyName = fs.Family.Name;
typeName = fs.Name;
}
if (familyName == family && typeName == familyType) { found = true; return e; }
}
found = false;
return collector.FirstElement();
}
示例12: GetLevelByName
public static Autodesk.Revit.DB.Level GetLevelByName(this Document document, string name, double elevation)
{
FilteredElementCollector collector = new FilteredElementCollector(document).OfClass(typeof(Autodesk.Revit.DB.Level));
Autodesk.Revit.DB.Level result = (Autodesk.Revit.DB.Level)collector.FirstElement();
List<Autodesk.Revit.DB.Level> levels = new List<Autodesk.Revit.DB.Level>();
foreach (Autodesk.Revit.DB.Level e in collector.ToElements())
{
if (e.Name == name) return e;
levels.Add(e);
}
List<Autodesk.Revit.DB.Level> ordered = levels.OrderBy(e => e.Elevation).ToList();
for (int i = 0; i < ordered.Count(); i++)
{
if (i < ordered.Count - 1)
{
if (ordered[i].Elevation <= elevation && ordered[i + 1].Elevation > elevation)
result = ordered[i];
}
else
result = ordered[i];
}
return result;
}
示例13: Execute
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
Debug.Assert( false, "this has not been tested yet in Revit 2011!" );
UIApplication app = commandData.Application;
Document doc = app.ActiveUIDocument.Document;
Autodesk.Revit.Creation.Application ca
= app.Application.Create;
Autodesk.Revit.Creation.Document cd
= doc.Create;
// determine line load symbol to use:
FilteredElementCollector symbols
= new FilteredElementCollector( doc );
symbols.OfClass( typeof( LineLoadType ) );
LineLoadType loadSymbol
= symbols.FirstElement() as LineLoadType;
// sketch plane and arrays of forces and moments:
Plane plane = ca.NewPlane( XYZ.BasisZ, XYZ.Zero );
//SketchPlane skplane = cd.NewSketchPlane( plane ); // 2013
SketchPlane skplane = SketchPlane.Create( doc, plane ); // 2014
XYZ forceA = new XYZ( 0, 0, 5 );
XYZ forceB = new XYZ( 0, 0, 10 );
List<XYZ> forces = new List<XYZ>();
forces.Add( forceA );
forces.Add( forceB );
XYZ momentA = new XYZ( 0, 0, 0 );
XYZ momentB = new XYZ( 0, 0, 0 );
List<XYZ> moments = new List<XYZ>();
moments.Add( momentA );
moments.Add( momentB );
BuiltInCategory bic
= BuiltInCategory.OST_StructuralFraming;
FilteredElementCollector beams = Util.GetElementsOfType(
doc, typeof( FamilyInstance ), bic );
XYZ p1 = new XYZ( 0, 0, 0 );
XYZ p2 = new XYZ( 3, 0, 0 );
List<XYZ> points = new List<XYZ>();
points.Add( p1 );
points.Add( p2 );
// create a new unhosted line load on points:
LineLoad lineLoadNoHost = cd.NewLineLoad(
points, forces, moments,
false, false, false,
loadSymbol, skplane );
Debug.Print( "Unhosted line load works." );
// create new line loads on beam:
foreach( Element e in beams )
{
try
{
LineLoad lineLoad = cd.NewLineLoad(
e, forces, moments,
false, false, false,
loadSymbol, skplane );
Debug.Print( "Hosted line load on beam works." );
}
catch( Exception ex )
{
Debug.Print( "Hosted line load on beam fails: "
+ ex.Message );
}
FamilyInstance i = e as FamilyInstance;
AnalyticalModel am = i.GetAnalyticalModel();
foreach( Curve curve in
am.GetCurves( AnalyticalCurveType.ActiveCurves ) )
{
try
{
LineLoad lineLoad = cd.NewLineLoad(
curve.Reference, forces, moments,
false, false, false,
loadSymbol, skplane );
//.........这里部分代码省略.........
示例14: AddFaceBasedFamilyToLinks
public void AddFaceBasedFamilyToLinks( Document doc )
{
ElementId alignedLinkId = new ElementId( 125929 );
// Get symbol
ElementId symbolId = new ElementId( 126580 );
FamilySymbol fs = doc.GetElement( symbolId )
as FamilySymbol;
// Aligned
RevitLinkInstance linkInstance = doc.GetElement(
alignedLinkId ) as RevitLinkInstance;
Document linkDocument = linkInstance
.GetLinkDocument();
FilteredElementCollector wallCollector
= new FilteredElementCollector( linkDocument );
wallCollector.OfClass( typeof( Wall ) );
Wall targetWall = wallCollector.FirstElement()
as Wall;
Reference exteriorFaceRef
= HostObjectUtils.GetSideFaces(
targetWall, ShellLayerType.Exterior )
.First<Reference>();
Reference linkToExteriorFaceRef
= exteriorFaceRef.CreateLinkReference(
linkInstance );
Line wallLine = ( targetWall.Location
as LocationCurve ).Curve as Line;
XYZ wallVector = ( wallLine.GetEndPoint( 1 )
- wallLine.GetEndPoint( 0 ) ).Normalize();
using( Transaction t = new Transaction( doc ) )
{
t.Start( "Add to face" );
doc.Create.NewFamilyInstance(
linkToExteriorFaceRef, XYZ.Zero,
wallVector, fs );
t.Commit();
}
}
示例15: GetElementsMatchingParameter
/// <summary>
/// Return a list of all elements with the
/// specified value in their shared parameter with
/// the given name oand group. They are retrieved
/// using a parameter filter, and the required
/// parameter id is found by temporarily adding
/// the shared parameter to the project info.
/// </summary>
static IList<Element> GetElementsMatchingParameter(
Document doc,
string paramName,
string paramGroup,
string paramValue)
{
IList<Element> elems = new List<Element>();
// Determine if definition for parameter binding exists
Definition definition = null;
BindingMap bm = doc.ParameterBindings;
DefinitionBindingMapIterator it = bm.ForwardIterator();
while( it.MoveNext() )
{
Definition def = it.Key;
if( def.Name.Equals( paramName ) )
{
definition = def;
break;
}
}
if( definition == null )
{
return elems; // parameter binding not defined
}
using( Transaction tx = new Transaction( doc ) )
{
tx.Start( "Set temporary parameter" );
// Temporarily set project information element
// parameter in order to determine param.Id
FilteredElementCollector collectorPI
= new FilteredElementCollector( doc );
collectorPI.OfCategory(
BuiltInCategory.OST_ProjectInformation );
Element projInfoElem
= collectorPI.FirstElement();
// using http://thebuildingcoder.typepad.com/blog/2012/04/adding-a-category-to-a-shared-parameter-binding.html
Parameter param = null;
//param = HelperParams.GetOrCreateElemSharedParam(
// projInfoElem, paramName, paramGroup,
// ParameterType.Text, false, true );
if( param != null )
{
ElementId paraId = param.Id;
tx.RollBack(); // discard project element change
ParameterValueProvider provider
= new ParameterValueProvider( paraId );
FilterRule rule = new FilterStringRule(
provider, new FilterStringEquals(),
paramValue, true );
ElementParameterFilter filter
= new ElementParameterFilter( rule );
FilteredElementCollector collector
= new FilteredElementCollector(
doc, doc.ActiveView.Id );
elems = collector.WherePasses( filter )
.ToElements();
}
}
return elems;
}