• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    Autodesk Navisworks API

    Reply
    Active Member
    Posts: 10
    Registered: ‎10-18-2009

    How to save a Search to Selection set by Navisworks API

    177 Views, 1 Replies
    06-05-2012 10:52 PM

    // New a Search

    Navisworks.Search s = new Navisworks.Search();

     

    // Add a search Condition

    Navisworks.SearchCondition scName = Navisworks.SearchCondition.HasPropertyByDisplayName("Item", "Name");

    scName = scName.EqualValue(Navisworks.VariantData.FromDisplayString(strItem));

    s.SearchConditions.Add(scName);

     

    // Get Search Result

    Navisworks.ModelItemCollection searchRst = s.FindAll(Navisworks.Application.ActiveDocument, false);

     

    if (searchRst.Count > 0)

    {

    // Save to current Search

            Navisworks.Application.ActiveDocument.CurrentSearch.CopyFrom(s);

     

    // Create Search Set

            ComApi.InwOpSelectionSet2 ss = state.ObjectFactory
                   (ComApi.nwEObjectType.eObjectType_nwOpSelectionSet) as ComApi.InwOpSelectionSet2;

            ss.name = selCompName;

     

    // Add Find Spec

           ComApi.InwOpFindSpec nwFindSpec  = state.ObjectFactory

                  (ComApi.nwEObjectType.eObjectType_nwOpFindSpec) as ComApi.InwOpFindSpec;

     

    // Set Find spec with Current Search

            nwFindSpec = state.CurrentFindSpec;

     

            ss.ImplicitFindSpec = nwFindSpec;

     

    // Add Search Set to Selection Sets

            state.SelectionSets().Add(ss);

     

    }

    Please use plain text.
    ADN Support Specialist
    xiaodong.liang
    Posts: 861
    Registered: ‎06-12-2011

    Re: How to save a Search to Selection set by Navisworks API

    08-01-2012 01:12 AM in reply to: ctci20299

    In this case, Search is a .NET object while InwXXX are COM objects. Although COM interop allows you communicate between COM API and .NET API, this does not mean the COM objects can be assigned to the .NET objects.

     

    Please refer to the two blogs. I think they answered your question.

     

    http://adndevblog.typepad.com/aec/2012/08/add-search-selectionset-in-net.html

    http://adndevblog.typepad.com/aec/2012/08/add-search-selectionset-in-com.html

     

     



    Xiaodong Liang
    Developer Technical Services
    Autodesk Developer Network

    Please use plain text.