|
![]() |
Defines a search that can be run to find ModelItems
Namespace: Autodesk.Navisworks.Api
Assembly: Autodesk.Navisworks.Api (in Autodesk.Navisworks.Api.dll)
Syntax
Visual Basic |
---|
Public Class Search _ Inherits NativeHandle |
C# |
---|
public class Search : NativeHandle |
Visual C++ |
---|
public ref class Search : public NativeHandle |
Remarks
Searches are the API equivalent of the 'Find' functionality in through the Navisworks GUI.
For more information on searches see 'Properties and Searching' in the 'Developer guide'.
Examples

using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Windows.Forms; using System.Text; using Autodesk.Navisworks.Api.Controls; //This sample should be tried with the GateHouse sample drawing, public static void NamedConstantSearch() { //Create a new search object Search s = new Search(); //Add our search condition s.SearchConditions.Add( new SearchCondition( new NamedConstant("LcOaNode", "Item"), new NamedConstant("LcOaNodeHidden", "Hidden"), SearchConditionOptions.StartGroup, SearchConditionComparison.Equal, VariantData.FromBoolean(false) ) ); //Note, this particular search would be better acheived using other methods than NamedConstant //and is purely to demonstrate NamedConstant usage. //for example a better form of the same query would be: //s.SearchConditions.Add( // SearchCondition.HasPropertyByName(PropertyCategoryNames.Item, DataPropertyNames.ItemHidden) // .EqualValue(VariantData.FromBoolean(false))); // // //Set the selection which we wish to search s.Selection.SelectAll(); s.Locations = SearchLocations.DescendantsAndSelf; //halt searching below ModelItems which match this s.PruneBelowMatch = true; //get the resulting collection by applying this search ModelItemCollection searchResults = s.FindAll(Autodesk.Navisworks.Api.Application.ActiveDocument, false); StringBuilder output = new StringBuilder(); output.AppendLine("Found the following:"); //show the results foreach (ModelItem mi in searchResults) { output.AppendLine(mi.ToString()); } MessageBox.Show(output.ToString()); }

using Autodesk.Navisworks.Api.Controls; //Create a new search Search s = new Search(); //set the selection to everything s.Selection.SelectAll(); //Add a search condition s.SearchConditions.Add(SearchCondition.HasCategoryByName(PropertyCategoryNames.Geometry)); try { //get the resulting collection by applying this search ModelItemCollection searchResults = s.FindAll(Autodesk.Navisworks.Api.Application.ActiveDocument, true); //Select the items in the model that are contained in the collection Autodesk.Navisworks.Api.Application.ActiveDocument.CurrentSelection.CopyFrom(searchResults); } catch (CanceledOperationException) { //the user cancelled the search }