本文整理汇总了C#中FilteredElementCollector.ToElements方法的典型用法代码示例。如果您正苦于以下问题:C# FilteredElementCollector.ToElements方法的具体用法?C# FilteredElementCollector.ToElements怎么用?C# FilteredElementCollector.ToElements使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FilteredElementCollector
的用法示例。
在下文中一共展示了FilteredElementCollector.ToElements方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAllViews
/// <summary>
/// Finds all the views in the active document.
/// </summary>
/// <param name="doc">the active document</param>
public static ViewSet GetAllViews (Document doc)
{
ViewSet allViews = new ViewSet();
FilteredElementCollector fec = new FilteredElementCollector(doc);
ElementClassFilter elementsAreWanted = new ElementClassFilter(typeof(FloorType));
fec.WherePasses(elementsAreWanted);
List<Element> elements = fec.ToElements() as List<Element>;
foreach (Element element in elements)
{
Autodesk.Revit.DB.View view = element as Autodesk.Revit.DB.View;
if (null == view)
{
continue;
}
else
{
ElementType objType = doc.GetElement(view.GetTypeId()) as ElementType;
if (null == objType || objType.Name.Equals("Drawing Sheet"))
{
continue;
}
else
{
allViews.Insert(view);
}
}
}
return allViews;
}
示例2: ReferenceCurve
public void ReferenceCurve()
{
var model = dynSettings.Controller.DynamoModel;
string samplePath = Path.Combine(_testPath, @".\ReferenceCurve\ReferenceCurve.dyn");
string testPath = Path.GetFullPath(samplePath);
model.Open(testPath);
dynSettings.Controller.RunExpression(true);
FilteredElementCollector fec = new FilteredElementCollector(dynRevitSettings.Doc.Document);
fec.OfClass(typeof(CurveElement));
//verify five model curves created
int count = fec.ToElements().Count;
Assert.IsInstanceOf(typeof(ModelCurve), fec.ToElements().First());
Assert.IsTrue(((ModelCurve)fec.ToElements().First()).IsReferenceLine);
Assert.AreEqual(5, count);
ElementId id = fec.ToElements().First().Id;
//update any number node and verify
//that the element gets updated not recreated
var doubleNodes = dynSettings.Controller.DynamoModel.Nodes.Where(x => x is DoubleInput);
var node = doubleNodes.First() as DoubleInput;
Assert.IsNotNull(node);
node.Value = node.Value + .1;
dynSettings.Controller.RunExpression(true);
Assert.AreEqual(5, fec.ToElements().Count);
}
示例3: DividedSurface
public void DividedSurface()
{
var model = ViewModel.Model;
string samplePath = Path.Combine(workingDirectory, @".\DividedSurface\DividedSurface.dyn");
string testPath = Path.GetFullPath(samplePath);
ViewModel.OpenCommand.Execute(testPath);
ViewModel.Model.RunExpression();
FilteredElementCollector fec = new FilteredElementCollector(DocumentManager.Instance.CurrentUIDocument.Document);
fec.OfClass(typeof(DividedSurface));
//did it create a divided surface?
Assert.AreEqual(1, fec.ToElements().Count());
var ds = (DividedSurface)fec.ToElements()[0];
Assert.AreEqual(5, ds.USpacingRule.Number);
Assert.AreEqual(5, ds.VSpacingRule.Number);
//can we change the number of divisions
var numNode = ViewModel.Model.Nodes.OfType<DoubleInput>().First();
numNode.Value = "10";
ViewModel.Model.RunExpression();
//did it create a divided surface?
Assert.AreEqual(10, ds.USpacingRule.Number);
Assert.AreEqual(10, ds.VSpacingRule.Number);
//ensure there is a warning when we try to set a negative number of divisions
numNode.Value = "-5";
ViewModel.Model.RunExpression();
Assert.Greater(ViewModel.Model.EngineController.LiveRunnerCore.RuntimeStatus.WarningCount, 0);
}
示例4: CurveByPoints
public void CurveByPoints()
{
var model = dynSettings.Controller.DynamoModel;
string samplePath = Path.Combine(_testPath, @".\Curve\CurveByPoints.dyn");
string testPath = Path.GetFullPath(samplePath);
Controller.DynamoViewModel.OpenCommand.Execute(testPath);
Assert.DoesNotThrow(() => dynSettings.Controller.RunExpression());
//cerate some points and wire them
//to the selections
ReferencePoint p1, p2, p3, p4;
using (_trans = new Transaction(DocumentManager.Instance.CurrentUIDocument.Document))
{
_trans.Start("Create reference points for testing.");
p1 = DocumentManager.Instance.CurrentUIDocument.Document.FamilyCreate.NewReferencePoint(new XYZ(1, 5, 12));
p2 = DocumentManager.Instance.CurrentUIDocument.Document.FamilyCreate.NewReferencePoint(new XYZ(5, 1, 12));
p3 = DocumentManager.Instance.CurrentUIDocument.Document.FamilyCreate.NewReferencePoint(new XYZ(12, 1, 5));
p4 = DocumentManager.Instance.CurrentUIDocument.Document.FamilyCreate.NewReferencePoint(new XYZ(5, 12, 1));
_trans.Commit();
}
var ptSelectNodes = dynSettings.Controller.DynamoModel.Nodes.Where(x => x is DSModelElementSelection);
if (!ptSelectNodes.Any())
Assert.Fail("Could not find point selection nodes in dynamo graph.");
((DSModelElementSelection)ptSelectNodes.ElementAt(0)).SelectedElement = p1.Id;
((DSModelElementSelection)ptSelectNodes.ElementAt(1)).SelectedElement = p2.Id;
((DSModelElementSelection)ptSelectNodes.ElementAt(2)).SelectedElement = p3.Id;
((DSModelElementSelection)ptSelectNodes.ElementAt(3)).SelectedElement = p4.Id;
dynSettings.Controller.RunExpression(true);
FilteredElementCollector fec = new FilteredElementCollector(DocumentManager.Instance.CurrentUIDocument.Document);
fec.OfClass(typeof(CurveElement));
Assert.AreEqual(fec.ToElements().Count(), 1);
CurveByPoints mc = (CurveByPoints)fec.ToElements().ElementAt(0);
Assert.IsTrue(mc.IsReferenceLine);
//now flip the switch for creating a reference curve
var boolNode = dynSettings.Controller.DynamoModel.Nodes.Where(x => x is DSCoreNodesUI.BoolSelector).First();
((DSCoreNodesUI.BasicInteractive<bool>)boolNode).Value = false;
dynSettings.Controller.RunExpression(true);
Assert.AreEqual(fec.ToElements().Count(), 1);
mc = (CurveByPoints)fec.ToElements().ElementAt(0);
Assert.IsFalse(mc.IsReferenceLine);
}
示例5: Evaluate
public override FScheme.Value Evaluate(Microsoft.FSharp.Collections.FSharpList<FScheme.Value> args)
{
var text = ((FScheme.Value.String) args[0]).Item;
var position = (XYZ) ((FScheme.Value.Container) args[1]).Item;
var normal = (XYZ) ((FScheme.Value.Container) args[2]).Item;
var up = (XYZ) ((FScheme.Value.Container) args[3]).Item;
var depth = ((FScheme.Value.Number) args[4]).Item;
var textTypeName = ((FScheme.Value.String) args[5]).Item;
//find a text type in the document to use
var fec = new FilteredElementCollector(dynRevitSettings.Doc.Document);
fec.OfClass(typeof(ModelTextType));
ModelTextType mtt;
if (fec.ToElements().Cast<ModelTextType>().Any(x => x.Name == textTypeName))
{
mtt = fec.ToElements().First() as ModelTextType;
}
else
{
throw new Exception(string.Format("A model text type named {0} could not be found in the document.", textTypeName));
}
Autodesk.Revit.DB.ModelText mt;
if (Elements.Any())
{
if (dynUtils.TryGetElement(Elements[0], out mt))
{
//if the position or normal are different
//we have to recreate
var currPos = mt.Location as LocationPoint;
if (!position.IsAlmostEqualTo(currPos.Point))
{
dynRevitSettings.Doc.Document.Delete(Elements[0]);
mt = CreateModelText(normal, position, -up, text, mtt, depth);
Elements.Add(mt.Id);
}
else
{
//reset the text and the depth
mt.Text = text;
mt.Depth = depth;
Elements[0] = mt.Id;
}
}
}
else
{
mt = CreateModelText(normal, position, -up, text, mtt, depth);
Elements.Add(mt.Id);
}
return FScheme.Value.NewContainer(mt);
}
示例6: GetAllSheets
/// <summary>
/// Gather up all the available sheets.
/// </summary>
/// <param name="doc"></param>
/// <param name="sheet"></param>
/// <returns></returns>
public static ElementSet GetAllSheets(Document doc)
{
ElementSet allSheets = new ElementSet();
FilteredElementCollector fec = new FilteredElementCollector(doc);
ElementClassFilter elementsAreWanted = new ElementClassFilter(typeof(ViewSheet));
fec.WherePasses(elementsAreWanted);
List<Element> elements = fec.ToElements() as List<Element>;
foreach (Element element in elements)
{
ViewSheet viewSheet = element as ViewSheet;
if (null == viewSheet)
{
continue;
}
else
{
ElementId objId = viewSheet.GetTypeId();
if (ElementId.InvalidElementId == objId)
{
continue;
}
else
{
allSheets.Insert(viewSheet);
}
}
}
return allSheets;
}
示例7: 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;
}
示例8: TestOne
public void TestOne()
{
using (var t = new Transaction(DocumentManager.Instance.CurrentDBDocument))
{
if (t.Start("Test one.") == TransactionStatus.Started)
{
//create a reference point
var pt = DocumentManager.Instance.CurrentDBDocument.FamilyCreate.NewReferencePoint(new XYZ(5, 5, 5));
if (t.Commit() != TransactionStatus.Committed)
{
t.RollBack();
}
}
else
{
throw new Exception("Transaction could not be started.");
}
}
//verify that the point was created
var collector = new FilteredElementCollector(DocumentManager.Instance.CurrentDBDocument);
collector.OfClass(typeof (ReferencePoint));
Assert.AreEqual(1, collector.ToElements().Count);
}
示例9: ProjectSettingsManager
private ProjectSettingsManager(Document document)
{
var col = new FilteredElementCollector(document).OfClass(typeof(ProjectInfo));
_element = col.ToElements().First();
_schema = Schema.Lookup(_schemaGuid) ?? GetStorageSchema();
//get entity from element if it exists in there already or create new otherwise
_entity = _element.GetEntity(_schema);
if (_entity == null || _entity.Schema == null)
_entity = new Entity(_schema);
LoadData(document);
//static cache management
Cache.Add(document, this);
document.DocumentClosing += new EventHandler<DocumentClosingEventArgs>(OnDocumentClosing);
document.Application.DocumentSynchronizedWithCentral += new EventHandler<DocumentSynchronizedWithCentralEventArgs>(OnDocumentSynchronized);
document.Application.DocumentChanged += new EventHandler<DocumentChangedEventArgs>((sender, args) =>
{
if (args.Operation == UndoOperation.TransactionUndone || args.Operation == UndoOperation.TransactionRedone)
{
}
});
}
示例10: Level
public void Level()
{
var model = dynSettings.Controller.DynamoModel;
string samplePath = Path.Combine(_testPath, @".\Level\Level.dyn");
string testPath = Path.GetFullPath(samplePath);
model.Open(testPath);
Assert.DoesNotThrow(() => dynSettings.Controller.RunExpression(true));
//ensure that the level count is the same
var levelColl = new FilteredElementCollector(dynRevitSettings.Doc.Document);
levelColl.OfClass(typeof(Autodesk.Revit.DB.Level));
Assert.AreEqual(levelColl.ToElements().Count(), 6);
//change the number and run again
var numNode = (DoubleInput)dynRevitSettings.Controller.DynamoModel.Nodes.First(x => x is DoubleInput);
numNode.Value = "0..20..2";
Assert.DoesNotThrow(() => dynSettings.Controller.RunExpression(true));
//ensure that the level count is the same
levelColl = new FilteredElementCollector(dynRevitSettings.Doc.Document);
levelColl.OfClass(typeof(Autodesk.Revit.DB.Level));
Assert.AreEqual(levelColl.ToElements().Count(), 11);
}
示例11: Execute
Execute ()
{
//Get every level by iterating through all elements
systemLevelsData = new List<LevelsDataSource>();
FilteredElementCollector fec = new FilteredElementCollector(m_app.ActiveUIDocument.Document);
ElementClassFilter elementsAreWanted = new ElementClassFilter(typeof(Level));
fec.WherePasses(elementsAreWanted);
List<Element> elements = fec.ToElements() as List<Element>;
foreach (Element element in elements)
{
Level systemLevel = element as Level;
if (systemLevel != null)
{
LevelsDataSource levelsDataSourceRow = new LevelsDataSource();
levelsDataSourceRow.LevelIDValue = systemLevel.Id.IntegerValue;
levelsDataSourceRow.Name = systemLevel.Name;
levelsDataSourceRow.Elevation = systemLevel.Elevation;
systemLevelsData.Add(levelsDataSourceRow);
}
}
LevelsForm displayForm = new LevelsForm(this);
displayForm.ShowDialog();
return true;
}
示例12: CanChangeLacingAndHaveElementsUpdate
public void CanChangeLacingAndHaveElementsUpdate()
{
string samplePath = Path.Combine(_testPath, @".\Core\LacingTest.dyn");
string testPath = Path.GetFullPath(samplePath);
Controller.DynamoViewModel.OpenCommand.Execute(testPath);
var xyzNode = dynSettings.Controller.DynamoModel.Nodes.First(x => x.NickName == "Point.ByCoordinates");
Assert.IsNotNull(xyzNode);
//test the shortest lacing
xyzNode.ArgumentLacing = LacingStrategy.Shortest;
dynSettings.Controller.RunExpression(true);
var fec = new FilteredElementCollector((Autodesk.Revit.DB.Document)DocumentManager.Instance.CurrentDBDocument);
fec.OfClass(typeof(ReferencePoint));
Assert.AreEqual(4, fec.ToElements().Count());
//test the longest lacing
xyzNode.ArgumentLacing = LacingStrategy.Longest;
dynSettings.Controller.RunExpression(true);
fec = null;
fec = new FilteredElementCollector((Autodesk.Revit.DB.Document)DocumentManager.Instance.CurrentDBDocument);
fec.OfClass(typeof(ReferencePoint));
Assert.AreEqual(5, fec.ToElements().Count());
//test the cross product lacing
xyzNode.ArgumentLacing = LacingStrategy.CrossProduct;
dynSettings.Controller.RunExpression(true);
fec = null;
fec = new FilteredElementCollector((Autodesk.Revit.DB.Document)DocumentManager.Instance.CurrentDBDocument);
fec.OfClass(typeof(ReferencePoint));
Assert.AreEqual(20, fec.ToElements().Count());
}
示例13: Loft
public void Loft()
{
var model = dynSettings.Controller.DynamoModel;
string samplePath = Path.Combine(_testPath, @".\Solid\Loft.dyn");
string testPath = Path.GetFullPath(samplePath);
model.Open(testPath);
dynSettings.Controller.RunExpression(true);
var fec = new FilteredElementCollector(dynRevitSettings.Doc.Document);
fec.OfClass(typeof(GenericForm));
//verify one loft created
int count = fec.ToElements().Count;
Assert.IsInstanceOf(typeof(Form), fec.ToElements().First());
Assert.AreEqual(1, count);
}
示例14: PopulateItems
public override void PopulateItems()
{
var wallTypesColl = new FilteredElementCollector(dynRevitSettings.Doc.Document);
wallTypesColl.OfClass(typeof(WallType));
Items.Clear();
wallTypesColl.ToElements().ToList().ForEach(x => Items.Add(new DynamoDropDownItem(x.Name, x)));
}
示例15: ClsCategory
public ClsCategory(Category cat, Document doc)
{
_Cat = cat;
_Doc = doc;
FilteredElementCollector col = new FilteredElementCollector(doc);
col.OfCategoryId(cat.Id).WhereElementIsNotElementType();
_InstanceElements = col.ToElements().ToList();
}